Skip to main content

SlotTable

Struct SlotTable 

Source
pub struct SlotTable<K, M, S> { /* private fields */ }
Expand description

A transposition table with a fixed number of slots, each holding at most one entry.

A key’s slot comes from the low bits of TableKey::slot. Storing always replaces what the slot held, so memory stays fixed and recent positions win; a probe whose key differs from the slot’s misses.

§Examples

use game_tree_search::{Hashed, Searcher, SlotTable, alpha_beta};

impl Hashed for Nim {
    type Key = u64;

    fn key(&self, &(stones, side): &Self::Position) -> u64 {
        u64::from(stones) * 2 + u64::from(side == Side::Max)
    }
}

// Many move orders lead to the same pile, so the table saves most of the work.
let mut searcher = Searcher::with_table(SlotTable::new(1024));
let remembered = searcher.search(&Nim, &(20, Side::Max), 20);
let plain = alpha_beta(&Nim, &(20, Side::Max), 20);
assert_eq!(remembered.score, plain.score);
assert!(remembered.stats.nodes < plain.stats.nodes / 10);

Implementations§

Source§

impl<K: TableKey, M: Clone, S: Clone> SlotTable<K, M, S>

Source

pub fn new(capacity: usize) -> Self

A table with capacity slots, rounded up to a power of two (at least one).

§Panics

Panics if the rounded capacity does not fit in usize.

Source

pub fn capacity(&self) -> usize

The number of slots.

Source

pub fn clear(&mut self)

Empties every slot, for example before searching a different game.

Trait Implementations§

Source§

impl<K: Clone, M: Clone, S: Clone> Clone for SlotTable<K, M, S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, M: Debug, S: Debug> Debug for SlotTable<K, M, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: TableKey, M: Clone, S: Clone> Table<K, M, S> for SlotTable<K, M, S>

Source§

fn probe(&mut self, key: &K) -> Option<Entry<M, S>>

The entry stored for key, if any.
Source§

fn store(&mut self, key: K, entry: Entry<M, S>)

Stores entry for key; the table may keep or drop it, or evict another entry.

Auto Trait Implementations§

§

impl<K, M, S> Forget for SlotTable<K, M, S>

§

impl<K, M, S> Freeze for SlotTable<K, M, S>
where Vec<Option<(K, Entry<M, S>)>>: Freeze,

§

impl<K, M, S> Move for SlotTable<K, M, S>

§

impl<K, M, S> RefUnwindSafe for SlotTable<K, M, S>
where Vec<Option<(K, Entry<M, S>)>>: RefUnwindSafe,

§

impl<K, M, S> Send for SlotTable<K, M, S>
where Vec<Option<(K, Entry<M, S>)>>: Send,

§

impl<K, M, S> Sync for SlotTable<K, M, S>
where Vec<Option<(K, Entry<M, S>)>>: Sync,

§

impl<K, M, S> Unpin for SlotTable<K, M, S>
where Vec<Option<(K, Entry<M, S>)>>: Unpin,

§

impl<K, M, S> UnsafeUnpin for SlotTable<K, M, S>
where Vec<Option<(K, Entry<M, S>)>>: UnsafeUnpin,

§

impl<K, M, S> UnwindSafe for SlotTable<K, M, S>
where Vec<Option<(K, Entry<M, S>)>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.