pub struct SumTree { /* private fields */ }Expand description
Sum-tree over capacity leaves backed by a flat Vec<f32>.
Used by super::PrioritizedReplayBuffer to draw transitions with
probability proportional to their priority. The tree itself doesn’t
know about transitions — the buffer maintains the leaf-to-transition
mapping separately.
Implementations§
Source§impl SumTree
impl SumTree
Sourcepub fn max_leaf(&self) -> f32
pub fn max_leaf(&self) -> f32
Maximum priority across all leaves.
Used by super::PrioritizedReplayBuffer::push to assign a
freshly inserted transition a priority that guarantees it gets
sampled at least once.
Sourcepub fn leaf_priority(&self, leaf_idx: usize) -> f32
pub fn leaf_priority(&self, leaf_idx: usize) -> f32
Sourcepub fn update(&mut self, leaf_idx: usize, priority: f32)
pub fn update(&mut self, leaf_idx: usize, priority: f32)
Set the priority of leaf leaf_idx ∈ [0, capacity) to priority,
propagating the delta up to the root.
§Panics
Panics if leaf_idx >= capacity or priority is not finite or is
negative.
Sourcepub fn find(&self, p: f32) -> (usize, f32)
pub fn find(&self, p: f32) -> (usize, f32)
Find the leaf whose cumulative-priority interval contains p.
Returns (leaf_idx, priority). The walk is deterministic: at each
internal node we descend left if p ≤ left_child, else we subtract
the left child’s value from p and descend right.
The caller is responsible for ensuring p ∈ [0, total()]; values
slightly above total() are clamped by the walk so that the
rightmost non-zero leaf is returned.
§Panics
Panics if total() == 0 (cannot sample from a zero-priority tree).
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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