-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranspositionTable.java
More file actions
69 lines (58 loc) · 1.76 KB
/
TranspositionTable.java
File metadata and controls
69 lines (58 loc) · 1.76 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.Arrays;
public class TranspositionTable {
private final int size;
private final int[] keys;
private final byte[] values;
private final byte[] depths;
private final byte[] boundTypes;
public static final byte BOUND_EXACT = 0;
public static final byte BOUND_LOWER = 1;
public static final byte BOUND_UPPER = 2;
public TranspositionTable(int size) {
this.size = size;
keys = new int[size];
values = new byte[size];
depths = new byte[size];
boundTypes = new byte[size];
}
public void reset() {
Arrays.fill(keys, 0);
Arrays.fill(values, (byte) 0);
Arrays.fill(depths, (byte) 0);
Arrays.fill(boundTypes, (byte) 0);
}
public void put(long key, byte val) {
put(key, val, (byte) 0, BOUND_EXACT);
}
public void put(long key, byte val, byte depth, byte type) {
int pos = index(key);
keys[pos] = (int) key;
values[pos] = val;
depths[pos] = depth;
boundTypes[pos] = type;
}
public byte get(long key) {
TTEntry e = getEntry(key);
return (e != null ? e.value : 0);
}
public TTEntry getEntry(long key) {
int pos = index(key);
if (keys[pos] == (int) key) {
return new TTEntry(values[pos], depths[pos], boundTypes[pos]);
}
return null;
}
public static class TTEntry {
public final byte value;
public final byte depth;
public final byte boundType;
public TTEntry(byte value, byte depth, byte boundType) {
this.value = value;
this.depth = depth;
this.boundType = boundType;
}
}
private int index(long key) {
return (int) (key % size);
}
}