6 * Hash table implemenation.
15 typedef struct hashTable_s * hashTable;
19 typedef unsigned int (*hashFunctionType) (const void * string);
23 typedef int (*hashEqualityType) (const void * key1, const void * key2);
26 * Return hash value of a string
27 * @param string string on which to calculate hash value
30 unsigned int hashFunctionString(const void * string);
33 * Compare two hash table entries for equality.
36 * @return 0 if entries are equal
38 int hashEqualityString(const void * key1, const void * key2);
42 * If keySize > 0, the key is duplicated within the table (which costs
43 * memory, but may be useful anyway.
44 * @param numBuckets number of hash buckets
45 * @param keySize size of key (0 if unknown)
46 * @param freeData Should data be freed when table is destroyed?
47 * @param fn function to generate hash value for key
48 * @param eq function to compare hash keys for equality
49 * @return pointer to initialized hash table
51 hashTable htCreate(int numBuckets, size_t keySize, int freeData,
52 hashFunctionType fn, hashEqualityType eq);
56 * @param ht pointer to hash table
59 hashTable htFree( hashTable ht);
62 * Add item to hash table.
63 * @param ht pointer to hash table
64 * @param key pointer to key
65 * @param data pointer to data value
67 void htAddEntry(hashTable ht, const void * key,
71 * Retrieve item from hash table.
72 * @param ht pointer to hash table
73 * @param key pointer to key value
74 * @retval data address to store data value from bucket
75 * @retval dataCount address to store data value size from bucket
76 * @retval tableKey address to store key value from bucket (may be NULL)
77 * @return 0 on success, 1 if the item is not found.
79 int htGetEntry(hashTable ht, const void * key,
82 const void ** tableKey);
85 * Check for key in hash table.
86 * @param ht pointer to hash table
87 * @param key pointer to key value
88 * @return 1 if the key is present, 0 otherwise
90 int htHasEntry(hashTable ht, const void * key);