MentOS  0.8.0
The Mentoring Operating System
Classes | Macros | Typedefs | Functions
list.h File Reference

An implementation for generic list. More...

Go to the source code of this file.

Classes

struct  listnode_t
 Represent the node of a list. More...
 
struct  list_t
 Represent the list. More...
 

Macros

#define listnode_foreach(it, list)    for (listnode_t * (it) = (list)->head; (it) != NULL; (it) = (it)->next)
 Macro used to iterate through a list.
 

Typedefs

typedef struct listnode_t listnode_t
 Represent the node of a list.
 
typedef struct list_t list_t
 Represent the list.
 

Functions

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...
 
void list_push_front (list_t *list, void *value)
 Insert before head of list(same as insert front). More...
 
listnode_tlist_pop_front (list_t *list)
 Remove and return the head of the list. 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...
 
void list_destroy (list_t *list)
 Destroy a list. 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_merge (list_t *target, list_t *source)
 Append source at the end of target. More...
 

Detailed Description

An implementation for generic list.

Function Documentation

◆ 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.