hashtbl
a hash table package in C.
The other reusable hash table packages I've made were not quite
right for one reason or another. Sometimes they suffered from unecessary
complexity because they were too general.
The hash tables other people made also weren't quite right for me. I
wanted to be able to ...
- easily use as many hash tables as I want in one process
- use regular C "strings" (null-terminated character arrays) as the
keys
- store anything I want in any given hash table
The way those goals were met was ...
- to make the functions accept as the first parameter a pointer to a
hashtbl_t. You can create and use different hash tables by making
lots of hashtbl_t's, each with its own independent state.
- to assume that the keys will always be strings. This limits
generality, but I find it a great relief, since I almost always want
the hash keys to be strings. It also boosts performance, since we don't
need to use the extra level of indirection that allows
us to use arbitrary objects
as keys.
- to use void pointers as the data type for the hash table. You can
put a pointer to anything in the hash table. The hash table won't try
to free the pointer, copy the referenced data anywhere, or do anything
with the pointer at all. It just stores the address in the hash.
Simple and general.
download hashtbl-20001101.tar.gz
For more information see the example, "hashtest.c", included in the
distribution.
There is a more recent version of hashtbl bundled with integrit. I just haven't gotten around to updating the standalone release yet.