SDDSlib
|
Implements a hash table. More...
#include "standard.h"
#include "lookupa.h"
#include "hashtab.h"
#include "recycle.h"
Go to the source code of this file.
Functions | |
static void | hgrow (htab *t) |
htab * | hcreate (word logsize) |
Create a hash table. | |
void | hdestroy (htab *t) |
Destroy the hash table and free all its memory. | |
word | hfind (htab *t, ub1 *key, ub4 keyl) |
Find an item with a given key in the hash table. | |
word | hadd (htab *t, ub1 *key, ub4 keyl, void *stuff) |
Add an item to the hash table. | |
word | hdel (htab *t) |
word | hfirst (htab *t) |
Position the hash table on the first element. | |
word | hnbucket (htab *t) |
void | hstat (htab *t) |
Implements a hash table.
Keys are unique. Adding an item fails if the key is already there. Keys and items are pointed at, not copied. If you change the value of the key after it is inserted then hfind()
will not be able to find it. The hash table maintains a position that can be set and queried. The table length doubles dynamically and never shrinks. The insert that causes table doubling may take a long time. The table length splits when the table length equals the number of items. Comparisons usually take 7 instructions. Computing a hash value takes 35+6n instructions for an n-byte key.
Functions provided:
hcreate()
- create a hash tablehdestroy()
- destroy a hash tablehcount()
- the number of items in the hash tablehkey()
- key at the current positionhkeyl()
- key length at the current positionhstuff()
- stuff at the current positionhfind()
- find an item in the tablehadd()
- insert an item into the tablehdel()
- delete an item from the tablehstat()
- print statistics about the tablehfirst()
- position at the first item in the tablehnext()
- move the position to the next item in the table Definition in file hashtab.c.
word hadd | ( | htab * | t, |
ub1 * | key, | ||
ub4 | keyl, | ||
void * | stuff ) |
Add an item to the hash table.
Inserts an item into the hash table with the given key and associated data.
t | Pointer to the hash table. |
key | Key to add to the hash table. |
keyl | Length of the key. |
stuff | Data to associate with the key. |
Definition at line 207 of file hashtab.c.
htab * hcreate | ( | word | logsize | ) |
Create a hash table.
Initializes a hash table with an initial size of 2 raised to the power of logsize
.
logsize | Log base 2 of the initial size of the hash table. |
Definition at line 124 of file hashtab.c.
word hdel | ( | htab * | t | ) |
Definition at line 254 of file hashtab.c.
void hdestroy | ( | htab * | t | ) |
Destroy the hash table and free all its memory.
t | Pointer to the hash table to destroy. |
Definition at line 149 of file hashtab.c.
word hfind | ( | htab * | t, |
ub1 * | key, | ||
ub4 | keyl ) |
Find an item with a given key in the hash table.
Searches for an item with the specified key in the hash table.
t | Pointer to the hash table. |
key | Key to find. |
keyl | Length of the key. |
Definition at line 178 of file hashtab.c.
word hfirst | ( | htab * | t | ) |
Position the hash table on the first element.
Sets the current position to the first item in the hash table.
t | Pointer to the hash table. |
Definition at line 292 of file hashtab.c.
|
static |
Definition at line 82 of file hashtab.c.
word hnbucket | ( | htab * | t | ) |
Definition at line 306 of file hashtab.c.
void hstat | ( | htab * | t | ) |
Definition at line 334 of file hashtab.c.