pub struct ElemPool<T> { /* private fields */ }Expand description
A pool of ListElem<T> nodes that provides memory for multiple data structures.
§Rationale
The ElemPool is the cornerstone of this library’s design. It acts as a
specialized memory allocator. By pre-allocating memory in a Vec and managing
its own free list, it avoids the performance cost of frequent calls to the
global allocator. This makes creating and destroying elements extremely fast.
All list elements, regardless of which PieList or FibHeap they belong to,
are stored contiguously within this single structure, leading to better cache
locality during traversals compared to traditional node-based linked lists.
Its public API is minimal, as most interactions are performed through PieList,
CursorMut, or FibHeap methods, which take the pool as an argument.
Implementations§
Source§impl<T> ElemPool<T>
impl<T> ElemPool<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty element pool.
The pool is initialized with a capacity for zero elements but contains one internal node to act as the sentinel for the free list.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements holding user data in the pool.
This is a semantic count that excludes sentinel nodes for active lists and any elements on the free list. It provides a clear measure of how many items are actually being stored across all lists.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total number of elements (used, sentinels, or free) that the pool can hold without reallocating its internal vector. This count excludes the pool’s own free-list sentinel.
Sourcepub fn list_count(&self) -> usize
pub fn list_count(&self) -> usize
Returns the number of active lists associated with this pool.
This is calculated by subtracting the number of data-holding elements and free elements from the total capacity, with the remainder being the sentinel nodes for active lists.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be
allocated in the pool.
The pool’s underlying storage may reallocate if its capacity is
less than the current length plus additional. If the capacity is
already sufficient, this does nothing.
This is useful to avoid multiple reallocations when a large number of elements are expected to be added.
§Panics
Panics if the new capacity overflows isize::MAX.
Sourcepub fn contains(&self, index: Index<T>) -> bool
pub fn contains(&self, index: Index<T>) -> bool
Checks if a given index points to an element that contains user data.
Returns false if the index is NONE, out of bounds, or points to a
free/sentinel element.
Sourcepub fn validate_index(&self, index: Index<T>) -> Result<(), IndexError>
pub fn validate_index(&self, index: Index<T>) -> Result<(), IndexError>
Performs a detailed validation of an index and its surrounding links.
This is a powerful debugging tool to verify the structural integrity of a list. It checks that:
- The index is valid and in bounds.
- The element at the index contains data.
- The
prevelement’snextlink points back to this index. - The
nextelement’sprevlink points back to this index.
§Errors
Returns Ok(()) on success, or an IndexError variant describing the
first validation failure encountered.