Lines Matching defs:tbl

64   hashtable *tbl;
69 tbl = malloc(sizeof(hashtable));
70 if (tbl == NULL)
73 tbl->entries = calloc(sizeof(hashtable_entry *), table_size);
74 if (tbl->entries == NULL)
77 tbl->table_size = table_size;
78 tbl->usage = 0;
79 tbl->key_size = key_size;
80 tbl->value_size = value_size;
82 return (tbl);
85 free(tbl);
93 * Places the key-value pair to the hashtable tbl.
105 hashtable_put(hashtable *tbl, const void *key, const void *value)
109 if (tbl->table_size == tbl->usage)
115 hash = hash32_buf(key, tbl->key_size, hash) % tbl->table_size;
125 if (tbl->entries[hash] == NULL)
127 else if (memcmp(tbl->entries[hash]->key, key, tbl->key_size) == 0)
129 memcpy(tbl->entries[hash]->value, value, tbl->value_size);
134 if (++hash == tbl->table_size)
140 tbl->entries[hash] = malloc(sizeof(hashtable_entry));
141 if (tbl->entries[hash] == NULL)
147 tbl->entries[hash]->key = malloc(tbl->key_size);
148 if (tbl->entries[hash]->key == NULL)
154 tbl->entries[hash]->value = malloc(tbl->value_size);
155 if (tbl->entries[hash]->value == NULL)
161 memcpy(tbl->entries[hash]->key, key, tbl->key_size);
162 memcpy(tbl->entries[hash]->value, value, tbl->value_size);
163 tbl->usage++;
170 free(tbl->entries[hash]->key);
172 free(tbl->entries[hash]);
179 **hashtable_lookup(const hashtable *tbl, const void *key)
183 hash = hash32_buf(key, tbl->key_size, hash) % tbl->table_size;
187 if (tbl->entries[hash] == NULL)
189 else if (memcmp(key, tbl->entries[hash]->key, tbl->key_size) == 0)
192 return (&tbl->entries[hash]);
195 if (++hash == tbl->table_size)
201 * Retrieves the value for key from the hash table tbl and places
207 hashtable_get(hashtable *tbl, const void *key, void *value)
211 entry = hashtable_lookup(tbl, key);
218 memcpy(value, (*entry)->value, tbl->value_size);
225 * tbl. Returns HASH_OK if the entry has been found and removed
229 hashtable_remove(hashtable *tbl, const void *key)
233 entry = hashtable_lookup(tbl, key);
245 tbl->usage--;
251 * Frees the resources associated with the hash table tbl.
254 hashtable_free(hashtable *tbl)
256 if (tbl == NULL)
259 for (unsigned int i = 0; i < tbl->table_size; i++)
260 if ((tbl->entries[i] != NULL))
262 free(tbl->entries[i]->key);
263 free(tbl->entries[i]->value);
266 free(tbl->entries);