pub struct LoudsTree { /* private fields */ }Expand description
LOUDS-encoded tree with O(1) navigation.
Stores the tree structure in 2n+1 bits plus rank superblocks for fast rank/select queries.
Implementations§
Source§impl LoudsTree
impl LoudsTree
Sourcepub fn from_degrees(degrees: &[usize]) -> Self
pub fn from_degrees(degrees: &[usize]) -> Self
Build a LOUDS tree from BFS-order degree sequence.
degrees[i] is the number of children of the i-th node in
level-order. The root is degrees[0].
§Panics
Panics if the degree sequence is empty or inconsistent (doesn’t describe a valid tree).
Sourcepub fn from_children(children: &[&[usize]]) -> Self
pub fn from_children(children: &[&[usize]]) -> Self
Build a LOUDS tree from a pointer-based tree (children list per node).
children[i] is a slice of child node indices for node i. Nodes
must be numbered 0..n in BFS order.
§Panics
Panics if the tree structure is inconsistent.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the tree.
Sourcepub fn size_in_bytes(&self) -> usize
pub fn size_in_bytes(&self) -> usize
Total memory usage in bytes (excluding struct overhead).
Sourcepub fn first_child(&self, v: usize) -> Option<usize>
pub fn first_child(&self, v: usize) -> Option<usize>
Sourcepub fn next_sibling(&self, v: usize) -> Option<usize>
pub fn next_sibling(&self, v: usize) -> Option<usize>
Sourcepub fn depth(&self, v: usize) -> usize
pub fn depth(&self, v: usize) -> usize
Depth of node v (root has depth 0).
This is O(depth) — it walks to the root via parent().
§Panics
Panics if v >= node_count().
Sourcepub fn subtree_size(&self, v: usize) -> usize
pub fn subtree_size(&self, v: usize) -> usize
Subtree size rooted at node v (including v itself).
This is O(subtree_size) — it performs a BFS within the subtree.
§Panics
Panics if v >= node_count().