pub struct KeyValueHeap<Key, Value> { /* private fields */ }Expand description
A max-heap
which allows for generalised Keys (required to implement StorageKey) and Values (which are
required to be ordered, divisible and addable).
Implementations§
Source§impl<Key, Value> KeyValueHeap<Key, Value>where
Key: StorageKey + Copy,
Value: AddAssign<Value> + DivAssign<Value> + PartialOrd + Default + Copy,
impl<Key, Value> KeyValueHeap<Key, Value>where
Key: StorageKey + Copy,
Value: AddAssign<Value> + DivAssign<Value> + PartialOrd + Default + Copy,
pub fn get_value(&self, key: Key) -> &Value
Sourcepub fn pop_max(&mut self) -> Option<Key>
pub fn pop_max(&mut self) -> Option<Key>
Deletes the key with maximum value from the heap and returns it, or None if the heap is empty.
The time-complexity of this operation is O(logn).
Sourcepub fn increment(&mut self, key: Key, increment: Value)
pub fn increment(&mut self, key: Key, increment: Value)
Increments the value of the element of ‘key’ by ‘increment’
The worst-case time-complexity of this operation is O(logn); average case is likely to be better
Sourcepub fn restore_key(&mut self, key: Key)
pub fn restore_key(&mut self, key: Key)
Restores the entry with key ‘key’ to the heap if the key is not present, otherwise does nothing. Its value is the previous value used before ‘delete_key’ was called.
The run-time complexity of this operation is O(logn)
Sourcepub fn delete_key(&mut self, key: Key)
pub fn delete_key(&mut self, key: Key)
Removes the entry with key ‘key’ (temporarily) from the heap if the key is present,
otherwise does nothing. Its value remains recorded internally and is available upon
calling KeyValueHeap::restore_key. The value can still be subjected to
KeyValueHeap::divide_values.
The run-time complexity of this operation is O(logn)
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns how many elements are in the heap (including the (temporarily) “removed” values)
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether there are no elements in the heap (including the (temporarily) “removed” values)
pub fn num_nonremoved_elements(&self) -> usize
Sourcepub fn is_key_present(&self, key: Key) -> bool
pub fn is_key_present(&self, key: Key) -> bool
Returns whether the key is currently not (temporarily) remove
Sourcepub fn grow(&mut self, key: Key, value: Value)
pub fn grow(&mut self, key: Key, value: Value)
Increases the size of the heap by one and adjust the data structures appropriately by adding
Key and Value
pub fn clear(&mut self)
Sourcepub fn divide_values(&mut self, divisor: Value)
pub fn divide_values(&mut self, divisor: Value)
Divides all the values in the heap by ‘divisor’. This will also affect the values of keys
that have been KeyValueHeap::delete_key.
The run-time complexity of this operation is O(n)
Trait Implementations§
Source§impl<Key: Clone, Value: Clone> Clone for KeyValueHeap<Key, Value>
impl<Key: Clone, Value: Clone> Clone for KeyValueHeap<Key, Value>
Source§fn clone(&self) -> KeyValueHeap<Key, Value>
fn clone(&self) -> KeyValueHeap<Key, Value>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Key: StorageKey, Value> Default for KeyValueHeap<Key, Value>
impl<Key: StorageKey, Value> Default for KeyValueHeap<Key, Value>
Auto Trait Implementations§
impl<Key, Value> Freeze for KeyValueHeap<Key, Value>
impl<Key, Value> RefUnwindSafe for KeyValueHeap<Key, Value>where
Key: RefUnwindSafe,
Value: RefUnwindSafe,
impl<Key, Value> Send for KeyValueHeap<Key, Value>
impl<Key, Value> Sync for KeyValueHeap<Key, Value>
impl<Key, Value> Unpin for KeyValueHeap<Key, Value>
impl<Key, Value> UnwindSafe for KeyValueHeap<Key, Value>where
Key: UnwindSafe,
Value: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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