pub struct MoveArena<M> { /* private fields */ }Expand description
Arena allocator for moves with O(1) reset.
Instead of allocating a new Vecreset() simply
sets the length to 0 without running destructors (moves are Copy-like
in practice since they contain only primitives and small inline data).
§Performance
| Operation | Vec per step | MoveArena |
|---|---|---|
| Alloc | O(n) heap | O(1) bump |
| Cleanup | O(n) drop | O(1) reset |
| Memory | n * size_of | Reused |
§Example
use solverforge_solver::heuristic::r#move::MoveArena;
let mut arena: MoveArena<i32> = MoveArena::new();
// Step 1: generate and evaluate moves
arena.push(1);
arena.push(2);
arena.push(3);
assert_eq!(arena.len(), 3);
// Step 2: reset and reuse (O(1)!)
arena.reset();
assert!(arena.is_empty());
arena.push(10);
arena.push(20);
for mov in arena.iter() {
assert!(*mov >= 10);
}Implementations§
Source§impl<M> MoveArena<M>
impl<M> MoveArena<M>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new arena with pre-allocated capacity.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the arena, making it empty.
This is O(1) - it just sets len to 0. Existing data is left in place and will be overwritten.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut M>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut M>
Returns a mutable iterator over the moves.
Sourcepub fn extend<I: IntoIterator<Item = M>>(&mut self, iter: I)
pub fn extend<I: IntoIterator<Item = M>>(&mut self, iter: I)
Extends the arena from an iterator.
Trait Implementations§
Auto Trait Implementations§
impl<M> Freeze for MoveArena<M>
impl<M> RefUnwindSafe for MoveArena<M>where
M: RefUnwindSafe,
impl<M> Send for MoveArena<M>where
M: Send,
impl<M> Sync for MoveArena<M>where
M: Sync,
impl<M> Unpin for MoveArena<M>where
M: Unpin,
impl<M> UnwindSafe for MoveArena<M>where
M: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more