pub struct NodeStore<const D: usize> { /* private fields */ }Expand description
Flat-array storage for NodeRef-addressed nodes with O(1) allocation and
deallocation via per-arena free lists.
§Examples
use anomstream_core::NodeStore;
let mut store = NodeStore::<2>::new(4).unwrap();
let leaf = store.add_leaf(0, None, 1).unwrap();
assert!(leaf.is_leaf());
assert_eq!(store.live_count(), 1);Implementations§
Source§impl<const D: usize> NodeStore<D>
impl<const D: usize> NodeStore<D>
Sourcepub fn new(capacity: u32) -> RcfResult<Self>
pub fn new(capacity: u32) -> RcfResult<Self>
Build a store with capacity internal slots and capacity
leaf slots, all initially free.
§Errors
Returns RcfError::InvalidConfig when capacity == 0 or
capacity > NodeRef::MAX_INDEX + 1.
Sourcepub fn live_count(&self) -> usize
pub fn live_count(&self) -> usize
Number of live nodes (internals + leaves).
Sourcepub fn live_internal_count(&self) -> usize
pub fn live_internal_count(&self) -> usize
Number of live internal nodes.
Sourcepub fn live_leaf_count(&self) -> usize
pub fn live_leaf_count(&self) -> usize
Number of live leaf nodes.
Sourcepub fn add_internal(
&mut self,
cut: Cut,
bbox: BoundingBox<D>,
left: NodeRef,
right: NodeRef,
parent: Option<NodeRef>,
mass: u64,
) -> RcfResult<NodeRef>
pub fn add_internal( &mut self, cut: Cut, bbox: BoundingBox<D>, left: NodeRef, right: NodeRef, parent: Option<NodeRef>, mass: u64, ) -> RcfResult<NodeRef>
Allocate an internal node.
§Errors
Returns RcfError::InvalidConfig when the internal arena is
exhausted (every slot is live).
Sourcepub fn add_leaf(
&mut self,
point_idx: usize,
parent: Option<NodeRef>,
mass: u64,
) -> RcfResult<NodeRef>
pub fn add_leaf( &mut self, point_idx: usize, parent: Option<NodeRef>, mass: u64, ) -> RcfResult<NodeRef>
Allocate a leaf node.
§Errors
Returns RcfError::InvalidConfig when the leaf arena is
exhausted (every slot is live).
Sourcepub fn delete(&mut self, n: NodeRef) -> RcfResult<()>
pub fn delete(&mut self, n: NodeRef) -> RcfResult<()>
Free a node back to its arena. The slot becomes available for the next allocation.
§Errors
Returns RcfError::OutOfBounds when the slot is empty
(double-free) or n.index() >= capacity().
Sourcepub fn view(&self, n: NodeRef) -> RcfResult<NodeView<'_, D>>
pub fn view(&self, n: NodeRef) -> RcfResult<NodeView<'_, D>>
Zero-copy immutable view of a node. Pattern-match on the
returned NodeView to branch on internal-vs-leaf without
cloning the underlying record.
§Errors
Returns RcfError::OutOfBounds when the slot is empty or
n.index() >= capacity().
Sourcepub fn view_mut(&mut self, n: NodeRef) -> RcfResult<NodeViewMut<'_, D>>
pub fn view_mut(&mut self, n: NodeRef) -> RcfResult<NodeViewMut<'_, D>>
Zero-copy mutable view of a node — see Self::view.
§Errors
Returns RcfError::OutOfBounds when the slot is empty or
n.index() >= capacity().
Sourcepub fn internal(&self, n: NodeRef) -> RcfResult<&InternalData<D>>
pub fn internal(&self, n: NodeRef) -> RcfResult<&InternalData<D>>
Typed immutable accessor for an internal node. Prefer this
when the caller already knows the node is internal —
one-level shallower than going through Self::view + match.
§Errors
RcfError::OutOfBoundswhen the slot is empty or OOB.RcfError::InvalidConfigwhen called on a leaf reference.
Sourcepub fn internal_mut(&mut self, n: NodeRef) -> RcfResult<&mut InternalData<D>>
pub fn internal_mut(&mut self, n: NodeRef) -> RcfResult<&mut InternalData<D>>
Sourcepub fn leaf(&self, n: NodeRef) -> RcfResult<&LeafData>
pub fn leaf(&self, n: NodeRef) -> RcfResult<&LeafData>
Typed immutable accessor for a leaf node.
§Errors
RcfError::OutOfBoundswhen the slot is empty or OOB.RcfError::InvalidConfigwhen called on an internal reference.
Sourcepub fn parent(&self, n: NodeRef) -> RcfResult<Option<NodeRef>>
pub fn parent(&self, n: NodeRef) -> RcfResult<Option<NodeRef>>
Parent reference of a node (None for the root).
§Errors
Returns RcfError::OutOfBounds when the node does not exist.
Sourcepub fn sibling(&self, n: NodeRef) -> RcfResult<Option<NodeRef>>
pub fn sibling(&self, n: NodeRef) -> RcfResult<Option<NodeRef>>
Sibling of a node.
Returns None when n is the root (no parent → no sibling).
§Errors
RcfError::OutOfBoundswhenndoes not exist.RcfError::InvalidConfigwhen the parent is a leaf (impossible state — internal data structure invariant violated) or whennis not registered as a child of its parent (orphan).
Sourcepub fn internal_bbox(&self, n: NodeRef) -> RcfResult<&BoundingBox<D>>
pub fn internal_bbox(&self, n: NodeRef) -> RcfResult<&BoundingBox<D>>
Cached bounding box of an internal node.
§Errors
RcfError::OutOfBoundswhen the node does not exist.RcfError::InvalidConfigwhen called on a leaf — leaf bounding boxes are degenerate single-point boxes; build them from the underlying point store entry on the consumer side.
Sourcepub fn set_internal_bbox(
&mut self,
n: NodeRef,
bbox: BoundingBox<D>,
) -> RcfResult<()>
pub fn set_internal_bbox( &mut self, n: NodeRef, bbox: BoundingBox<D>, ) -> RcfResult<()>
Replace the cached bounding box of an internal node.
§Errors
RcfError::OutOfBoundswhen the node does not exist.RcfError::InvalidConfigwhen called on a leaf.
Sourcepub fn set_internal_children(
&mut self,
n: NodeRef,
new_left: NodeRef,
new_right: NodeRef,
) -> RcfResult<()>
pub fn set_internal_children( &mut self, n: NodeRef, new_left: NodeRef, new_right: NodeRef, ) -> RcfResult<()>
Replace the children of an internal node. Used by
crate::RandomCutTree delete when merging a sibling
into its grandparent’s slot.
§Errors
RcfError::OutOfBoundswhen the node does not exist.RcfError::InvalidConfigwhen called on a leaf.
Sourcepub fn set_internal_cut(&mut self, n: NodeRef, new_cut: Cut) -> RcfResult<()>
pub fn set_internal_cut(&mut self, n: NodeRef, new_cut: Cut) -> RcfResult<()>
Replace the cut of an internal node. Used when a tree rearrangement preserves the slot but swaps in a new cut.
§Errors
RcfError::OutOfBoundswhen the node does not exist.RcfError::InvalidConfigwhen called on a leaf.
Trait Implementations§
Source§impl<'de, const D: usize> Deserialize<'de> for NodeStore<D>
impl<'de, const D: usize> Deserialize<'de> for NodeStore<D>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl<const D: usize> Freeze for NodeStore<D>
impl<const D: usize> RefUnwindSafe for NodeStore<D>
impl<const D: usize> Send for NodeStore<D>
impl<const D: usize> Sync for NodeStore<D>
impl<const D: usize> Unpin for NodeStore<D>
impl<const D: usize> UnsafeUnpin for NodeStore<D>
impl<const D: usize> UnwindSafe for NodeStore<D>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more