#[repr(transparent)]pub struct SegTreeNode(pub usize);Expand description
A node in a power-of-two layout segment tree.
This struct wraps a usize index representing a node’s position in the tree.
The tree uses 1-based indexing for efficient parent/child calculations.
§Examples
use array_range_query::SegTreeNode;
let root = SegTreeNode(1);
let left_child = root.left_child();
let right_child = root.right_child();
assert_eq!(left_child.0, 2);
assert_eq!(right_child.0, 3);Tuple Fields§
§0: usizeImplementations§
Source§impl SegTreeNode
impl SegTreeNode
Sourcepub fn left_child(&self) -> SegTreeNode
pub fn left_child(&self) -> SegTreeNode
Returns the left child of this node.
Sourcepub fn right_child(&self) -> SegTreeNode
pub fn right_child(&self) -> SegTreeNode
Returns the right child of this node.
Sourcepub fn parent(&self) -> SegTreeNode
pub fn parent(&self) -> SegTreeNode
Sourcepub fn sibling(&self) -> SegTreeNode
pub fn sibling(&self) -> SegTreeNode
Returns the sibling of this node (assumes node is not root).
Sourcepub fn sibling_safe(&self) -> SegTreeNode
pub fn sibling_safe(&self) -> SegTreeNode
Sourcepub fn is_left_child(&self) -> bool
pub fn is_left_child(&self) -> bool
Returns true if this node is a left child of its parent.
Sourcepub fn is_left_child_if_not_root(&self) -> bool
pub fn is_left_child_if_not_root(&self) -> bool
Returns true if this node is a left child (assumes node is not root).
Sourcepub fn is_right_child(&self) -> bool
pub fn is_right_child(&self) -> bool
Returns true if this node is a right child of its parent.
Sourcepub fn is_right_child_if_not_root(&self) -> bool
pub fn is_right_child_if_not_root(&self) -> bool
Returns true if this node is a right child (assumes node is not root).
Sourcepub fn size(&self, max_depth: u32) -> usize
pub fn size(&self, max_depth: u32) -> usize
Returns the size of the range this node represents.
§Parameters
max_depth: The maximum depth of the tree (depth of leaf nodes)
§Examples
use array_range_query::SegTreeNode;
let root = SegTreeNode(1);
let leaf = SegTreeNode(8);
assert_eq!(root.size(3), 8); // Root covers entire array of size 8
assert_eq!(leaf.size(3), 1); // Leaf covers single elementSourcepub fn left_bound(&self, max_depth: u32) -> usize
pub fn left_bound(&self, max_depth: u32) -> usize
Sourcepub fn right_bound(&self, max_depth: u32) -> usize
pub fn right_bound(&self, max_depth: u32) -> usize
Sourcepub fn mid(&self, max_depth: u32) -> usize
pub fn mid(&self, max_depth: u32) -> usize
Returns the midpoint of the range this node represents.
Sourcepub fn node_bounds(&self, max_depth: u32) -> (usize, usize)
pub fn node_bounds(&self, max_depth: u32) -> (usize, usize)
Sourcepub fn get_lca_from_same_depth(
left: SegTreeNode,
right: SegTreeNode,
) -> SegTreeNode
pub fn get_lca_from_same_depth( left: SegTreeNode, right: SegTreeNode, ) -> SegTreeNode
Finds the Lowest Common Ancestor (LCA) of two nodes at the same depth.
Sourcepub fn get_lca_from_different_depth(
left: SegTreeNode,
right: SegTreeNode,
) -> SegTreeNode
pub fn get_lca_from_different_depth( left: SegTreeNode, right: SegTreeNode, ) -> SegTreeNode
Finds the Lowest Common Ancestor (LCA) of two nodes at potentially different depths.
Sourcepub fn get_left_binding_node(&self) -> SegTreeNode
pub fn get_left_binding_node(&self) -> SegTreeNode
Returns the binding node by traversing up while this node is a right child. Used in segment tree range operations.
§Examples
use array_range_query::SegTreeNode;
let node = SegTreeNode(4); // Left child
let binding = node.get_left_binding_node();
assert_eq!(binding, SegTreeNode(1));Sourcepub fn get_right_binding_node(&self) -> SegTreeNode
pub fn get_right_binding_node(&self) -> SegTreeNode
Returns the binding node by traversing up while this node is a right child. Used in segment tree range operations.
§Examples
use array_range_query::SegTreeNode;
let node = SegTreeNode(5); // Right child
let binding = node.get_right_binding_node();
assert_eq!(binding, SegTreeNode(2));Trait Implementations§
Source§impl Clone for SegTreeNode
impl Clone for SegTreeNode
Source§fn clone(&self) -> SegTreeNode
fn clone(&self) -> SegTreeNode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more