MentOS
0.8.0
The Mentoring Operating System
|
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_t * | list_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_t * | list_insert_front (list_t *list, void *value) |
Insert a value at the front of list. More... | |
listnode_t * | list_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_t * | list_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_t * | list_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_t * | list_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_t * | list_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... | |
An implementation for generic list.
list_t* list_create | ( | void | ) |
Create a list and set head, tail to NULL, and size to 0.
void list_destroy | ( | list_t * | list | ) |
Destroy a list.
list | The list. |
int list_empty | ( | list_t * | list | ) |
Checks if the list is empty.
list | The list. |
listnode_t* list_find | ( | list_t * | list, |
void * | value | ||
) |
Searches the node of the list which points at the given value.
list | The list. |
value | The value that has to be searched. |
int list_get_index_of_value | ( | list_t * | list, |
void * | value | ||
) |
Checks if the given value is contained inside the list.
list | The list. |
value | The value to search. |
listnode_t* list_get_node_by_index | ( | list_t * | list, |
unsigned int | index | ||
) |
Returns the node at the given index.
list | The list. |
index | The index of the desired node. |
listnode_t* list_insert_back | ( | list_t * | list, |
void * | value | ||
) |
Insert a value at the back of list.
list | The list. |
value | The value to insert. |
listnode_t* list_insert_front | ( | list_t * | list, |
void * | value | ||
) |
Insert a value at the front of list.
list | The list. |
value | The value to insert. |
Append source at the end of target.
target | Where the element are added. |
source | Where the element are removed. |
Beware, source is destroyed.
void* list_peek_back | ( | list_t * | list | ) |
Get the value of the last element but not remove it.
list | The list. |
void* list_peek_front | ( | list_t * | list | ) |
Get the value of the first element but not remove it.
list | The list. |
listnode_t* list_pop_back | ( | list_t * | list | ) |
Remove and return the tail of the list.
list | The list. |
User is responsible for freeing the returned node and the value.
listnode_t* list_pop_front | ( | list_t * | list | ) |
Remove and return the head of the list.
list | The list. |
User is responsible for freeing the returned node and the value.
void list_push_back | ( | list_t * | list, |
void * | value | ||
) |
Insert after tail of list(same as insert back).
list | The list. |
value | The value to insert. |
void list_push_front | ( | list_t * | list, |
void * | value | ||
) |
Insert before head of list(same as insert front).
list | The list. |
value | The value to insert. |
void* list_remove_back | ( | list_t * | list | ) |
Remove a value at the back of list.
list | The list. |
void* list_remove_by_index | ( | list_t * | list, |
unsigned int | index | ||
) |
Removes a node from the list at the given index.
list | The list. |
index | The index of the node we need to remove. |
void* list_remove_front | ( | list_t * | list | ) |
Remove a value at the front of list.
list | The list. |
void* list_remove_node | ( | list_t * | list, |
listnode_t * | node | ||
) |
Given a listnode, remove it from list.
list | The list. |
node | The node that has to be removed. |
unsigned int list_size | ( | list_t * | list | ) |
Get list size.
list | The list. |