pub trait IterativeSizeBalancedTree<T: LinkType>: RecursiveSizeBalancedTree<T> {
// Provided methods
unsafe fn attach(&mut self, root: *mut T, node: T) { ... }
unsafe fn detach(&mut self, root: *mut T, node: T) { ... }
unsafe fn attach_core(&mut self, root: *mut T, node: T) { ... }
unsafe fn detach_core(&mut self, root: *mut T, node: T) { ... }
}Expand description
Extends RecursiveSizeBalancedTree with iterative attach and
detach operations.
The iterative approach avoids stack overflow on deep trees by using a loop with pointer-chasing instead of recursion.
§Usage
Implement RecursiveSizeBalancedTree for your storage type, then
add an empty impl IterativeSizeBalancedTree<T> for MyStorage {}.
§Safety
All methods are unsafe — the caller must ensure that root points
to a valid, writable location and that node indices are valid.
Provided Methods§
Sourceunsafe fn attach(&mut self, root: *mut T, node: T)
unsafe fn attach(&mut self, root: *mut T, node: T)
Inserts node into the tree rooted at *root.
If *root is zero (empty tree), node becomes the root with
size 1. Otherwise the tree is rebalanced after insertion.
Sourceunsafe fn detach(&mut self, root: *mut T, node: T)
unsafe fn detach(&mut self, root: *mut T, node: T)
Removes node from the tree rooted at *root.
The tree is rebalanced after removal. After detach, node’s
left, right, and size fields are cleared to zero.