diff --git a/main.c b/main.c index 412b192..ad65707 100644 --- a/main.c +++ b/main.c @@ -2,13 +2,17 @@ #include #include #include -#include #define WORD 32 #define RAND_MAX 4294967296 #define DELTA 1 +#ifdef __clang__ +#include #define rot32_left(x, y) __builtin_rotateleft32(x, y) +#else +#define rot32_left(x, y) (x << y) | (x >> 32 - y) +#endif // Contains everything the functions for the hashtables need, to work with, including the hash table itself typedef struct @@ -21,7 +25,8 @@ typedef struct void shash_init_hashtable(shash_hashtable_t *hashtable, unsigned int table_size) { // Create a random transformation table - srand(time(NULL)); + srand(0); + //srand(time(NULL)); unsigned int *table = malloc((CHAR_MAX-CHAR_MIN)*sizeof(int)); for(int i = 0; i < CHAR_MAX-CHAR_MIN; i++){ @@ -39,7 +44,7 @@ unsigned int shash_hash(char *key, unsigned int len, shash_hashtable_t *hashtabl unsigned int hash_word = 0; for(int i = 0; i < len; i++) { - hash_word = rot32_left(hash_word, DELTA); + hash_word = rot32_left(hash_word, 1); hash_word = hash_word ^ hashtable->transformation_table[key[i]]; } @@ -64,7 +69,7 @@ int main(void) // Initialize an empty hashtable shash_hashtable_t hashtable; shash_init_hashtable(&hashtable, 100); - + shash_set("INC", 3, 41, &hashtable); int retrieved_val = shash_get("INC", 3, &hashtable);