Add compatibilty for gcc compiler
This commit is contained in:
parent
6ae406787a
commit
c1fafc6246
1 changed files with 9 additions and 4 deletions
13
main.c
13
main.c
|
|
@ -2,13 +2,17 @@
|
|||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include <builtins.h>
|
||||
|
||||
#define WORD 32
|
||||
#define RAND_MAX 4294967296
|
||||
#define DELTA 1
|
||||
|
||||
#ifdef __clang__
|
||||
#include <builtins.h>
|
||||
#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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue