A hashtable c implementation.
The key object is an union which supports char, long and void * data:
typedef union {
char char_t;
long long_t;
void * ptr_t;
} hash_key_t;
You can add more structures if you want. This object acts as the KEY in the hash table.
As I'm no sure the real type of keys, so you have to specify your own hash function, turn the key object into a hash code that will be very important for later HASH MAPPING.
almost same as the key object, you can attach any pointer to hash_data_t->ptr_t for much rich and personalized data.
Just because they are unions, I've no idea about how to get the hash code and how to compare them.
You can offer your hash function and key compare function in the init call:
CALLABLE int hash_table_new(
hash_table_t * table,
int init_size,
hash_func_ptr_t func_ptr,
hash_key_cmp_func_ptr_t hash_key_cmp_func_ptr);
See comments here!
The visit table strategy indices via this recurrence:
j = ((5*j) + 1) mod 2**i
There are always 2**i entries in the hash table, 8 for example. The visite order will be:
0 -> 1 -> 6 -> 7 -> 4 -> 5 -> 2 -> 3 -> 0 [and here it's repeating]
see hashtable.h for details.