typedef struct _LListElement { void* data; struct _LListElement* next; } LListElement; typedef struct _LList{ int size; LListElement *head,*tail; destroyfunc* destroy; comparefunc* cmp; } LList; The LList data structure represents a singly-linked list. |
| LList* llist_create(destroyfunc*
destroy, comparefunc* cmp); description: creates a new, empty singly-linked list.The destroy parameter is a pointer to a destroyfunc . This function is called to free dynammically allocated data when llist_destroy is called. If the list contains data that should not be freed, it should be set to NULL. The cmp parameter is a pointer to a comparefunc . This function is used by the LList data structure to compare it's elements when llist_element_is_member or llist_get_previous is called. This parameter should be set to NULL if llist_element_is_member and llist_get_previous won't be necessary. return value: a pointer to a new LList data structure or NULL if the allocation fails. since: YACLib 1.0 int llist_insert_next(LList* llist, LListElement* prev, const void* data) description: inserts an element in the singly-linked list specified by llist, after the element prev. If prev is NULL, the element will be inserted at the head of the list. The new element stores a pointer to data. return value: 0 if the element could be inserted, -1 otherwise. since: YACLib 1.0 int llist_insert_at(LList* llist, int pos, const void* data) description: inserts an element in the singly-linked list specified by llist, at the position specified by pos. pos must be a positive integer different than zero. If pos is greater than (or equal to) the list's size, then the element will be inserted at the tail of the list. The new element stores a pointer to data. return value: 0 if the element could be inserted, -1 otherwise. since: YACLib 1.0 int llist_insert_first(LList* llist, const void* data) description: inserts an element in the singly-linked list specified by llist, at the first position (the list's head). The new element stores a pointer to data. return value: 0 if the element could be inserted, -1 otherwise. since: YACLib 1.0 int llist_insert_last(LList* llist, const void* data) description: inserts an element in the singly-linked list specified by llist, at the last position (the list's tail). The new element stores a pointer to data. return value: 0 if the element could be inserted, -1 otherwise. since: YACLib 1.0 int llist_remove_next(LList* llist, LListElement* prev, void** data) description: removes an element from the singly-linked list specified by llist, after the element prev. If prev is NULL, the element will be removed from the head of the list. Upon return, data points to the data stored in the element that was removed. return value: 0 if the element could be removed, -1 otherwise. since: YACLib 1.0 int llist_remove_at(LList* llist, int pos, void** data) description: removes an element from the singly-linked list specified by llist, at the position specified by pos. pos must be a positive integer different than zero. If pos is greater than (or equal to) the list's size, then the element will be removed from the tail of the list. Upon return, data points to the data stored in the element that was removed. return value: 0 if the element could be removed, -1 otherwise. since: YACLib 1.0 int llist_remove_first(LList* llist, void** data) description: removes the first element from the singly-linked list specified by llist. Upon return, data points to the data stored in the element that was removed. return value: 0 if the element could be removed, -1 otherwise. since: YACLib 1.0 int llist_remove_all(LList* llist) description: removes all elements from the singly-linked list specified by llist. return value: 0 if the elements could be removed, -1 otherwise. since: YACLib 1.0 int llist_element_is_member(const LList* llist, const void* data) description: searches for an element matching data in the singly-linked list specified by llist. return value: 1 if an element matching data was found, 0 otherwise. since: YACLib 1.0 int llist_get_previous(const LList* llist, const void* elementdata, LListElement** prevptr) description: get a pointer to the element previous to the element matching elementdata, in the singly-linked list specified by llist. Upon return, this pointer is assigned to prevptr. return value: 0 if an element matching data was found, -1 otherwise. since: YACLib 1.0 void llist_destroy(LList* llist) description: destroys the singly-linked list specified by llist. It removes all elements of the list and calls the destroyfunc function passed to llist_create for each element as it is removed from the list, provided destroy wasn't set to NULL. return value: none since: YACLib 1.0 int llist_size(const LList* llist) description: macro that evaluates to the number of elements in the singly-linked list specified by llist. return value: the number of elements in llist. since: YACLib 1.0 LListElement* llist_head(const LList* llist) description: macro that evaluates to the head of the singly-linked list specified by llist. return value: the head of llist. since: YACLib 1.0 LListElement* llist_tail(const LList* llist) description: macro that evaluates to the tail of the singly-linked list specified by llist. return value: the tail of llist. since: YACLib 1.0 LListElement* llist_element_next(const LListElement* element) description: macro that evaluates to the next pointer of the singly-linked list element specified by element. return value: the next pointer of element. since: YACLib 1.0 void* llist_element_data(const LListElement* element) description: macro that evaluates to the data pointer of the singly-linked list element specified by element. returns: the data pointer of element. since: YACLib 1.0 |