Client Library - List API


Detailed Description

detailed description

Example:
typical usage of list api;
 int compare_function (void *p1, void *p2)
 {
        int v1 = (int) p1;
        int v2 = (int) p2;
        if (v1 < v2) { return -1; }
        if (v1 > v2) { return  1; }
        return 0;
 }

 int pos;
 void *item;
 s_list_t *list;

 // initialize the list struct
 s_list_init(&list);

 // add an item to the end
 item = (void *) 0;
 s_list_add(list, item, -1);

 // add an item to the beginning
 item = (void *) 1;
 s_list_add(list, item, 0);

 // add an item to position 1
 item = (void *) 2;
 s_list_add(list, item, 1);

 // add an item to the end
 item = (void *) 3;
 s_list_add(list, item, -1);

 // find the the item with compare function
 item = (void *) 2;
 item = s_list_find(list, item, compare_function);

 // get the items, and print them
 // output: 1 2 0 3
 for (pos = 0; !s_list_eol(list, pos); pos++) {
        item = (void *) s_list_get(list, pos);
        printf("%d ", (int) item;
 }

 // remove items
 while (!s_list_eol(list, 0)) {
        s_list_remove(list, 0);
 }

 // uninitialize the list
 s_list_uninit(list);


Data Structures

struct  s_list_node_s
 list node struct More...
struct  s_list_s
 list struct More...

Functions

int s_list_init (s_list_t **li)
 initializes the list struct
int s_list_uninit (s_list_t *li)
 uninitializes the list struct
int s_list_eol (s_list_t *li, int i)
 query if i'nth element exists
void * s_list_get (s_list_t *li, int pos)
 return the element at position
int s_list_remove (s_list_t *li, int pos)
 removes the element at position
int s_list_add (s_list_t *li, void *el, int pos)
 adds the element at position
void * s_list_find (s_list_t *list, void *node, int(*cmp_func)(void *, void *))
 search the node at list, with the given compare function
int s_list_get_pos (s_list_t *list, void *node)
 return the position of node


Function Documentation

int s_list_add ( s_list_t li,
void *  el,
int  pos 
)

adds the element at position

Parameters:
*li - the list
*el - element
pos - position (-1 means the end)
Returns:
- on success, 1 on error

int s_list_eol ( s_list_t li,
int  i 
)

query if i'nth element exists

Parameters:
*li - the list
i - position
Returns:
0 on success, 1 on error

void* s_list_find ( s_list_t list,
void *  node,
int(*)(void *, void *)  cmp_func 
)

search the node at list, with the given compare function

Parameters:
*list - the list
*node - node to be matched
cmp_func - compare function. compare function must return -1, 0, 1 for less than, equal to, and greater than
Returns:
- on success, 1 on error

void* s_list_get ( s_list_t li,
int  pos 
)

return the element at position

Parameters:
*li - the list
pos - position
Returns:
pointer to element on success, NULL on error.

int s_list_get_pos ( s_list_t list,
void *  node 
)

return the position of node

Parameters:
*list - the list
*node - element
Returns:
- position on success, -1 on error

int s_list_init ( s_list_t **  li  ) 

initializes the list struct

Parameters:
**li - address of the pointer to list struct
Returns:
0 on success, 1 on error

int s_list_remove ( s_list_t li,
int  pos 
)

removes the element at position

Parameters:
*li - the list
pos - position
Returns:
- on success, 1 on error

int s_list_uninit ( s_list_t li  ) 

uninitializes the list struct

Parameters:
*li - the list
Returns:
0 on success, 1 on error


Generated on Wed Dec 27 17:53:06 2006 for xynth-0.8.40 by  doxygen 1.4.7