forked from lemire/rollinghashcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example64bits.cpp
33 lines (28 loc) · 1000 Bytes
/
example64bits.cpp
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
#include <string>
#include <vector>
#include <memory>
#include <iostream>
// Example of 64-bit hashing
#include "cyclichash.h"
int main(int argc, char * argv[])
{
CyclicHash<uint64> hf(5,64);
string input = "ABCDE";
hf.eat(input[0]);//A
hf.eat(input[1]);//B
hf.eat(input[2]);//C
hf.eat(input[3]);//D
cout<<"Hash value of ABCD is " << hf.hashvalue << endl;
// we check the answer going the long way...
const std::vector<unsigned char> charvectslice(input.begin(), input.begin()+4);
uint64_t trueanswerslice = hf.hash(charvectslice);
if(trueanswerslice != hf.hashvalue ) throw runtime_error("bug");
// we continue
hf.eat(input[4]);//E
cout<<"Hash value of ABCDE is " << hf.hashvalue << endl;
// we check the answer going the long way
const std::vector<unsigned char> charvect(input.begin(), input.end());
uint64_t trueanswer = hf.hash(charvect);
if(trueanswer != hf.hashvalue ) throw runtime_error("bug");
return 0;
}