C Hash Table is a simple implementation of a hash table for C.
Here's the list of functions:
Name | Description |
---|---|
ht_create() |
Creates empty hash table |
ht_delete() |
Deletes existing table |
ht_get() |
Gets value of a given key |
ht_set() |
Sets/creates key-value pair |
ht_length() |
Returns length of a hash table |
f1nva_hash() |
F1NVa hashing algorithm |
gxhash() |
GxHash hashing algorithm |
git clone https://github.com/georghegel/chashtable.git
cd chashtable
make hashtable.a
# Next steps depends on your project.
# For project with main.c:
gcc main.c hashtable.a -o myprogram
needs to be implemented
There is a lot of hash functions: cyclic redundancy checks, checksums, universal hash function families, non-cryptographic hash functions, keyed/unkeyed cryptographic hash functions.
[Wikipedia Article]
Key concepts:
FNV Prime: 1099511628211
(for 64-bit, unsigned integer)
FNV offset basis: 14695981039346656037
(for 64-bit, unsigned integer)
XOR
and MUL
operations
As simple as this code:
uint64_t fnv1a_hash(const char* key) {
uint64_t hash = FNV_offset_basis;
for (const char* p = key; *p; p++) {
hash ^= (uint64_t)(unsigned char)(*p);
hash *= FNV_prime;
}
return hash;
}
needs to be implemented
- Tests
- Performance tests
- GxHash hashing algorithm