OurOS 0.1
Operating System built by McGill Students
 
Loading...
Searching...
No Matches
list.c File Reference
#include "sys/list.h"
#include "string.h"
#include "stdint.h"
#include "panic.h"

Functions

struct list_head * list_init_head (struct list_head *head)
 Initializes head as an empty list.
 
struct list_node * list_init_node (struct list_node *node)
 Initializes node.
 
bool list_is_empty (const struct list_head *head)
 
struct list_node * list_insert_after (struct list_node *after, struct list_node *node)
 Inserts node after after in the list of after.
 
struct list_node * list_insert_before (struct list_node *before, struct list_node *node)
 Inserts node before before in the list of before.
 
struct list_node * list_append (struct list_head *head, struct list_node *node)
 Inserts node at the end of head's list (aka stack push).
 
struct list_head * list_extend (struct list_head *head1, struct list_head *head2)
 Merges head2 unto head1 at the end of head1 and returns head1.
 
struct list_node * list_first (struct list_head *head)
 
struct list_node * list_last (struct list_head *head)
 
struct list_node * list_remove (struct list_node *node)
 Removes node from head's list.
 
struct list_node * list_pop_first (struct list_head *head)
 Removes the first node of head's list (aka deque with respect to list_append).
 
struct list_node * list_pop_last (struct list_head *head)
 Removes the last node of head's list (aka stack pop with respect to list_append).
 
struct list_node * list_next (struct list_head *head, struct list_node *node)
 
struct list_node * list_prev (struct list_head *head, struct list_node *node)
 
size_t list_length (struct list_head *head)
 

Function Documentation

◆ list_append()

struct list_node * list_append ( struct list_head *  head,
struct list_node *  node 
)

Inserts node at the end of head's list (aka stack push).

Returns
node

◆ list_extend()

struct list_head * list_extend ( struct list_head *  head1,
struct list_head *  head2 
)

Merges head2 unto head1 at the end of head1 and returns head1.

Warning
This will modify head2, so head2 should be discarded or reinitialized afterwards.
Returns
head1

◆ list_first()

struct list_node * list_first ( struct list_head *  head)
Returns
The first node of head's list, otherwise NULL.

◆ list_init_head()

struct list_head * list_init_head ( struct list_head *  head)

Initializes head as an empty list.

◆ list_init_node()

struct list_node * list_init_node ( struct list_node *  node)

Initializes node.

◆ list_insert_after()

struct list_node * list_insert_after ( struct list_node *  after,
struct list_node *  node 
)

Inserts node after after in the list of after.

Returns
node

◆ list_insert_before()

struct list_node * list_insert_before ( struct list_node *  before,
struct list_node *  node 
)

Inserts node before before in the list of before.

Returns
node

◆ list_is_empty()

bool list_is_empty ( const struct list_head *  head)
Returns
true if head's list is empty, otherwise false.

◆ list_last()

struct list_node * list_last ( struct list_head *  head)
Returns
The last node of head's list, otherwise NULL.

◆ list_length()

size_t list_length ( struct list_head *  head)
Returns
The length of head's list.

◆ list_next()

struct list_node * list_next ( struct list_head *  head,
struct list_node *  node 
)
Returns
The node right after node in the head's list, otherwise NULL.

◆ list_pop_first()

struct list_node * list_pop_first ( struct list_head *  head)

Removes the first node of head's list (aka deque with respect to list_append).

Note
The node returned is not modified.
Returns
The removed node if the list of head is not empty, otherwise NULL.

◆ list_pop_last()

struct list_node * list_pop_last ( struct list_head *  head)

Removes the last node of head's list (aka stack pop with respect to list_append).

Note
The node returned is not modified.
Returns
The removed node if the list of head is not empty, otherwise NULL.

◆ list_prev()

struct list_node * list_prev ( struct list_head *  head,
struct list_node *  node 
)
Returns
The node right before node in the head's list, otherwise NULL.

◆ list_remove()

struct list_node * list_remove ( struct list_node *  node)

Removes node from head's list.

Note
node is not modified.
Warning
node must already be in a list, otherwise there might be unintended consequences.
Returns
node