This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Defines | |
| #define | DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) |
| #define | DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) |
| #define | DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) |
Functions | |
| hashtable * | create_hashtable (unsigned int minsize, unsigned int(*hashfunction)(void *), int(*key_eq_fn)(void *, void *)) |
| int | hashtable_insert (struct hashtable *h, void *k, void *v) |
| void * | hashtable_search (struct hashtable *h, void *k) |
| void * | hashtable_remove (struct hashtable *h, void *k) |
| unsigned int | hashtable_count (struct hashtable *h) |
| void | hashtable_destroy (struct hashtable *h, int free_values) |
| #define DEFINE_HASHTABLE_INSERT | ( | fnname, | |||
| keytype, | |||||
| valuetype | ) |
Value:
int fnname (struct hashtable *h, keytype *k, valuetype *v) \ { \ return hashtable_insert(h,k,v); \ }
Definition at line 132 of file hashtable.h.
| #define DEFINE_HASHTABLE_REMOVE | ( | fnname, | |||
| keytype, | |||||
| valuetype | ) |
Value:
valuetype * fnname (struct hashtable *h, keytype *k) \ { \ return (valuetype *) (hashtable_remove(h,k)); \ }
Definition at line 168 of file hashtable.h.
| #define DEFINE_HASHTABLE_SEARCH | ( | fnname, | |||
| keytype, | |||||
| valuetype | ) |
Value:
valuetype * fnname (struct hashtable *h, keytype *k) \ { \ return (valuetype *) (hashtable_search(h,k)); \ }
Definition at line 150 of file hashtable.h.
| struct hashtable* create_hashtable | ( | unsigned int | minsize, | |
| unsigned int(*)(void *) | hashfunction, | |||
| int(*)(void *, void *) | key_eq_fn | |||
| ) |
Definition at line 62 of file hashtable.c.
References FREE, h, MALLOC, NULL, prime_table_length, and size.
Referenced by createGetHashTable(), CreateHashtable_string(), createSetHashTable(), and myhcreate().
00065 { 00066 struct hashtable *h; 00067 unsigned int pindex, size = primes[0]; 00068 /* Check requested hashtable isn't too large */ 00069 if (minsize > (1u << 30)) return NULL; 00070 /* Enforce size as prime */ 00071 for (pindex=0; pindex < prime_table_length; pindex++) { 00072 if (primes[pindex] > minsize) { size = primes[pindex]; break; } 00073 } 00074 h = (struct hashtable *)MALLOC(sizeof(struct hashtable)); 00075 if (NULL == h) return NULL; /*oom*/ 00076 h->table = (struct entry **)MALLOC(sizeof(struct entry*) * size); 00077 if (NULL == h->table) { FREE(h); return NULL; } /*oom*/ 00078 memset(h->table, 0, size * sizeof(struct entry *)); 00079 h->tablelength = size; 00080 h->primeindex = pindex; 00081 h->entrycount = 0; 00082 h->hashfn = hashf; 00083 h->eqfn = eqf; 00084 h->loadlimit = (unsigned int) ceil(size * max_load_factor); 00085 return h; 00086 }
Here is the caller graph for this function:

Definition at line 162 of file hashtable.c.
References h.
00163 { 00164 return h->entrycount; 00165 }
Definition at line 251 of file hashtable.c.
References f(), FREE, freekey, h, entry::next, NULL, and table.
Referenced by destroyGetHashTable(), DestroyHashtable_string(), destroySetHashTable(), DisposeHashTableScilabErrors(), DisposeHashTableScilabMenus(), DisposeHashTableScilabMessages(), and myhdestroy().
00252 { 00253 unsigned int i; 00254 struct entry *e, *f; 00255 struct entry **table = h->table; 00256 if (free_values) 00257 { 00258 for (i = 0; i < h->tablelength; i++) 00259 { 00260 e = table[i]; 00261 while (NULL != e) 00262 { f = e; e = e->next; freekey(f->k); FREE(f->v); FREE(f); } 00263 } 00264 } 00265 else 00266 { 00267 for (i = 0; i < h->tablelength; i++) 00268 { 00269 e = table[i]; 00270 while (NULL != e) 00271 { f = e; e = e->next; freekey(f->k); FREE(f); } 00272 } 00273 } 00274 FREE(h->table); 00275 FREE(h); 00276 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 169 of file hashtable.c.
References entry::h, h, hash(), hashtable_expand(), indexFor(), entry::k, MALLOC, entry::next, NULL, and entry::v.
Referenced by insertGetHashtable(), InsertHashtable_string(), and insertSetHashtable().
00170 { 00171 /* This method allows duplicate keys - but they shouldn't be used */ 00172 unsigned int index_; 00173 struct entry *e; 00174 if (++(h->entrycount) > h->loadlimit) 00175 { 00176 /* Ignore the return value. If expand fails, we should 00177 * still try cramming just this value into the existing table 00178 * -- we may not have memory for a larger table, but one more 00179 * element may be ok. Next time we insert, we'll try expanding again.*/ 00180 hashtable_expand(h); 00181 } 00182 e = (struct entry *)MALLOC(sizeof(struct entry)); 00183 if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ 00184 e->h = hash(h,k); 00185 index_ = indexFor(h->tablelength,e->h); 00186 e->k = k; 00187 e->v = v; 00188 e->next = h->table[index_]; 00189 h->table[index_] = e; 00190 return -1; 00191 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void* hashtable_remove | ( | struct hashtable * | h, | |
| void * | k | |||
| ) |
Definition at line 217 of file hashtable.c.
References FREE, freekey, entry::h, h, hash(), indexFor(), entry::k, entry::next, NULL, entry::v, and v.
Referenced by RemoveHastable_string().
00218 { 00219 /* TODO: consider compacting the table when the load factor drops enough, 00220 * or provide a 'compact' method. */ 00221 00222 struct entry *e; 00223 struct entry **pE; 00224 void *v; 00225 unsigned int hashvalue, index_; 00226 00227 hashvalue = hash(h,k); 00228 index_ = indexFor(h->tablelength,hash(h,k)); 00229 pE = &(h->table[index_]); 00230 e = *pE; 00231 while (NULL != e) 00232 { 00233 /* Check hash value to short circuit heavier comparison */ 00234 if ((hashvalue == e->h) && (h->eqfn(k, e->k))) 00235 { 00236 *pE = e->next; 00237 h->entrycount--; 00238 v = e->v; 00239 freekey(e->k); 00240 FREE(e); 00241 return v; 00242 } 00243 pE = &(e->next); 00244 e = e->next; 00245 } 00246 return NULL; 00247 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void* hashtable_search | ( | struct hashtable * | h, | |
| void * | k | |||
| ) |
Definition at line 195 of file hashtable.c.
References entry::h, h, hash(), indexFor(), entry::k, entry::next, NULL, and entry::v.
Referenced by searchGetHashtable(), SearchHashtable_string(), and searchSetHashtable().
00196 { 00197 struct entry *e; 00198 unsigned int hashvalue, index_; 00199 hashvalue = hash(h,k); 00200 index_ = indexFor(h->tablelength,hashvalue); 00201 e = h->table[index_]; 00202 while (NULL != e) 00203 { 00204 /* Check hash value to short circuit heavier comparison */ 00205 if ((hashvalue == e->h) && (h->eqfn(k, e->k))) 00206 { 00207 return e->v; 00208 } 00209 00210 e = e->next; 00211 } 00212 return NULL; 00213 }
Here is the call graph for this function:

Here is the caller graph for this function:

1.5.1