Struct inanis::cache::search::TranspositionTable
source · pub struct TranspositionTable {
table: Vec<TranspositionTableBucket>,
}
Fields§
§table: Vec<TranspositionTableBucket>
Implementations§
source§impl TranspositionTable
impl TranspositionTable
sourcepub fn new(size: usize) -> Self
pub fn new(size: usize) -> Self
Constructs a new instance of TranspositionTable by allocating size
bytes of memory.
sourcepub fn add(
&self,
hash: u64,
score: i16,
best_move: Move,
depth: i8,
ply: u16,
score_type: u8,
age: u8
)
pub fn add( &self, hash: u64, score: i16, best_move: Move, depth: i8, ply: u16, score_type: u8, age: u8 )
Adds a new entry (storing the key, score
, best_move
, depth
, ply
, score_type
and age
) using hash & (self.table.len() - 1)
formula
to calculate an index of the bucket. Replacement strategy considers a few elements to optimize memory usage and prioritizes slots to replace as follows:
- empty slots or slots with the same key as the new entry
- slots with the smallest depth (if there are some old entries, prioritize them)
This function takes care of converting mate score
using passed ply
.
sourcepub fn get(&self, hash: u64, ply: u16) -> Option<TranspositionTableResult>
pub fn get(&self, hash: u64, ply: u16) -> Option<TranspositionTableResult>
Gets a wanted entry using hash & (self.table.len() - 1)
formula to calculate an index of the bucket. This function takes care of converting
mate score
using passed ply
. Returns None if hash
is incompatible with the stored key.
sourcepub fn get_best_move(&self, hash: u64) -> Option<Move>
pub fn get_best_move(&self, hash: u64) -> Option<Move>
Gets an entry’s best move using hash & (self.table.len() - 1)
formula to calculate an index of the bucket.
Returns None if hash
is incompatible with the stored key.
sourcepub fn get_pv_line(&self, board: &mut Board, ply: i8) -> Vec<Move>
pub fn get_pv_line(&self, board: &mut Board, ply: i8) -> Vec<Move>
Retrieves PV line from the transposition table, using board
position and the current ply
.
sourcepub fn get_usage(&self, resolution: usize) -> f32
pub fn get_usage(&self, resolution: usize) -> f32
Calculates an approximate percentage usage of the table, based on the first resolution
entries.