X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Finclude%2Futils%2Fllist.h;h=104c9e45ab94c2e08a8aca2feb5e84ba57a2e1db;hb=ed06d81139bc1a55f64793dea85dd59a58736ad8;hp=354e97665649fa915fdd67e7a08d330d73db5e71;hpb=bef7167f0dc1fd405e35d5cbffb3c0820945a9ea;p=sysdb.git diff --git a/src/include/utils/llist.h b/src/include/utils/llist.h index 354e976..104c9e4 100644 --- a/src/include/utils/llist.h +++ b/src/include/utils/llist.h @@ -40,6 +40,9 @@ typedef struct sdb_llist sdb_llist_t; struct sdb_llist_iter; typedef struct sdb_llist_iter sdb_llist_iter_t; +typedef int (*sdb_llist_cmp_cb)(const sdb_object_t *, const sdb_object_t *); +typedef int (*sdb_llist_lookup_cb)(const sdb_object_t *, const void *user_data); + /* * sdb_llist_create, sdb_llist_destroy: * Create and destroy a doubly linked list object. @@ -93,7 +96,7 @@ sdb_llist_append(sdb_llist_t *list, sdb_object_t *obj); * - a negative value on failure */ int -sdb_llist_insert(sdb_llist_t *list, sdb_object_t *obj, size_t index); +sdb_llist_insert(sdb_llist_t *list, sdb_object_t *obj, size_t idx); /* * sdb_llist_insert_sorted: @@ -113,27 +116,55 @@ sdb_llist_insert(sdb_llist_t *list, sdb_object_t *obj, size_t index); * - a negative value on failure */ int -sdb_llist_insert_sorted(sdb_llist_t *list, sdb_object_t *obj, - int (*compare)(const sdb_object_t *, const sdb_object_t *)); +sdb_llist_insert_sorted(sdb_llist_t *list, + sdb_object_t *obj, sdb_llist_cmp_cb); + +/* + * sdb_llist_search: + * Search for a object in the given 'list'. The function will return the first + * entry for which the 'lookup' callback returns 0. The 'user_data' is passed + * on to the lookup function on each invocation. + * + * Returns: + * - a pointer to the first matching object + * - NULL else + */ +sdb_object_t * +sdb_llist_search(sdb_llist_t *list, + sdb_llist_lookup_cb lookup, const void *user_data); -/* sdb_llist_search: - * Search for a 'key' in the given 'list'. The function will return the first - * entry that matches the specified 'key'. For that purpose, the 'compare' - * function is used. It should return 0 iff the two arguments compare equal. +/* + * sdb_llist_search_by_name: + * Search for an object named 'key' in the given 'list'. The function will + * return the first entry whose name matches the specified 'key' ignoring the + * case of the characters. + * + * Returns: + * - a pointer to the first matching object + * - NULL else + */ +sdb_object_t * +sdb_llist_search_by_name(sdb_llist_t *list, const char *key); + +/* + * sdb_llist_remove: + * Removes and returns the first matchin element of the list. The ref-count of + * the item will not be changed, that is, if the element will not be used any + * further, it should be de-referenced by the caller. * * Returns: - * - a pointer the sdb_object_t containing the matching entry + * - a pointer to the first matching object * - NULL else */ sdb_object_t * -sdb_llist_search(sdb_llist_t *list, const sdb_object_t *key, - int (*compare)(const sdb_object_t *, const sdb_object_t *)); +sdb_llist_remove(sdb_llist_t *list, + sdb_llist_lookup_cb lookup, const void *user_data); /* * sdb_llist_shift: * Removes and returns the first element of the list. The ref-count of the * item will not be changed, that is, if the element will not be used any - * further, it should be re-referenced by the caller. + * further, it should be de-referenced by the caller. * * Returns: * - the former first element of the list