Closed gf777 closed 2 weeks ago
Actually, I realize that the syntax is the same:
maps[m] = new ParallelMap(0, KeyHasher(seqBuf[m].seq, prefix, k), KeyEqualTo(seqBuf[m].seq, prefix, k));
And:
struct KeyHasher {
uint8_t prefix;
uint32_t k;
uint64_t* pows;
Buf2bit<> *seqBuf;
KeyHasher() {}
KeyHasher(Buf2bit<> *seqBuf, uint8_t prefix, uint32_t k) : prefix(prefix), k(k), seqBuf(seqBuf) {
pows = new uint64_t[prefix];
for(uint8_t p = 0; p<prefix; ++p) // precomputes the powers of k
pows[p] = (uint64_t) pow(4,p);
}
std::size_t operator()(const Key& key) const {
uint64_t fw = 0, rv = 0, offset = key.getKmer(); // hashes for both forward and reverse complement sequence
for(uint8_t c = 0; c<prefix; ++c) { // for each position up to prefix len
fw += seqBuf->at(offset+c) * pows[c]; // base * 2^N
rv += (3-seqBuf->at(offset+k-1-c)) * pows[c]; // we walk the kmer backward to compute the rvcp
}
// return fw < rv ? 0 : 0; // even if they end up in the same bucket it's fine!
return fw < rv ? fw : rv;
}
};
@gf777 Glad you found your answer, sorry I wasn't more helpful, I'm very busy these days.
Hi @greg7mdp I was looking here https://github.com/greg7mdp/parallel-hashmap/issues/125 And I thought I could use the same syntax for parallel_hash_map but it doesn't work:
What is the right syntax? Thanks!!