Debian Codegraph @

vendor/btl_bloomfilter/Examples/RollingFilterLoad.cpp

raw
1 #include "BloomFilter.hpp"
2 #include <string>
3 #include <vector>
4
5 using namespace std;
6
7 /** stores state between calls to rolling hash */
8 struct RollingHashState
9 {
10 /* seed hash value for current k-mer */
11 uint64_t hash;
12 /* seed hash value for reverse complement of current k-mer */
13 uint64_t rcHash;
14 };
15
16 int
17 main(int argc, char** argv)
18 {
19 /* test sequence */
20 const string seq = "TAGAATCACCCAAAGA";
21 /* k-mer size */
22 const unsigned k = 5;
23 /* number of Bloom filter hash functions */
24 const unsigned numHashes = 4;
25 /* size of Bloom filter (in bits) */
26 const unsigned size = 1000;
27 /* hash values for current k-mer */
28 vector<size_t> hashes;
29
30 /* init Bloom filter */
31 BloomFilter bloom(size, numHashes, k);
32
33 /* init rolling hash state and compute hash values for first k-mer */
34 RollingHashState state;
35 string kmer0 = seq.substr(0, k);
36 hashes = bloom.multiHash(kmer0.c_str(), state.hash, state.rcHash);
37
38 /* load k-mers into Bloom filter using rolling hash */
39 for (unsigned i = 1; i < seq.length() - k + 1; ++i) {
40 /* "roll" hash values right to current k-mer */
41 char charOut = seq[i - 1];
42 char charIn = seq[i + k - 1];
43 hashes = bloom.multiHash(state.hash, state.rcHash, charOut, charIn);
44 /* insert current k-mer into Bloom filter */
45 bloom.insert(hashes);
46 }
47
48 return 0;
49 }