5 * Hash table implemenation.
8 typedef struct hashTable_s * hashTable;
15 typedef unsigned int (*hashFunctionType) (const void * string) /*@*/;
17 typedef int (*hashEqualityType) (const void * key1, const void * key2) /*@*/;
20 * Return hash value of a string
21 * @param string string on which to calculate hash value
24 unsigned int hashFunctionString(const void * string) /*@*/;
27 * Compare two hash table entries for equality.
30 * @return 0 if entries are equal
32 int hashEqualityString(const void * key1, const void * key2) /*@*/;
36 * If keySize > 0, the key is duplicated within the table (which costs
37 * memory, but may be useful anyway.
38 * @param numBuckets number of hash buckets
39 * @param keySize size of key (0 if unknown)
40 * @param freeData should data be freed when table is destroyed?
41 * @param fn function to generate hash value for key
42 * @param eq function to compare hash keys for equality
43 * @return pointer to initialized hash table
45 hashTable htCreate(int numBuckets, int keySize, int freeData,
46 hashFunctionType fn, hashEqualityType eq) /*@*/;
50 * @param ht pointer to hash table
52 void htFree( /*@only@*/ hashTable ht);
55 * Add item to hash table.
56 * @param ht pointer to hash table
57 * @param key pointer to key
58 * @param data pointer to data value
60 void htAddEntry(hashTable ht, /*@owned@*/ const void * key,
61 /*@owned@*/ const void * data) /*@modifies ht */;
64 * Retrieve item from hash table.
65 * @param ht pointer to hash table
66 * @param key pointer to key value
67 * @retval data address to store data value from bucket
68 * @retval dataCount address to store data value size from bucket
69 * @retval tableKey address to store key value from bucket (may be NULL)
70 * @return 0 on success, 1 if the item is not found.
72 int htGetEntry(hashTable ht, const void * key, /*@out@*/ const void *** data,
73 /*@out@*/ int * dataCount, /*@out@*/ const void ** tableKey)
74 /*@modifies *data, *dataCount, *tableKey @*/;
77 * Check for key in hash table.
78 * @param ht pointer to hash table
79 * @param key pointer to key value
80 * @return 1 if the key is present, 0 otherwise
82 int htHasEntry(hashTable ht, const void * key) /*@*/;