Created
February 17, 2016 09:56
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int * getBuckets(uint32_t key, struct Table *td) { | |
static int bucketID[TABLE_SIZE]; | |
uint32_t out; | |
MurmurHash3_x86_32((const void *)&key, sizeof(uint32_t), SEED, &out); //calculate the hash value for each subtables, | |
for (int i = 0; i < TABLE_SIZE; i++) { | |
if (td->subtables[i].buckets[out % SUBTABLE_SIZE].counter == 0) { | |
bucketID[i] = -1; | |
continue; | |
} | |
bucketID[i] = out % SUBTABLE_SIZE; // Then divide hash value by subtable size | |
} | |
return bucketID; | |
} | |
bool lookup(uint32_t key, struct Table *td) { | |
int *bucketList = getBuckets(key, td); | |
bool emptyArr = checkEmptyArray(bucketList); | |
if (emptyArr) { | |
for (int i = 0; i < TABLE_SIZE; i++) { | |
if (bucketList[i] != -1) { | |
for (int j = 0; j < BUCKET_HEIGHT; j++) { | |
if (td->subtables[i].buckets[bucketList[i]].fingerprint[j] == key) { | |
return true; | |
} | |
} | |
} | |
} | |
} else { | |
printf("[Error]: Key does not exists\n"); | |
return false; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment