Skip to content

Instantly share code, notes, and snippets.

@skyylex
Created March 2, 2017 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyylex/4a36d28320fd738e1d2037ef28d0dc6d to your computer and use it in GitHub Desktop.
Save skyylex/4a36d28320fd738e1d2037ef28d0dc6d to your computer and use it in GitHub Desktop.
StripedMap hash verification gist
#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