Lists

#include <mailutils/list.h>

typedef int mu_list_action_t (void *item,void *cbdata);
typedef int (*mu_list_comparator_t)(void *item1, void* item2);

int mu_list_append(mu_list_t list,void *item);
int mu_list_count(mu_list_t list, size_t *pcount);
int mu_list_create(mu_list_t *list);
void mu_list_destroy(mu_list_t *list);
int mu_list_do(mu_list_t t, mu_list_action_t *action, void *cbdata);
int mu_list_get(mu_list_t list, size_t index, void **item);
int mu_list_get_comparator(mu_list_t list,mu_list_comparator_t *comp);
int mu_list_get_iterator(mu_list_t list,mu_iterator_t *iter);
int mu_list_insert(mu_list_t list, void *item, void *new_item, int insert_before);
int mu_list_intersect(mu_list_t *dest, mu_list_t a, mu_list_t b);
int mu_list_intersect_dup(mu_list_t *dest, mu_list_t a, mu_list_t b, int (*dup_item)(void **, void*, void*),void *dup_closure);
int mu_list_is_empty(mu_list_t list);
int mu_list_locate(mu_list_t list, void *item, void **ret_item);
int mu_list_prepend(mu_list_t list,void *item);
int mu_list_remove(mu_list_t list, void *item);
int mu_list_replace(mu_list_t list,void *old_item, void *new_item);
mu_list_comparator_t mu_list_set_comparator(mu_list_t list, mu_list_comparator_t comp);
int mu_list_set_destroy_item(mu_list_t list, void(*destroy_item)(void *item));
int mu_list_to_array(mu_list_t list,void **array, size_t count, size_t *pcount);

mu_list_t

typedef struct _mu_list *mu_list_t

This is an opaque data structure. None of the fields should be accessed by a user program.

mu_list_append

int mu_list_append(mu_list_t list,void *item);

Adds item to the end of the list. Returns 0 if successful or an error code.

mu_list_count

int mu_list_count(mu_list_t list, size_t *pcount);

Returns 0 and the number of items in the list in pcount if successful or an error code and pcount unchanged.

mu_list_create

int mu_list_create(mu_list_t *list);

Creates a new list. Returns 0 if successful or an error code.

mu_list_destroy

void mu_list_destroy(mu_list_t *list);

Releases all the resources associated with list. Unless a destroy function is set using mu_list_set_destroy then the memory associated with the list items will not be released.

mu_list_do

int mu_list_do(mu_list_t t, mu_list_action_t *action, void *cbdata);

Calls action for each item in list. cbdata is user data which is passed to action. If action returns non-zero then the processing is halted. mu_list_do returns 0 if all items have been processed or an error code or the non-zero return value from the last action call.

mu_list_get

int mu_list_get(mu_list_t list, size_t index, void **item);

Returns a pointer to the index'th item in list in item. The list is zero based. Returns 0 if successful or an error code.

mu_list_get_comparator

int mu_list_get_comparator(mu_list_t list,mu_list_comparator_t *comp);

Returns 0 and a pointer to the comparator function in comp or an error code.

mu_list_get_iterator

int mu_list_get_iterator(mu_list_t list,mu_iterator_t *iter);

Returns 0 and the iterator associated with list in iter if successful or an error code.

mu_list_insert

int mu_list_insert(mu_list_t list, void *item, void *new_item, int insert_before);

Inserts new_item before or after item in list. If insert_before is TRUE then new_item is inserted before item else it is inserted after item.

mu_list_intersect

int mu_list_intersect(mu_list_t *dest, mu_list_t a, mu_list_t b);

Creates a new list, dest, which contains of all the entries in a which are also in b. The items in the new list are those in b, and so some care will be needed when destroying b. This returns 0 if the operation is successful or an error code.

mu_list_intersect_dup

int mu_list_intersect_dup(mu_list_t *dest, mu_list_t a, mu_list_t b, int (*dup_item)(void **, void*, void*),void *dup_closure);

Creates a new list, dest, which contains all of the entries in a which are also in b. The dup_item function is used to create a copy of the item which is added to the new list. The dup_closure argument is user data which is passed as the third argument of dup_item. The comparator and destroy functions of the new list are set to those of b. This returns 0 if the operation is successful or an error code.

mu_list_is_empty

int mu_list_is_empty(mu_list_t list);

Returns TRUE if list is empty.

mu_list_locate

int mu_list_locate(mu_list_t list, void *item, void **ret_item);

Returns 0 and the item in ret_item if item can be found in list or an error code.

mu_list_prepend

int mu_list_prepend(mu_list_t list,void *item);

Adds item to the beginning of list. Returns 0 if successful or an error code.

mu_list_remove

int mu_list_remove(mu_list_t list, void *item);

Removes item from list. Returns 0 if successful or an error code.

The resources allocated for the removed item are not automatically released, so a pointer to the item should be obtained by calling mu_list_locate before calling mu_list_remove.

mu_list_replace

int mu_list_replace(mu_list_t list,void *old_item, void *new_item);

Replaces old_item with new_item. Returns 0 if successful or an error code;

The resources allocated for old_item are not automatically released, so a pointer to the item should be obtained by calling mu_list_locate before calling mu_list_replace.

mu_list_set_comparator

mu_list_comparator_t mu_list_set_comparator(mu_list_t list, mu_list_comparator_t comp);

This sets the function used to compare two items in the list. The function returns a pointer to the old comparator function.

The comparator function should return 0 if both items are identical. If no function is provided then a default function that simply compares the addresses of the two items is used. The comparator function is called internally by several other routines.

mu_list_set_destroy_item

int mu_list_set_destroy_item(mu_list_t list, void(*destroy_item)(void *item));

This sets the function called to release resources allocated to the the item when the list is destroyed. Unless a destroy function is set then item will not be released.

mu_list_to_array

int mu_list_to_array(mu_list_t list,void **array, size_t count, size_t *pcount);

Returns pointers to the first count items in array. The actual number of items returned is stored in pcount. The function returns 0 if successful or an error code.

 
lists.txt · Last modified: 2009/06/13 08:55 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki