-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhash.cpp
39 lines (33 loc) · 912 Bytes
/
hash.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
#include <experimental/string_view>
#include "tbb/concurrent_unordered_map.h"
#include "tbb/concurrent_vector.h"
#include "hash.hpp"
#include "read.hpp"
/* Constructors */
Hash::Hash(int _K) {
K = _K;
reads.clear();
}
Hash::~Hash() {
//delete[] maps;
}
/* Computes matches. */
const tbb::concurrent_vector<Read*>& Hash::matches(std::experimental::string_view bases) {
HashMap::iterator iter = maps.find(bases);
if (iter != maps.end())
return iter->second;
return reads;
}
/* Adds read READ to hashmaps. */
void Hash::add(std::experimental::string_view bases, Read *read) {
HashMap::iterator iter = maps.find(bases);
if (iter != maps.end())
iter->second.push_back(read);
else {
tbb::concurrent_vector<Read*> newreads;
newreads.push_back(read);
std::pair<HashMap::iterator, bool> res = maps.insert(make_pair(bases, newreads));
if (!res.second)
res.first->second.push_back(read);
}
}