pub struct SumTree { /* private fields */ }Expand description
A binary sum tree over capacity leaves. The capacity is rounded up to a
power of two so the tree stays complete.
Implementations§
Source§impl SumTree
impl SumTree
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a tree whose capacity is capacity rounded up to a power of two
(at least one).
pub fn is_empty(&self) -> bool
pub fn is_full(&self) -> bool
Sourcepub fn update(&mut self, index: usize, priority: f32)
pub fn update(&mut self, index: usize, priority: f32)
Set the priority at index and repair the sums up to the root.
Ancestors are adjusted by the delta rather than recomputed from both
children, halving the memory traffic per level. Over very many updates
this can accumulate floating-point drift; call SumTree::rebuild to
reset it.
Sourcepub fn rebuild(&mut self)
pub fn rebuild(&mut self)
Recompute every internal sum from the leaves, clearing any drift left by
repeated SumTree::update calls.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SumTree
impl RefUnwindSafe for SumTree
impl Send for SumTree
impl Sync for SumTree
impl Unpin for SumTree
impl UnsafeUnpin for SumTree
impl UnwindSafe for SumTree
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