struct TopKHeap<VAL: ValueType> {
desc: bool,
len: usize,
capacity: usize,
heap: Vec<Option<HeapItem<VAL>>>,
}Expand description
A custom heap implementation that allows several things that couldn’t be achieved with
collections::BinaryHeap:
- It allows values to be updated at arbitrary positions (when group values change)
- It can be either a min or max heap
- It can use our
HeapItemtype &Comparabletrait - It is specialized to grow to a certain limit, then always replace without grow & shrink
Fields§
§desc: bool§len: usize§capacity: usize§heap: Vec<Option<HeapItem<VAL>>>Implementations§
Source§impl<VAL: ValueType> TopKHeap<VAL>
impl<VAL: ValueType> TopKHeap<VAL>
pub fn new(limit: usize, desc: bool) -> Self
pub fn worst_val(&self) -> Option<&VAL>
pub fn worst_map_idx(&self) -> usize
pub fn is_full(&self) -> bool
pub fn len(&self) -> usize
pub fn append_or_replace( &mut self, new_val: VAL, map_idx: usize, map: &mut Vec<(usize, usize)>, )
fn append( &mut self, new_val: VAL, map_idx: usize, mapper: &mut Vec<(usize, usize)>, )
fn pop(&mut self, map: &mut Vec<(usize, usize)>) -> Option<HeapItem<VAL>>
pub fn drain(&mut self) -> (Vec<VAL>, Vec<usize>)
fn replace_root( &mut self, new_val: VAL, map_idx: usize, mapper: &mut Vec<(usize, usize)>, )
pub fn replace_if_better( &mut self, heap_idx: usize, new_val: VAL, mapper: &mut Vec<(usize, usize)>, )
pub fn renumber(&mut self, heap_to_map: &[(usize, usize)])
fn heapify_up(&mut self, idx: usize, mapper: &mut Vec<(usize, usize)>)
fn swap(&mut self, a_idx: usize, b_idx: usize, mapper: &mut Vec<(usize, usize)>)
fn heapify_down(&mut self, node_idx: usize, mapper: &mut Vec<(usize, usize)>)
fn _tree_print( &self, idx: usize, prefix: String, is_tail: bool, output: &mut String, )
Trait Implementations§
Auto Trait Implementations§
impl<VAL> Freeze for TopKHeap<VAL>
impl<VAL> RefUnwindSafe for TopKHeap<VAL>where
VAL: RefUnwindSafe,
impl<VAL> Send for TopKHeap<VAL>where
VAL: Send,
impl<VAL> Sync for TopKHeap<VAL>where
VAL: Sync,
impl<VAL> Unpin for TopKHeap<VAL>where
VAL: Unpin,
impl<VAL> UnwindSafe for TopKHeap<VAL>where
VAL: UnwindSafe,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.