MentOS  0.8.0
The Mentoring Operating System
Functions
list.c File Reference

Functions

static listnode_t__node_alloc (void)
 Allocates the memory for a node. More...
 
static void __node_dealloc (listnode_t *node)
 Frees the memory of a node. More...
 
static list_t__list_alloc (void)
 Allocates the memory for a list. More...
 
static void __list_dealloc (list_t *list)
 Frees the memory of a list. More...
 
list_tlist_create (void)
 Create a list and set head, tail to NULL, and size to 0. More...
 
unsigned int list_size (list_t *list)
 Get list size. More...
 
int list_empty (list_t *list)
 Checks if the list is empty. More...
 
listnode_tlist_insert_front (list_t *list, void *value)
 Insert a value at the front of list. More...
 
listnode_tlist_insert_back (list_t *list, void *value)
 Insert a value at the back of list. More...
 
void * list_remove_node (list_t *list, listnode_t *node)
 Given a listnode, remove it from list. More...
 
void * list_remove_front (list_t *list)
 Remove a value at the front of list. More...
 
void * list_remove_back (list_t *list)
 Remove a value at the back of list. More...
 
listnode_tlist_find (list_t *list, void *value)
 Searches the node of the list which points at the given value. More...
 
void list_push_back (list_t *list, void *value)
 Insert after tail of list(same as insert back). More...
 
listnode_tlist_pop_back (list_t *list)
 Remove and return the tail of the list. More...
 
listnode_tlist_pop_front (list_t *list)
 Remove and return the head of the list. More...
 
void list_push_front (list_t *list, void *value)
 Insert before head of list(same as insert front). More...
 
void * list_peek_front (list_t *list)
 Get the value of the first element but not remove it. More...
 
void * list_peek_back (list_t *list)
 Get the value of the last element but not remove it. More...
 
int list_get_index_of_value (list_t *list, void *value)
 Checks if the given value is contained inside the list. More...
 
listnode_tlist_get_node_by_index (list_t *list, unsigned int index)
 Returns the node at the given index. More...
 
void * list_remove_by_index (list_t *list, unsigned int index)
 Removes a node from the list at the given index. More...
 
void list_destroy (list_t *list)
 Destroy a list. More...
 
void list_merge (list_t *target, list_t *source)
 Append source at the end of target. More...
 

Detailed Description

Function Documentation

◆ __list_alloc()

static list_t* __list_alloc ( void  )
inlinestatic

Allocates the memory for a list.

Returns
a pointer to the newly allocated list.

◆ __list_dealloc()

static void __list_dealloc ( list_t list)
inlinestatic

Frees the memory of a list.

Parameters
listthe list we want to free.

◆ __node_alloc()

static listnode_t* __node_alloc ( void  )
inlinestatic

Allocates the memory for a node.

Returns
a pointer to the newly allocated node.

◆ __node_dealloc()

static void __node_dealloc ( listnode_t node)
inlinestatic

Frees the memory of a node.

Parameters
nodethe new we want to free.

◆ list_create()

list_t* list_create ( void  )

Create a list and set head, tail to NULL, and size to 0.

Returns
The newly created list.

◆ list_destroy()

void list_destroy ( list_t list)

Destroy a list.

Parameters
listThe list.

◆ list_empty()

int list_empty ( list_t list)

Checks if the list is empty.

Parameters
listThe list.
Returns
1 if empty, 0 otherwise.

◆ list_find()

listnode_t* list_find ( list_t list,
void *  value 
)

Searches the node of the list which points at the given value.

Parameters
listThe list.
valueThe value that has to be searched.
Returns
The node associated with the value.

◆ list_get_index_of_value()

int list_get_index_of_value ( list_t list,
void *  value 
)

Checks if the given value is contained inside the list.

Parameters
listThe list.
valueThe value to search.
Returns
-1 if list element is not found, the index otherwise.

◆ list_get_node_by_index()

listnode_t* list_get_node_by_index ( list_t list,
unsigned int  index 
)

Returns the node at the given index.

Parameters
listThe list.
indexThe index of the desired node.
Returns
A pointer to the node, or NULL otherwise.

◆ list_insert_back()

listnode_t* list_insert_back ( list_t list,
void *  value 
)

Insert a value at the back of list.

Parameters
listThe list.
valueThe value to insert.
Returns
The node associated with the inserted value.

◆ list_insert_front()

listnode_t* list_insert_front ( list_t list,
void *  value 
)

Insert a value at the front of list.

Parameters
listThe list.
valueThe value to insert.
Returns
The node associated with the inserted value.

◆ list_merge()

void list_merge ( list_t target,
list_t source 
)

Append source at the end of target.

Parameters
targetWhere the element are added.
sourceWhere the element are removed.

Beware, source is destroyed.

◆ list_peek_back()

void* list_peek_back ( list_t list)

Get the value of the last element but not remove it.

Parameters
listThe list.
Returns
The value associated with the first node.

◆ list_peek_front()

void* list_peek_front ( list_t list)

Get the value of the first element but not remove it.

Parameters
listThe list.
Returns
The value associated with the first node.

◆ list_pop_back()

listnode_t* list_pop_back ( list_t list)

Remove and return the tail of the list.

Parameters
listThe list.
Returns
The node that has been removed.

User is responsible for freeing the returned node and the value.

◆ list_pop_front()

listnode_t* list_pop_front ( list_t list)

Remove and return the head of the list.

Parameters
listThe list.
Returns
The node that has been removed.

User is responsible for freeing the returned node and the value.

◆ list_push_back()

void list_push_back ( list_t list,
void *  value 
)

Insert after tail of list(same as insert back).

Parameters
listThe list.
valueThe value to insert.

◆ list_push_front()

void list_push_front ( list_t list,
void *  value 
)

Insert before head of list(same as insert front).

Parameters
listThe list.
valueThe value to insert.

◆ list_remove_back()

void* list_remove_back ( list_t list)

Remove a value at the back of list.

Parameters
listThe list.
Returns
The value associated with the removed node.

◆ list_remove_by_index()

void* list_remove_by_index ( list_t list,
unsigned int  index 
)

Removes a node from the list at the given index.

Parameters
listThe list.
indexThe index of the node we need to remove.
Returns
The value contained inside the node, NULL otherwise.

◆ list_remove_front()

void* list_remove_front ( list_t list)

Remove a value at the front of list.

Parameters
listThe list.
Returns
The value associated with the removed node.

◆ list_remove_node()

void* list_remove_node ( list_t list,
listnode_t node 
)

Given a listnode, remove it from list.

Parameters
listThe list.
nodeThe node that has to be removed.
Returns
The value associated with the removed node.

◆ list_size()

unsigned int list_size ( list_t list)

Get list size.

Parameters
listThe list.
Returns
The size of the list.