/* hash.h - Don Yang (uguu.org) 12/27/05 */ #ifndef HASH_H__ #define HASH_H__ #include typedef struct { /*@only@*/void *key; /*@only@*//*@null@*/void *value; size_t key_size, value_size; unsigned int hash; } HashTableEntry; typedef struct { size_t size, capacity; /*@only@*//*@notnull@*/HashTableEntry *entries; } HashTable; /* Create hash table at least as large as specified capacity */ /*@only@*/HashTable *HashTable_create(size_t capacity); /* Free hash table */ void HashTable_destroy(/*@only@*//*@notnull@*/HashTable *h) /*@releases h@*/; /* Free hash table using alternative free function */ void HashTable_destroy_custom(/*@only@*//*@notnull@*/HashTable *h, void (*free_value)(void*)) /*@releases h@*/; /* Add (key, value) pair to hash table. If key exists already, replaces existing value. Keys can not be NULL but values can be NULL. Calls abort() if there isn't enough memory. */ void HashTable_add(HashTable *h, /*@observer@*/void *key, size_t key_size, /*@observer@*/void *value, size_t value_size); /* Remove (key, value) pair from hash table. Does nothing if the key doesn't exist. */ void HashTable_remove(HashTable *h, /*@observer@*/void *key, size_t key_size); /* Find value from hash table. Returns NULL if not found. */ /*@null@*//*@dependent@*/ void *HashTable_find(/*@observer@*/HashTable *h, /*@observer@*/void *key, size_t key_size, /*@out@*//*@null@*/size_t *value_size); #endif