-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.h
49 lines (39 loc) · 1.22 KB
/
hash.h
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef HASH_H
#define HASH_H
#include <iostream>
#include <cmath>
#include <random>
#include <chrono>
typedef std::size_t HASH_INDEX_T;
struct MyStringHash {
HASH_INDEX_T rValues[5] { 983132572, 1468777056, 552714139, 984953261, 261934300 };
MyStringHash(bool debug = true)
{
if(false == debug){
generateRValues();
}
}
// hash function entry point (i.e. this is h(k))
HASH_INDEX_T operator()(const std::string& k) const
{
// Add your code here
}
// A likely helper function is to convert a-z,0-9 to an integral value 0-35
HASH_INDEX_T letterDigitToNumber(char letter) const
{
// Add code here or delete this helper function if you do not want it
}
// Code to generate the random R values
void generateRValues()
{
// obtain a seed from the system clock:
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 generator (seed); // mt19937 is a standard random number generator
// Simply call generator() [it has an operator()] to get another random number
for(int i{ 0 }; i < 5; ++i)
{
rValues[i] = generator();
}
}
};
#endif