forked from lemire/rollinghashcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example4.cpp
35 lines (27 loc) · 1018 Bytes
/
example4.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
34
35
#include <string>
#include <memory>
#include <cassert>
#include <iostream>
#include "cyclichash.h"
/**
* Test of the prepend and append functions to test slightly longer and slightly shorter n-grams.
*/
int main(int argc, char * argv[])
{
CyclicHash<uint64_t> hf(4, 64);
string input = "XABCDY";
string base(input.begin() + 1, input.end() - 1);
string extend(input.begin() + 1, input.end());
string prepend(input.begin(), input.end() - 1);
for (string::const_iterator j = base.begin(); j != base.end(); ++j)
{
hf.eat(*j);
}
std::cout << base << " " << hf.hash(base) << std::endl;
std::cout << prepend << " " << hf.hash_prepend(input[0]) << " " << hf.hash(prepend) << std::endl;
std::cout << extend << " " << hf.hash_extend(input.back()) << " " << hf.hash(extend) << std::endl;
assert(hf.hashvalue == hf.hash(base));
assert(hf.hash_prepend(input[0]) == hf.hash(prepend));
assert(hf.hash_extend(input.back()) == hf.hash(extend));
return 0;
}