pub struct LinkCutTree { /* private fields */ }Expand description
Link-Cut Tree supporting dynamic tree operations
Implementations§
Source§impl LinkCutTree
impl LinkCutTree
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Create with capacity hint
§Performance
Pre-allocates memory to avoid reallocation during tree construction
Sourcepub fn link(&mut self, u: NodeId, v: NodeId) -> Result<()>
pub fn link(&mut self, u: NodeId, v: NodeId) -> Result<()>
Link node v as child of node u Returns error if v is not a root or u and v are in same tree After this operation, v will be the parent of u in the represented tree
Sourcepub fn cut(&mut self, v: NodeId) -> Result<()>
pub fn cut(&mut self, v: NodeId) -> Result<()>
Cut the edge from node v to its parent Returns error if v is already a root
Sourcepub fn find_root(&mut self, v: NodeId) -> Result<NodeId>
pub fn find_root(&mut self, v: NodeId) -> Result<NodeId>
Find the root of the tree containing node v
§Performance Optimizations
- Uses path compression: splays intermediate nodes to reduce future queries
- Caches root for O(1) lookups on subsequent queries
- Inline hint for hot path
Sourcepub fn connected(&mut self, u: NodeId, v: NodeId) -> bool
pub fn connected(&mut self, u: NodeId, v: NodeId) -> bool
Check if two nodes are in the same tree
Sourcepub fn path_aggregate(&mut self, v: NodeId) -> Result<f64>
pub fn path_aggregate(&mut self, v: NodeId) -> Result<f64>
Get the path aggregate (e.g., minimum) from root to v
§Performance
Uses lazy aggregation - aggregates are maintained incrementally
Sourcepub fn lca(&mut self, u: NodeId, v: NodeId) -> Result<NodeId>
pub fn lca(&mut self, u: NodeId, v: NodeId) -> Result<NodeId>
Get the Lowest Common Ancestor of u and v
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LinkCutTree
impl RefUnwindSafe for LinkCutTree
impl Send for LinkCutTree
impl Sync for LinkCutTree
impl Unpin for LinkCutTree
impl UnwindSafe for LinkCutTree
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
Mutably borrows from an owned value. Read more
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>
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 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>
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