Site hosted by Angelfire.com: Build your free website today!

(c) 2002 - Pedro Flynn <pflynn@microsoftsucks.org>

DLList



typedef struct DLListElement_ {
    void* data;
    struct DLListElement_  *next, *prev;
} DLListElement;

typedef struct DLList_ {
    int size;
    DLListElement *head,*tail;
    destroyfunc* destroy;
    comparefunc* cmp;
} DLList;


    The DLList data structure represents a doubly-linked list. 

Related functions and macros



DLList* dllist_create(destroyfunc* destroy, comparefunc* cmp);

description: creates a new, empty doubly-linked list.The destroy parameter is a pointer to a destroyfunc . This function is called to free dynammically allocated data when dllist_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 DLList data structure to compare it's elements when dllist_element_is_member is called. This parameter should be set to NULL if dllist_element_is_member won't be necessary.

return value: a pointer to a  new DLList data structure or NULL if the allocation fails.

since: YACLib 1.0

int  dllist_insert_next(DLList* dllist, DLListElement* prev, const void* data)

description: inserts an  element in the doubly-linked list specified by dllist, after the element prev. The new element stores a pointer to data.

return value:
0 if the element could be inserted, -1 otherwise.

since: YACLib 1.0

int dllist_insert_prev(DLList* dllist, DLListElement* next, const void* data)

description: inserts an element in the doubly-linked list specified by dllist, before the element next. The new element stores a pointer to data.

return value:
0 if the element could be inserted, -1 otherwise.

since: YACLib 1.0

int dllist_insert_at(DLList* dllist, int pos, const void* data)

description: inserts an element in the doubly-linked list specified by dllist, 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 dllist_insert_first(DLList* dllist, const void* data)

description: inserts an element in the doubly-linked list specified by dllist, 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 dllist_insert_last(DLList* dllist, const void* data)

description: inserts an element in the doubly-linked list specified by dllist, 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 dllist_remove(DLList* dllist, DLListElement* element, void** data)

description: removes the element element from the doubly-linked list specified by dllist. 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 dllist_remove_at(DLList* dllist, int pos, void** data)

description: removes an element from the doubly-linked list specified by dllist, 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 dllist_remove_first(DLList* dllist, void** data)

description: removes the first element from the doubly-linked list specified by dllist. 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 dllist_remove_last(DLList* dllist, void** data)

description: removes the last element from the doubly-linked list specified by dllist. 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 dllist_remove_all(DLList* llist)

description: removes all elements from the doubly-linked list specified by dllist.

return value:
0 if the elements could be removed, -1 otherwise.

since: YACLib 1.0

int dllist_element_is_member(const DLList* dllist,const void* data)

description: searches for an element matching data in the doubly-linked list specified by dllist.

return value:
1 if  an element matching data was found, 0 otherwise.

since: YACLib 1.0
void dllist_destroy(DLList* dllist)

description:  destroys the doubly-linked list specified by dllist. It removes all the elements of the list and calls the destroyfunc function passed to dllist_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 dllist_size(const DLList* dllist)

description:  macro that evaluates to the number of  elements in the doubly-linked list specified by dllist.

return value: the number of elements in dllist.

since: YACLib 1.0
DLListElement* dllist_head(const DLList* dllist)

description:  macro that evaluates to the head of the doubly-linked list specified by dllist.

return value: the head of dllist.

since: YACLib 1.0

DLListElement* dllist_tail(const DLList* dllist)

description:  macro that evaluates to the tail of the doubly-linked list specified by dllist.

return value: the tail of dllist.

since: YACLib 1.0
DLListElement* dllist_element_next(const DLListElement* element)

description:  macro that evaluates to the next pointer of  the  doubly-linked list element specified by element.

return value: the next pointer of element.

since: YACLib 1.0
DLListElement* dllist_element_prev(const DLListElement* element)

description:  macro that evaluates to the prev pointer of  the  doubly-linked list element specified by element.

return value: the prev pointer of element.

since: YACLib 1.0

void* dllist_element_data(const DLListElement* element)

description:  macro that evaluates to the data pointer of  the  doubly-linked list element specified by element.

return value: the data pointer of element.

since: YACLib 1.0