pub struct NodePool<S: GameState> { /* private fields */ }Expand description
Pool for efficient node allocation in MCTS
This implementation provides memory reuse by creating and recycling nodes instead of frequently allocating and deallocating them. This can significantly improve performance in large MCTS searches.
Implementations§
Source§impl<S: GameState> NodePool<S>
impl<S: GameState> NodePool<S>
Sourcepub fn new(template_state: S, initial_size: usize) -> Self
pub fn new(template_state: S, initial_size: usize) -> Self
Creates a new node pool with the given template state
§Arguments
template_state- A template state that can be cloned when creating new nodesinitial_size- Number of nodes to preallocate
Sourcepub fn create_node(
&mut self,
state: S,
action: Option<S::Action>,
parent_player: Option<S::Player>,
depth: usize,
) -> MCTSNode<S>
pub fn create_node( &mut self, state: S, action: Option<S::Action>, parent_player: Option<S::Player>, depth: usize, ) -> MCTSNode<S>
Creates a new node, either from the pool or by allocating a new one
Sourcepub fn recycle_node(&mut self, node: MCTSNode<S>)
pub fn recycle_node(&mut self, node: MCTSNode<S>)
Recycles a node back to the pool for future reuse
Sourcepub fn recycle_tree(&mut self, root: MCTSNode<S>)
pub fn recycle_tree(&mut self, root: MCTSNode<S>)
Recycles all nodes in a tree by recursively adding them to the pool
Sourcepub fn get_stats(&self) -> &NodePoolStats
pub fn get_stats(&self) -> &NodePoolStats
Get statistics about pool utilization
Sourcepub fn available_nodes(&self) -> usize
pub fn available_nodes(&self) -> usize
Get current pool size (available nodes)
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for NodePool<S>where
S: Freeze,
impl<S> RefUnwindSafe for NodePool<S>where
S: RefUnwindSafe,
<S as GameState>::Player: RefUnwindSafe,
<S as GameState>::Action: RefUnwindSafe,
impl<S> Send for NodePool<S>
impl<S> Sync for NodePool<S>
impl<S> Unpin for NodePool<S>
impl<S> UnwindSafe for NodePool<S>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)