Skip to main content

NodeStore

Struct NodeStore 

Source
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>

Source

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.

Source

pub fn capacity(&self) -> u32

Per-arena slot capacity.

Source

pub fn live_count(&self) -> usize

Number of live nodes (internals + leaves).

Source

pub fn live_internal_count(&self) -> usize

Number of live internal nodes.

Source

pub fn live_leaf_count(&self) -> usize

Number of live leaf nodes.

Source

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).

Source

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).

Source

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().

Source

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().

Source

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().

Source

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
Source

pub fn internal_mut(&mut self, n: NodeRef) -> RcfResult<&mut InternalData<D>>

Typed mutable accessor for an internal node — see Self::internal.

§Errors

Same as Self::internal.

Source

pub fn leaf(&self, n: NodeRef) -> RcfResult<&LeafData>

Typed immutable accessor for a leaf node.

§Errors
Source

pub fn leaf_mut(&mut self, n: NodeRef) -> RcfResult<&mut LeafData>

Typed mutable accessor for a leaf node — see Self::leaf.

§Errors

Same as Self::leaf.

Source

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.

Source

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::OutOfBounds when n does not exist.
  • RcfError::InvalidConfig when the parent is a leaf (impossible state — internal data structure invariant violated) or when n is not registered as a child of its parent (orphan).
Source

pub fn internal_bbox(&self, n: NodeRef) -> RcfResult<&BoundingBox<D>>

Cached bounding box of an internal node.

§Errors
  • RcfError::OutOfBounds when the node does not exist.
  • RcfError::InvalidConfig when called on a leaf — leaf bounding boxes are degenerate single-point boxes; build them from the underlying point store entry on the consumer side.
Source

pub fn set_parent( &mut self, n: NodeRef, parent: Option<NodeRef>, ) -> RcfResult<()>

Set the parent of a node.

§Errors

Returns RcfError::OutOfBounds when the node does not exist.

Source

pub fn set_mass(&mut self, n: NodeRef, mass: u64) -> RcfResult<()>

Replace the mass of a node.

§Errors

Returns RcfError::OutOfBounds when the node does not exist.

Source

pub fn set_internal_bbox( &mut self, n: NodeRef, bbox: BoundingBox<D>, ) -> RcfResult<()>

Replace the cached bounding box of an internal node.

§Errors
Source

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
Source

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

Trait Implementations§

Source§

impl<const D: usize> Debug for NodeStore<D>

Source§

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

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

impl<'de, const D: usize> Deserialize<'de> for NodeStore<D>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const D: usize> Serialize for NodeStore<D>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,