124 #ifndef _LIBUTIL_HASH_H_ 125 #define _LIBUTIL_HASH_H_ 128 #include <sphinxbase/sphinxbase_export.h> 175 #define hash_entry_val(e) ((e)->val) 176 #define hash_entry_key(e) ((e)->key) 177 #define hash_entry_len(e) ((e)->len) 178 #define hash_table_inuse(h) ((h)->inuse) 179 #define hash_table_size(h) ((h)->size) 197 #define HASH_CASE_YES 0 198 #define HASH_CASE_NO 1 228 #define hash_table_enter_int32(h,k,v) \ 229 ((int32)(long)hash_table_enter((h),(k),(void *)(long)(v))) 257 #define hash_table_replace_int32(h,k,v) \ 258 ((int32)(long)hash_table_replace((h),(k),(void *)(long)(v))) 315 #define hash_table_enter_bkey_int32(h,k,l,v) \ 316 ((int32)(long)hash_table_enter_bkey((h),(k),(l),(void *)(long)(v))) 338 #define hash_table_replace_bkey_int32(h,k,l,v) \ 339 ((int32)(long)hash_table_replace_bkey((h),(k),(l),(void *)(long)(v))) SPHINXBASE_EXPORT void * hash_table_delete_bkey(hash_table_t *h, const char *key, size_t len)
Like hash_table_delete, but with an explicitly specified key length, instead of a NULL-terminated...
SPHINXBASE_EXPORT int32 hash_table_lookup_int32(hash_table_t *h, const char *key, int32 *val)
Look up a 32-bit integer value in a hash table.
SPHINXBASE_EXPORT void * hash_table_enter_bkey(hash_table_t *h, const char *key, size_t len, void *val)
Like hash_table_enter, but with an explicitly specified key length, instead of a NULL-terminated, C-style key string.
hash_entry_t * ent
Current entry in that table.
SPHINXBASE_EXPORT int32 hash_table_lookup(hash_table_t *h, const char *key, void **val)
Look up a key in a hash table and optionally return the associated value.
SPHINXBASE_EXPORT void hash_table_display(hash_table_t *h, int32 showkey)
Display a hash-with-chaining representation on the screen.
SPHINXBASE_EXPORT int32 hash_table_lookup_bkey(hash_table_t *h, const char *key, size_t len, void **val)
Like hash_lookup, but with an explicitly specified key length, instead of a NULL-terminated, C-style key string.
int32 nocase
Number of valid entries in the table.
SPHINXBASE_EXPORT void * hash_table_replace(hash_table_t *h, const char *key, void *val)
Add a new entry with given key and value to hash table h.
struct hash_entry_s * next
Value associated with above key.
SPHINXBASE_EXPORT void hash_table_iter_free(hash_iter_t *itor)
Delete an unfinished iterator.
SPHINXBASE_EXPORT glist_t hash_table_tolist(hash_table_t *h, int32 *count)
Build a glist of valid hash_entry_t pointers from the given hash table.
int32 size
Primary hash table, excluding entries that collide.
A node in a generic list.
SPHINXBASE_EXPORT hash_iter_t * hash_table_iter(hash_table_t *h)
Start iterating over key-value pairs in a hash table.
Basic type definitions used in Sphinx.
int32 inuse
Primary hash table size, (is a prime#); NOTE: This is the number of primary entries ALLOCATED...
SPHINXBASE_EXPORT hash_table_t * hash_table_new(int32 size, int32 casearg)
Allocate a new hash table for a given expected size.
SPHINXBASE_EXPORT void hash_table_empty(hash_table_t *h)
Delete all entries from a hash_table.
SPHINXBASE_EXPORT void hash_table_free(hash_table_t *h)
Free the specified hash table; the caller is responsible for freeing the key strings pointed to by th...
struct hash_entry_s hash_entry_t
A note by ARCHAN at 20050510: Technically what we use is so-called "hash table with buckets" which is...
A note by ARCHAN at 20050510: Technically what we use is so-called "hash table with buckets" which is...
SPHINXBASE_EXPORT int32 hash_table_lookup_bkey_int32(hash_table_t *h, const char *key, size_t len, int32 *val)
Look up a 32-bit integer value in a hash table.
size_t len
Key string, NULL if this is an empty slot.
size_t idx
Index of next bucket to search.
hash_table_t * ht
Hash table we are iterating over.
Generic linked-lists maintenance.
SPHINXBASE_EXPORT void * hash_table_enter(hash_table_t *h, const char *key, void *val)
Try to add a new entry with given key and associated value to hash table h.
SPHINXBASE_EXPORT hash_iter_t * hash_table_iter_next(hash_iter_t *itor)
Get the next key-value pair in iteration.
SPHINXBASE_EXPORT void * hash_table_delete(hash_table_t *h, const char *key)
Delete an entry with given key and associated value to hash table h.
void * val
Key-length; the key string does not have to be a C-style NULL terminated string; it can have arbitrar...
SPHINXBASE_EXPORT void * hash_table_replace_bkey(hash_table_t *h, const char *key, size_t len, void *val)
Like hash_table_replace, but with an explicitly specified key length, instead of a NULL-terminated...