-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhashtable.cpp
54 lines (49 loc) · 1.16 KB
/
hashtable.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
#include "myutils.h"
#include "syncmerindex.h"
#include "alpha.h"
void SyncmerIndex::CountPlus()
{
asserta(m_PlusCounts == 0);
m_PlusCounts = myalloc(byte, m_SlotCount);
zero(m_PlusCounts, m_SlotCount);
const uint K = GetKmerCount();
for (uint SeqPos = 0; SeqPos < K; ++SeqPos)
{
if (IsSyncmer(SeqPos))
{
uint64 Kmer = m_Kmers[SeqPos];
uint64 Hash = KmerToHash(Kmer);
uint64 Slot = Hash%m_SlotCount;
if (m_PlusCounts[Slot] < 255)
++m_PlusCounts[Slot];
}
}
}
void SyncmerIndex::SetHashTable(uint SlotCount)
{
m_SlotCount = SlotCount;
m_HashTable.clear();
m_HashTable.resize(m_SlotCount, UINT32_MAX);
CountPlus();
const uint K = GetKmerCount();
for (uint SeqPos = 0; SeqPos < K; ++SeqPos)
{
if (IsSyncmer(SeqPos))
{
uint64 Kmer = m_Kmers[SeqPos];
uint64 Hash = KmerToHash(Kmer);
uint64 Slot = Hash%m_SlotCount;
if (m_PlusCounts[Slot] == 1)
{
asserta(Slot < SIZE(m_HashTable));
m_HashTable[Slot] = SeqPos;
}
}
}
}
uint32 SyncmerIndex::GetPos(uint64 Slot) const
{
asserta(Slot < SIZE(m_HashTable));
uint32 Pos = m_HashTable[Slot];
return Pos;
}