Struct confertus::dynamic_vector::DynamicBitVector
source · [−]Expand description
Implementation of Dynamic Bit Vector using self-balancing AVL tree.
Instance bit size: 56 bytes = 448 (not included: bit sizes of instances in Vector structures)
Fields
root: usizeindex to root Node, 8 bytes
nodes: Vec<Node>Vector containing Node, 24 bytes
leafs: Vec<Leaf>Vector containing Leaf, 24 bytes
Implementations
sourceimpl DynamicBitVector
impl DynamicBitVector
sourcepub fn apply<T>(
&mut self,
f: impl FnMut(&mut DynamicBitVector, isize, usize) -> T,
index: usize
) -> T
pub fn apply<T>(
&mut self,
f: impl FnMut(&mut DynamicBitVector, isize, usize) -> T,
index: usize
) -> T
Descend tree to position index and apply function f with f(self, leaf, index) -> T.
Used to implement traversal for DynamicBitVector::access, DynamicBitVector::flip,
DynamicBitVector::delete, DynamicBitVector::insert
Panics
If tree invariances are violated
sourcepub fn apply_bitop<T>(
&self,
f: impl FnMut(&DynamicBitVector, isize, usize, bool) -> T,
g: impl Fn(&DynamicBitVector, usize, bool) -> T,
index: usize,
bit: bool
) -> T where
T: Add<Output = T>,
pub fn apply_bitop<T>(
&self,
f: impl FnMut(&DynamicBitVector, isize, usize, bool) -> T,
g: impl Fn(&DynamicBitVector, usize, bool) -> T,
index: usize,
bit: bool
) -> T where
T: Add<Output = T>,
Descend tree to position index and apply function f with f(self, leaf, index, bit) -> T. Function g with g(self, node, left_descent) -> T is used to modify the return value of f
dependent on node. Its value is added to the result of recursion.
Used to implement traversal for DynamicBitVector::rank
Panics
If tree invariances are violated
sourcepub fn retrace(&mut self, node: usize, depth_change: i8)
pub fn retrace(&mut self, node: usize, depth_change: i8)
Retrace and update rank of parent until root (or until they cancel out, or until
a rebalancing happens). node self is expected to be updated already.
Arguments
node: usize- begin retracing here, first to get updated is parent ofnodedepth_change: i8- if depth change was positive or negative. Addition/Subtraction to rank depends on which child side it came from.
sourcepub fn rotate_left(&mut self, z: usize, x: usize)
pub fn rotate_left(&mut self, z: usize, x: usize)
Left rotation of Nodes x and z.
Assumes that z is right child of x, x.rank == 2 and z.rank == 1|0
(0 can only happens after deletion, and correct ranks might not be zero in all situations
after rotation).
│parent │parent
│ │
┌─▼─┐ ┌─▼─┐
left│ X │right left│ Z │right
┌───┤ ├───┐ ┌───┤ ├───┐
│ │r:2│ │ │ │r:0│ │
┌─▼─┐ └───┘ ┌─▼─┐ ┌─▼─┐ └───┘ ┌─▼─┐
│ │ left│ Z │right left rotation left│ X │right │ │
│T1 │ ┌───┤ ├───┐ ┌───┤ ├───┐ │T4 │
│ │ │ │r:1│ │ ────────────► │ │r:0│ │ │ │
└───┘ ┌─▼─┐ └───┘ ┌─▼─┐ ┌─▼─┐ └───┘ ┌─▼─┐ └───┘
│ │ │ │ │ │ │ │
│T23│ │T4 │ │T1 │ │T23│
│ │ │ │ │ │ │ │
└───┘ └───┘ └───┘ └───┘See also the wikipedia article on AVL-tree rebalancing.
sourcepub fn rotate_right(&mut self, z: usize, x: usize)
pub fn rotate_right(&mut self, z: usize, x: usize)
Right rotation of Nodes z and x to reestablish rank-difference invariant.
Assumes that z is left child of x, x.rank == 2 and z.rank == 1|0
(0 can only happens after deletion, and correct ranks might not be zero in all situations
after rotation). We won’t need to recursively update nums and ones, as they won't change from the perspective of parent`.
│parent │parent
│ │
┌─▼─┐ ┌─▼─┐
left│ X │right left│ Z │right
┌───┤ ├───┐ ┌───┤ ├───┐
│ │r:2│ │ │ │r:0│ │
┌─▼─┐ └───┘ ┌─▼─┐ right rotation ┌─▼─┐ └───┘ ┌─▼─┐
left│ Z │right │ │ │ │ left│ X │right
┌───┤ ├───┐ │T4 │ ───────────► │T1 │ ┌───┤ ├───┐
│ │r:1│ │ │ │ │ │ │ │r:0│ │
┌─▼─┐ └───┘ ┌─▼─┐ └───┘ └───┘ ┌─▼─┐ └───┘ ┌─▼─┐
│ │ │ │ │ │ │ │
│T1 │ │T23│ │T23│ │T4 │
│ │ │ │ │ │ │ │
└───┘ └───┘ └───┘ └───┘See also the wikipedia article on AVL-tree rebalancing.
sourcepub fn rebalance(&mut self, node: usize, parent: usize)
pub fn rebalance(&mut self, node: usize, parent: usize)
Rebalance tree to reestablish the rank difference invariance (valid values -1, 0, 1).
This is done via combinations of left and right rotations. For insertions, at most two
rotations are necessary, deletions might require up until log(depth) rotations to
reestablish balance. (rebalancing after deletion requires additional retracing which is not
yet implemented)
parentisNodewith temporary rank / balance factor violationnodeis higher child ofparent
sourcepub fn rebalance_no_child(&mut self, parent: usize)
pub fn rebalance_no_child(&mut self, parent: usize)
Rebalance tree on parent, where highest node might not be known. One child has to be of
|rank| == 1 while the other is rank == 0. Safe to assume, given that parent has |rank| == 2 (would be zero otherwise).
sourcepub fn create_right_leaf(&mut self, node: usize) -> isize
pub fn create_right_leaf(&mut self, node: usize) -> isize
Create Leaf as right child of node, returns id of newly created Leaf.
sourcepub fn closest_neighbor_leaf(&self, leaf: isize) -> Option<Either<isize, isize>>
pub fn closest_neighbor_leaf(&self, leaf: isize) -> Option<Either<isize, isize>>
Return closest immediately sequential neighbor to given Leaf leaf, should it exist.
Either additionally tells if it was a right or left child.
sourcepub fn closest_neighbor_child(
&self,
child: usize
) -> Option<Either<isize, isize>>
pub fn closest_neighbor_child(
&self,
child: usize
) -> Option<Either<isize, isize>>
Try to return a Leaf that is the closest neighbor (left or right) to the given Node
child by ascending, and descending the respectively ‘other’ side of child. Fails if no
such neighbor exists.
sourcepub fn merge_away(&mut self, leaf: isize)
pub fn merge_away(&mut self, leaf: isize)
Try to find neighboring Leaf and merge into, or steal values if neighbor is too full.
Assumption: leaf has a used size of <= 3/4 LeafValue::BITS.
Merge, when found neighbor has at least 1/4 LeafValue::BITS to spare. Otherwise, steal.
sourcepub fn swap_remove_leaf(&mut self, leaf: isize)
pub fn swap_remove_leaf(&mut self, leaf: isize)
Remove Leaf with given index leaf. Swaps with currently last in self.leafs and updates
the child index of the parent of the swapped Leaf.
sourcepub fn swap_remove_node(&mut self, node: usize)
pub fn swap_remove_node(&mut self, node: usize)
Remove Node with given index node. Swaps with currently last Node and updates its parent
index for the swapped child.
sourcepub fn get_side(&self, child: isize) -> Option<Either<usize, usize>>
pub fn get_side(&self, child: isize) -> Option<Either<usize, usize>>
Given some Child child, return side on parent and parent index
sourcepub fn get_leaf_side(&self, child: isize) -> Either<usize, usize>
pub fn get_leaf_side(&self, child: isize) -> Either<usize, usize>
Given Leaf child, return side on parent and parent index
sourcepub fn get_node_side(&self, child: usize) -> Option<Either<usize, usize>>
pub fn get_node_side(&self, child: usize) -> Option<Either<usize, usize>>
Given Node child, return side on parent and parent index
sourcepub fn update_left_values_only(&mut self, node: usize, child: isize) -> bool
pub fn update_left_values_only(&mut self, node: usize, child: isize) -> bool
Non-recursive updating of parent nums and ones values.
Returns if child is left side child of node or not.
sourcepub fn update_left_values(&mut self, node: usize, child: isize)
pub fn update_left_values(&mut self, node: usize, child: isize)
Recursively update parent values in case of left-child modification of nums or ones,
coming from child.
sourcepub fn split_leaf(&mut self, leaf: isize) -> usize
pub fn split_leaf(&mut self, leaf: isize) -> usize
Split content of leaf in two, and replace location with new Node. Afterward, apply
DynamicBitVector::retrace. Returns id of newly created Node. Potentially
rebalances when tracing ranks.
sourcepub fn full_nums_ones(&self, child: isize) -> (usize, usize)
pub fn full_nums_ones(&self, child: isize) -> (usize, usize)
Return nums and ones of child (N2) from both its left and right subtrees.
Graphically, return fully redundant indexing support values nums and ones for N1 by
adding left-values from N2 and N3, as well as right-values from N3 (recursively until
leaf).
┌───┐
│ │
┌──┤N1 │
│ │num│
┌─▼─┐└───┘
│ │
│N2 ├───┐
│num│ │
└───┘ ┌─▼─┐
│ │
│N3 │
│num│
└───┘Trait Implementations
sourceimpl BitSize for DynamicBitVector
impl BitSize for DynamicBitVector
sourcefn bitsize_full(&self) -> usize
fn bitsize_full(&self) -> usize
Return total number of bits allocated by objects managed by structures. Includes all elements on different areas of heap. Read more
sourcefn bitsize_used(&self) -> usize
fn bitsize_used(&self) -> usize
Return total number of used bits (fewer than allocated) by objects managed by structures. Includes all elements on different areas of heap. Read more
sourceimpl Clone for DynamicBitVector
impl Clone for DynamicBitVector
sourcefn clone(&self) -> DynamicBitVector
fn clone(&self) -> DynamicBitVector
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for DynamicBitVector
impl Debug for DynamicBitVector
sourceimpl Default for DynamicBitVector
impl Default for DynamicBitVector
sourcefn default() -> DynamicBitVector
fn default() -> DynamicBitVector
Returns the “default value” for a type. Read more
sourceimpl Display for DynamicBitVector
impl Display for DynamicBitVector
Really just the Debug output
sourceimpl Dot for DynamicBitVector
impl Dot for DynamicBitVector
sourceimpl DynBitVec for DynamicBitVector
impl DynBitVec for DynamicBitVector
sourcefn insert(&mut self, index: usize, bit: bool) -> Result<(), &'static str>
fn insert(&mut self, index: usize, bit: bool) -> Result<(), &'static str>
Insert bit at position index in underlying container Read more
sourcefn delete(&mut self, index: usize) -> Result<(), &'static str>
fn delete(&mut self, index: usize) -> Result<(), &'static str>
Remove bit value at position index Read more
sourceimpl Index<isize> for DynamicBitVector
impl Index<isize> for DynamicBitVector
Return Leaf for isize indexing
When creating a new container with DynamicBitVector::new, a Leaf on position 0 (which
cannot be accessed) is created, as all attempted (later) indexing to values >= 0 are
converted to usize first and return a Node instead.
sourceimpl Index<usize> for DynamicBitVector
impl Index<usize> for DynamicBitVector
Return Node for usize indexing
sourceimpl IndexMut<isize> for DynamicBitVector
impl IndexMut<isize> for DynamicBitVector
sourceimpl IndexMut<usize> for DynamicBitVector
impl IndexMut<usize> for DynamicBitVector
sourceimpl PartialEq<DynamicBitVector> for DynamicBitVector
impl PartialEq<DynamicBitVector> for DynamicBitVector
sourcefn eq(&self, other: &DynamicBitVector) -> bool
fn eq(&self, other: &DynamicBitVector) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &DynamicBitVector) -> bool
fn ne(&self, other: &DynamicBitVector) -> bool
This method tests for !=.
sourceimpl StaticBitVec for DynamicBitVector
impl StaticBitVec for DynamicBitVector
impl StructuralPartialEq for DynamicBitVector
Auto Trait Implementations
impl RefUnwindSafe for DynamicBitVector
impl Send for DynamicBitVector
impl Sync for DynamicBitVector
impl Unpin for DynamicBitVector
impl UnwindSafe for DynamicBitVector
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more