Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further fixed hash function #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions count_min_sketch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ CountMinSketch::CountMinSketch(float ep, float gamm) {
}
// initialize d pairwise independent hashes
srand(time(NULL));
hashes = new int* [d];
hashes = new unsigned long* [d];
for (i = 0; i < d; i++) {
hashes[i] = new int[2];
hashes[i] = new unsigned long[2];
genajbj(hashes, i);
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ void CountMinSketch::update(int item, int c) {
total = total + c;
unsigned int hashval = 0;
for (unsigned int j = 0; j < d; j++) {
hashval = ((long)hashes[j][0]*item+hashes[j][1])%LONG_PRIME%w;
hashval = (hashes[j][0]*item+hashes[j][1])%LONG_PRIME%w;
C[j][hashval] = C[j][hashval] + c;
}
}
Expand All @@ -95,7 +95,7 @@ unsigned int CountMinSketch::estimate(int item) {
int minval = numeric_limits<int>::max();
unsigned int hashval = 0;
for (unsigned int j = 0; j < d; j++) {
hashval = ((long)hashes[j][0]*item+hashes[j][1])%LONG_PRIME%w;
hashval = (hashes[j][0]*item+hashes[j][1])%LONG_PRIME%w;
minval = MIN(minval, C[j][hashval]);
}
return minval;
Expand All @@ -108,9 +108,9 @@ unsigned int CountMinSketch::estimate(const char *str) {
}

// generates aj,bj from field Z_p for use in hashing
void CountMinSketch::genajbj(int** hashes, int i) {
hashes[i][0] = int(float(rand())*float(LONG_PRIME)/float(RAND_MAX) + 1);
hashes[i][1] = int(float(rand())*float(LONG_PRIME)/float(RAND_MAX) + 1);
void CountMinSketch::genajbj(unsigned long** hashes, int i) {
hashes[i][0] = (unsigned long)(float(rand())*float(LONG_PRIME-2)/float(RAND_MAX) + 1);
hashes[i][1] = (unsigned long)(float(rand())*float(LONG_PRIME-2)/float(RAND_MAX) + 1);
}

// generates a hash value for a sting
Expand Down
6 changes: 3 additions & 3 deletions count_min_sketch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**/

// define some constants
# define LONG_PRIME 4294967311l
# define LONG_PRIME 4294967311ul
# define MIN(a,b) (a < b ? a : b)

/** CountMinSketch class definition here **/
Expand Down Expand Up @@ -34,10 +34,10 @@ class CountMinSketch {

// array of hash values for a particular item
// contains two element arrays {aj,bj}
int **hashes;
unsigned long **hashes;

// generate "new" aj,bj
void genajbj(int **hashes, int i);
void genajbj(unsigned long **hashes, int i);

public:
// constructor
Expand Down