cp_hashlist *cp_hashlist_create(long initial_size,
cp_hashlist *cp_hashlist_create_by_mode(int mode,
long hash_fn(void *key);
and should return a number based on the key so that different keys yield different numbers to the extent possible. However since different keys may yield the same hash code a comparison function defined as
int hash_compare(void *a, void *b);
is needed to ultimately identify the requested key upon retrieval. The comparison function should return 0 for matching items, non-zero otherwise. See cp_hashtable_create(3) for more on hash and comparison functions and cp_hashtable(3) for a list of predefined hash functions for primitives and null terminated strings.
Lists created with the default mode (0) synchronize table operations (item insertion, iteration, retrieval and removal, internal table resizing and deleting) and perform no memory management. Different behavior can also be specified by calling cp_hashlist_create_by_mode and specifying a mode value. See cp_hashlist_set_mode(3) for a list of mode bits and their effect on list behavior.
In addition to list mode, cp_hashlist_create_by_option allows specifying copy and finalization functions for keys and values respectively. Copy functions are called on insertion if not NULL and COLLECTION_MODE_COPY is set and finalization functions are called on removal if not NULL and COLLECTION_MODE_DEEP is set. Copy functions should be defined as
void *copy_fn(void *);
and should return a pointer to a copy of the key or value passed. Destructor functions should be defined as
void *destructor_fn(void *);
and should release the memory associated with the key or value passed.
All mode bits can be set or reset after creation time by calling cp_hashlist_set_mode and cp_hashlist_unset_mode. Note that lists constructed with COLLECTION_MODE_NOSYNC set do not initialize the synchronization features, and subsequent attempts to perform thread safe operations may behave unpredictably. Hashlists that may be accessed by multiple threads at any point should not be initialized with COLLECTION_MODE_NOSYNC.
EINVAL a negative initial_size was requested.
This document was created by
using the manual pages.
Time: 18:37:21 GMT, December 27, 2005