SphinxBase 5prealpha
|
A note by ARCHAN at 20050510: Technically what we use is so-called "hash table with buckets" which is very nice way to deal with external hashing. More...
#include <hash_table.h>
Data Fields | |
const char * | key |
size_t | len |
Key string, NULL if this is an empty slot. | |
void * | val |
Key-length; the key string does not have to be a C-style NULL terminated string; it can have arbitrary binary bytes. | |
struct hash_entry_s * | next |
Value associated with above key. | |
A note by ARCHAN at 20050510: Technically what we use is so-called "hash table with buckets" which is very nice way to deal with external hashing.
There are definitely better ways to do internal hashing (i.e. when everything is stored in the memory.) In Sphinx 3, this is a reasonable practice because hash table is only used in lookup in initialization or in lookups which is not critical for speed. Another note by ARCHAN at 20050703: To use this data structure properly, it is very important to realize that the users are required to handle memory allocation of the C-style keys. The hash table will not make a copy of the memory allocated for any of the C-style key. It will not allocate memory for it. It will not delete memory for it. As a result, the following code sniplet will cause memory leak.
while (1){ str=(char*)ckd_calloc(str_length,sizeof(char*)) if(hash_enter(ht,str,id)!=id){ printf("fail to add key str %s with val id %d\n",str,id)} } A note by dhuggins on 20061010: Changed this to use void * instead of int32 as the value type, so that arbitrary objects can be inserted into a hash table (in a way that won't crash on 64-bit machines ;) The hash table structures. Each hash table is identified by a hash_table_t structure. hash_table_t.table is pre-allocated for a user-controlled max size, and is initially empty. As new entries are created (using hash_enter()), the empty entries get filled. If multiple keys hash to the same entry, new entries are allocated and linked together in a linear list.
Definition at line 149 of file hash_table.h.
const char* hash_entry_s::key |
Definition at line 150 of file hash_table.h.
size_t hash_entry_s::len |
Key string, NULL if this is an empty slot.
NOTE that the key must not be changed once the entry has been made.
Definition at line 153 of file hash_table.h.
Referenced by hash_table_display().
struct hash_entry_s* hash_entry_s::next |
Value associated with above key.
Definition at line 156 of file hash_table.h.
Referenced by hash_table_display(), hash_table_empty(), hash_table_free(), and hash_table_iter_next().
void* hash_entry_s::val |
Key-length; the key string does not have to be a C-style NULL terminated string; it can have arbitrary binary bytes.
Definition at line 155 of file hash_table.h.
Referenced by cmd_ln_free_r(), hash_table_display(), hash_table_lookup(), hash_table_lookup_bkey(), jsgf_grammar_free(), ngram_model_read_classdef(), and ngram_model_set_read().