pub struct U64RadixAddressableHeap<V> { /* private fields */ }Expand description
An addressable monotone radix heap for u64 keys.
Handles are checked for foreign and stale use. As with every radix heap in this module, fallible insertion and key-update methods enforce range and monotonicity restrictions.
§Examples
use rheaps::monotone::U64RadixAddressableHeap;
let mut heap = U64RadixAddressableHeap::new(0, 100).unwrap();
let task = heap.try_insert(30, "compile report").unwrap();
heap.try_insert(10, "answer mail").unwrap();
heap.decrease_key(task, 20).unwrap();
assert_eq!(heap.peek().map(|(_, key, _)| *key), Some(10));
assert_eq!(heap.delete(task), Ok((20, "compile report")));Implementations§
Source§impl<V> U64RadixAddressableHeap<V>
impl<V> U64RadixAddressableHeap<V>
Sourcepub fn new(minimum_key: u64, maximum_key: u64) -> Result<Self, RadixHeapError>
pub fn new(minimum_key: u64, maximum_key: u64) -> Result<Self, RadixHeapError>
Creates an empty addressable radix heap with inclusive bounds.
Sourcepub fn with_bounds(
minimum_key: u64,
maximum_key: u64,
) -> Result<Self, RadixHeapError>
pub fn with_bounds( minimum_key: u64, maximum_key: u64, ) -> Result<Self, RadixHeapError>
Alias for Self::new.
Sourcepub fn minimum_key(&self) -> &u64
pub fn minimum_key(&self) -> &u64
Returns the inclusive lower key bound.
Sourcepub fn maximum_key(&self) -> &u64
pub fn maximum_key(&self) -> &u64
Returns the inclusive upper key bound.
Sourcepub fn last_deleted_key(&self) -> &u64
pub fn last_deleted_key(&self) -> &u64
Returns the most recently removed key, or the lower bound if no key has yet been removed or the heap was cleared.
Sourcepub fn bucket_count(&self) -> usize
pub fn bucket_count(&self) -> usize
Returns the fixed number of radix buckets.
Sourcepub fn try_insert(
&mut self,
key: u64,
value: V,
) -> Result<RadixHandle, RadixHeapError>
pub fn try_insert( &mut self, key: u64, value: V, ) -> Result<RadixHandle, RadixHeapError>
Inserts a key-value entry and returns its handle.
Sourcepub fn peek(&self) -> Option<(RadixHandle, &u64, &V)>
pub fn peek(&self) -> Option<(RadixHandle, &u64, &V)>
Returns the handle, key, and value of the minimum entry.
Sourcepub fn key(&self, handle: RadixHandle) -> Result<&u64, InvalidHandle>
pub fn key(&self, handle: RadixHandle) -> Result<&u64, InvalidHandle>
Returns the key addressed by handle.
Sourcepub fn value(&self, handle: RadixHandle) -> Result<&V, InvalidHandle>
pub fn value(&self, handle: RadixHandle) -> Result<&V, InvalidHandle>
Returns the value addressed by handle.
Sourcepub fn value_mut(
&mut self,
handle: RadixHandle,
) -> Result<&mut V, InvalidHandle>
pub fn value_mut( &mut self, handle: RadixHandle, ) -> Result<&mut V, InvalidHandle>
Returns mutable access to the value addressed by handle.
Sourcepub fn decrease_key(
&mut self,
handle: RadixHandle,
key: u64,
) -> Result<(), RadixDecreaseKeyError>
pub fn decrease_key( &mut self, handle: RadixHandle, key: u64, ) -> Result<(), RadixDecreaseKeyError>
Decreases an entry’s key while preserving the monotonicity restriction.
Sourcepub fn delete(&mut self, handle: RadixHandle) -> Result<(u64, V), InvalidHandle>
pub fn delete(&mut self, handle: RadixHandle) -> Result<(u64, V), InvalidHandle>
Removes and returns the entry addressed by handle.
Trait Implementations§
Source§impl<V> TryAddressableHeap<u64, V> for U64RadixAddressableHeap<V>
impl<V> TryAddressableHeap<u64, V> for U64RadixAddressableHeap<V>
Source§type Handle = RadixHandle
type Handle = RadixHandle
Source§type InsertError = RadixHeapError
type InsertError = RadixHeapError
Source§fn try_insert(
&mut self,
key: u64,
value: V,
) -> Result<Self::Handle, Self::InsertError>
fn try_insert( &mut self, key: u64, value: V, ) -> Result<Self::Handle, Self::InsertError>
Source§fn peek(&self) -> Option<(Self::Handle, &u64, &V)>
fn peek(&self) -> Option<(Self::Handle, &u64, &V)>
Source§fn key(&self, handle: Self::Handle) -> Result<&u64, InvalidHandle>
fn key(&self, handle: Self::Handle) -> Result<&u64, InvalidHandle>
handle. Read moreSource§fn value(&self, handle: Self::Handle) -> Result<&V, InvalidHandle>
fn value(&self, handle: Self::Handle) -> Result<&V, InvalidHandle>
handle. Read moreSource§fn value_mut(&mut self, handle: Self::Handle) -> Result<&mut V, InvalidHandle>
fn value_mut(&mut self, handle: Self::Handle) -> Result<&mut V, InvalidHandle>
handle. Read moreSource§impl<V> TryDecreaseKeyHeap<u64, V> for U64RadixAddressableHeap<V>
impl<V> TryDecreaseKeyHeap<u64, V> for U64RadixAddressableHeap<V>
Source§type DecreaseKeyError = RadixDecreaseKeyError
type DecreaseKeyError = RadixDecreaseKeyError
Source§fn decrease_key(
&mut self,
handle: Self::Handle,
key: u64,
) -> Result<(), Self::DecreaseKeyError>
fn decrease_key( &mut self, handle: Self::Handle, key: u64, ) -> Result<(), Self::DecreaseKeyError>
handle. Read more