forked from lemire/rollinghashcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.cpp
56 lines (49 loc) · 1.31 KB
/
example.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <string>
#include <vector>
#include <memory>
#include <iostream>
#include "rabinkarphash.h"
int main(int argc, char * argv[])
{
size_t q = 3;
size_t k = 4;
typedef KarpRabinHash<> HashFunction;
std::vector<std::unique_ptr<HashFunction> > hashPtr(q);
for(size_t z = 0; z < hashPtr.size(); ++z)
{
std::unique_ptr<HashFunction> & ptr = hashPtr[z];
ptr.reset(new HashFunction(k, 12));
}
std::string str = "ACGTAACGT";
for (size_t j = 0; j < k; j++)
{
for(size_t z = 0; z < hashPtr.size(); ++z)
{
std::unique_ptr<HashFunction> & ptr = hashPtr[z];
ptr->eat(str[j]);
}
}
for (size_t i = 0;; i++)
{
std::cout << std::string(str.begin() + i, str.begin() + i + k);
for(size_t z = 0; z < hashPtr.size(); ++z)
{
std::unique_ptr<HashFunction> & ptr = hashPtr[z];
std::cout << ' ' << ptr->hashvalue;
}
std::cout << std::endl;
if (i + k < str.size())
{
for(size_t z = 0; z < hashPtr.size(); ++z)
{
std::unique_ptr<HashFunction> & ptr = hashPtr[z];
ptr->update(str[i], str[i + k]);
}
}
else
{
break;
}
}
return 0;
}