pub struct Node {
pub type_name: String,
pub id: String,
pub fields: SmallVec<[Value; 4]>,
pub children: Option<Box<BTreeMap<String, Vec<Node>>>>,
pub child_count: u16,
}Expand description
A node in a matrix list.
§Memory Layout Optimizations
Size reduced from ~120 bytes to ~80 bytes per node:
fields: Uses SmallVec to inline up to 4 values (typical case)children: Lazy allocation - None until first child added (saves 24 bytes for leaf nodes)child_count: Uses u16 (2 bytes) with 0 = no hint (vs 16 bytes forOption<usize>)
For 10,000 nodes: ~400KB saved in struct overhead alone.
Fields§
§type_name: StringThe type name (from schema). During parsing, this can be interned to share memory across all nodes of same type.
id: StringThe node’s ID (first column value).
fields: SmallVec<[Value; 4]>Field values (aligned with schema columns). SmallVec avoids heap allocation for ≤4 fields (common case: 90%+ of nodes).
children: Option<Box<BTreeMap<String, Vec<Node>>>>Child nodes grouped by type (from NEST relationships). Lazy allocation - None until first child added. ~70% of nodes are leaves.
child_count: u16Count of direct children (for LLM comprehension hints). 0 = no hint provided. Max 65,535 children (sufficient for all practical cases).
Implementations§
Source§impl Node
impl Node
Sourcepub fn new(
type_name: impl Into<String>,
id: impl Into<String>,
fields: Vec<Value>,
) -> Self
pub fn new( type_name: impl Into<String>, id: impl Into<String>, fields: Vec<Value>, ) -> Self
Create a new node.
Sourcepub fn add_child(&mut self, child_type: impl Into<String>, child: Node)
pub fn add_child(&mut self, child_type: impl Into<String>, child: Node)
Add a child node. Uses lazy allocation - children BTreeMap is only created on first add.
Sourcepub fn set_child_count(&mut self, count: usize)
pub fn set_child_count(&mut self, count: usize)
Set the child count hint (for LLM comprehension). Saturates at u16::MAX (65,535) if count exceeds.
Sourcepub fn get_child_count(&self) -> Option<usize>
pub fn get_child_count(&self) -> Option<usize>
Get the child count hint, if provided.
Sourcepub fn with_child_count(
type_name: impl Into<String>,
id: impl Into<String>,
fields: Vec<Value>,
child_count: usize,
) -> Self
pub fn with_child_count( type_name: impl Into<String>, id: impl Into<String>, fields: Vec<Value>, child_count: usize, ) -> Self
Create a new node with a child count hint.
§Arguments
type_name: The type name from the schemafields: Field values wherefields[0]MUST be the node ID (a string)child_count: Expected number of children (for LLM hints)
Trait Implementations§
impl StructuralPartialEq for Node
Auto Trait Implementations§
impl Freeze for Node
impl RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl UnwindSafe for Node
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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