Add a struct that represents the elements of the hashtable
This commit is contained in:
parent
c1fafc6246
commit
9ee3954d19
1 changed files with 17 additions and 3 deletions
20
main.c
20
main.c
|
|
@ -1,10 +1,11 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define WORD 32
|
||||
#define RAND_MAX 4294967296
|
||||
#define TRANSFORM_TABLE_MAX_RAND 4294967296
|
||||
#define DELTA 1
|
||||
|
||||
#ifdef __clang__
|
||||
|
|
@ -20,7 +21,20 @@ typedef struct
|
|||
unsigned int *transformation_table;
|
||||
int *hash_table;
|
||||
unsigned int table_size;
|
||||
}shash_hashtable_t;
|
||||
}shash_hashtable_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *key;
|
||||
int value;
|
||||
|
||||
// gets set to 1 if another key, collides with this elemnts location
|
||||
u_int8_t encountered_collision;
|
||||
|
||||
// On collision, this field stores, where in the hash table array the second key (with the same hash) is located
|
||||
int next_key_location;
|
||||
|
||||
}shash_table_element_t;
|
||||
|
||||
void shash_init_hashtable(shash_hashtable_t *hashtable, unsigned int table_size)
|
||||
{
|
||||
|
|
@ -30,7 +44,7 @@ void shash_init_hashtable(shash_hashtable_t *hashtable, unsigned int table_size)
|
|||
unsigned int *table = malloc((CHAR_MAX-CHAR_MIN)*sizeof(int));
|
||||
|
||||
for(int i = 0; i < CHAR_MAX-CHAR_MIN; i++){
|
||||
table[i] = rand();
|
||||
table[i] = TRANSFORM_TABLE_MAX_RAND * rand() / RAND_MAX;
|
||||
}
|
||||
hashtable->transformation_table = table;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue