Created
March 2, 2017 21:51
-
-
Save skyylex/4a36d28320fd738e1d2037ef28d0dc6d to your computer and use it in GitHub Desktop.
StripedMap hash verification gist
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
#include <iostream> | |
static int size = 64; | |
int stripedMapPseudoHash(uintptr_t addr) { | |
return ((addr >> 4) ^ (addr >> 9)) % size; | |
} | |
int main(int argc, const char * argv[]) { | |
int numericMap[size]; | |
for (int i = 0; i < size; i++) { | |
numericMap[i] = 0; | |
} | |
for (int i = 0; i < 100; i++ ) { | |
void *p = malloc(502); | |
uintptr_t addr = reinterpret_cast<uintptr_t>(p); | |
int hash = stripedMapPseudoHash(addr); | |
printf("#%d. %d\n", i, hash); | |
numericMap[hash] = numericMap[hash] + 1; | |
} | |
for (int i = 0; i < size; i++) { | |
printf("Matches %d\n", numericMap[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment