-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathegtb_hash.cpp
More file actions
39 lines (33 loc) · 792 Bytes
/
Copy pathegtb_hash.cpp
File metadata and controls
39 lines (33 loc) · 792 Bytes
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
#include <assert.h>
#include "egtb_hash.h"
EgtbHash::EgtbHash() {
for (int i = 0; i < BUCKETS; i++) {
bucketCount[i] = 0;
}
count = 0;
}
void EgtbHash::clear() {
// Decrease bucket counts for used buckets only. Should be faster than
// zeroing all bucket counts.
while (count) {
bucketCount[dest[--count]]--;
}
}
void EgtbHash::add(unsigned index) {
int b = hash(index);
assert(bucketCount[b] < BUCKET_SIZE);
data[b][bucketCount[b]++] = index;
dest[count++] = b;
}
bool EgtbHash::contains(unsigned index) {
int b = hash(index);
data[b][bucketCount[b]] = index; // sentinel
unsigned i = 0;
while (data[b][i] != index) {
i++;
}
return i < bucketCount[b];
}
unsigned EgtbHash::hash(unsigned index) {
return (index * MULT) & (BUCKETS - 1);
}