12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- use game::Game;
- use evaluate::PosValue;
- use std::collections::{HashMap};
- use std::hash::{BuildHasher, Hasher, Hash};
- use log::info;
- #[derive(Clone)]
- pub enum EntryType {
- Value,
- LowerBound,
- UpperBound,
- }
- #[derive(Clone)]
- pub struct CacheEntry {
- entry_type: EntryType,
- depth: i32,
- value: PosValue
- }
- pub struct Cache {
- hashmap: HashMap<Game, CacheEntry>,
- }
- impl Cache {
- pub fn new() -> Self {
- Cache {
- hashmap: HashMap::new()
- }
- }
- pub fn lookup(&self, game_pos: &Game) -> Option<CacheEntry> {
- self.hashmap.get(game_pos).map(|x| x.clone())
- }
-
- pub fn cache(&mut self, game_pos: &Game, ce: CacheEntry) {
- if self.hashmap.len() > 1000000 {
- let first_key = self.hashmap.keys().next().unwrap().clone();
- self.hashmap.remove(&first_key);
- }
- self.hashmap.insert(game_pos.clone(), ce);
- }
- }
|