Looking for an array (vs linked list) hash table in C

I am looking for a hash table implementation in C that stores its objects in (two-dimensional) arrays, rather than linked lists. that is, if a collision occurs, the object causing the collision will be stored in the next free row index, rather than clicking on the head and the first element of the linked list.

plus, the objects themselves should be copied to the hash table, and not indicated by pointers. (objects do not live throughout the entire program, but in the table).

I know that such an implementation can have serious performance flaws and is not a “standard hashing method,” but since I am working on a very special system architecture, I need these characteristics.

thank

+5
source share
3 answers

Super simple implementation:

char hashtable[MAX_KEY][MAX_MEMORY];
int counts[MAX_KEY] = {0}; 

/* Inserting something into the table */
SomeStruct* some_struct;
int hashcode = compute_code(some_struct);
int size = sizeof(SomeStruct); 
memcpy(hashtable[hashcode] + counts[hashcode] * size, some_struct, size);
++counts[hashcode];

Do not forget to check MAX_MEMORY.

+6
source

I assume that your system does not allow dynamic memory allocation. Therefore, you need to determine the front array boundaries that are reasonable for your data (the number of shared objects and the maximum expected collisions) and an additionally customizable hash function for your objects, so it’s best to implement your own hash table.

+1
source

C, ++, Google Sparse Hash - . , null.

0

All Articles