- // Implement replace strategy
- if ( (( tte->genBound8 & 0xFC) == generation || tte->bound() == BOUND_EXACT)
- - ((replace->genBound8 & 0xFC) == generation)
- - (tte->depth8 < replace->depth8) < 0)
- replace = tte;
- }
+ // Find an entry to be replaced according to the replacement strategy
+ TTEntry* replace = tte;
+ for (int i = 1; i < ClusterSize; ++i)
+ // Due to our packed storage format for generation and its cyclic
+ // nature we add 263 (256 is the modulus plus 7 to keep the unrelated
+ // lowest three bits from affecting the result) to calculate the entry
+ // age correctly even after generation8 overflows into the next cycle.
+ if ( replace->depth8 - ((263 + generation8 - replace->genBound8) & 0xF8)
+ > tte[i].depth8 - ((263 + generation8 - tte[i].genBound8) & 0xF8))
+ replace = &tte[i];
+
+ return found = false, replace;
+}
+
+
+/// TranspositionTable::hashfull() returns an approximation of the hashtable
+/// occupation during a search. The hash is x permill full, as per UCI protocol.
+
+int TranspositionTable::hashfull() const {
+
+ int cnt = 0;
+ for (int i = 0; i < 1000; ++i)
+ for (int j = 0; j < ClusterSize; ++j)
+ cnt += (table[i].entry[j].genBound8 & 0xF8) == generation8;