@@ -88,3 +88,36 @@ cms_destroy(&cms);
8888
8989## Required Compile Flags
9090-lm
91+
92+
93+ ## Backward Compatible Hash Function
94+ To use the older count-min sketch (v0.1.8 or lower) that utilized the default hashing
95+ algorithm, then change use the following code as the hash function:
96+
97+ ``` c
98+ /* NOTE: The caller will free the results */
99+ static uint64_t* original_default_hash(unsigned int num_hashes, const char* str) {
100+ uint64_t *results = (uint64_t*)calloc(num_hashes, sizeof(uint64_t));
101+ char key[17] = {0}; // largest value is 7FFF,FFFF,FFFF,FFFF
102+ results[0] = __fnv_1a(str);
103+ for (unsigned int i = 1; i < num_hashes; ++i) {
104+ sprintf(key, "%" PRIx64 "", results[i-1]);
105+ results[i] = old_fnv_1a(key);
106+ }
107+ return results;
108+ }
109+
110+ static uint64_t old_fnv_1a(const char* key) {
111+ // FNV-1a hash (http://www.isthe.com/chongo/tech/comp/fnv/)
112+ int i, len = strlen(key);
113+ uint64_t h = 14695981039346656073ULL; // FNV_OFFSET 64 bit
114+ for (i = 0; i < len; ++i){
115+ h = h ^ (unsigned char) key[i];
116+ h = h * 1099511628211ULL; // FNV_PRIME 64 bit
117+ }
118+ return h;
119+ }
120+ ```
121+
122+ If using only older count-min sketch, then you can update the // FNV_OFFSET 64 bit
123+ to use ` 14695981039346656073ULL `
0 commit comments