-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCHashTable.cc
38 lines (31 loc) · 1.01 KB
/
CHashTable.cc
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
#include "CHashTable.h"
#define TABLE_SIZE (8*1024*1024)
/***************************************************************
* constructor
***************************************************************/
CHashTable::CHashTable()
: m_table()
{
m_table.reserve(TABLE_SIZE);
}
/***************************************************************
* insert
***************************************************************/
void CHashTable::insert(const CHashEntry& hashEntry)
{
uint32_t ix = hashEntry.m_hashValue & (TABLE_SIZE - 1);
m_table[ix] = hashEntry; // Overwrite any existing value
} // end of insert
/***************************************************************
* find
***************************************************************/
bool CHashTable::find(uint64_t hashValue, CHashEntry& hashEntry) const
{
uint32_t ix = hashValue & (TABLE_SIZE - 1);
if (m_table[ix].m_hashValue == hashValue)
{
hashEntry = m_table[ix];
return true;
}
return false;
} // end of find