forked from xtaci/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversal_hash_demo.cpp
More file actions
33 lines (28 loc) · 814 Bytes
/
universal_hash_demo.cpp
File metadata and controls
33 lines (28 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*******************************************
* DANIEL'S PRIVATE ALGORITHM IMPLEMENTAIONS
* Universal Hashing
* Features:
* 1. randomized hash function, random a1,a2.. a32
* 2. alloc your storage larger than UHash->prime
* 3. the collsion expectation:
E[Cx] = (n - 1 ) / m (n: number of elements, m: bucket size--prime number)
* 4. this set has m^(r+1) different hash functions.
*******************************************/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "universal_hash.h"
using namespace alg;
int main(void)
{
int MAXELEMENT = 1000;
struct UHash params;
srand(time(NULL));
uhash_init(¶ms, MAXELEMENT);
int i;
for (i = 0; i < MAXELEMENT; i++)
{
printf("hashing %d --> %d\n", i, uhash_integer(¶ms, i));
}
printf("prime %d\n", params.prime);
}