Skip to main content

U64RadixAddressableHeap

Struct U64RadixAddressableHeap 

Source
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>

Source

pub fn new(minimum_key: u64, maximum_key: u64) -> Result<Self, RadixHeapError>

Creates an empty addressable radix heap with inclusive bounds.

Source

pub fn with_bounds( minimum_key: u64, maximum_key: u64, ) -> Result<Self, RadixHeapError>

Alias for Self::new.

Source

pub fn minimum_key(&self) -> &u64

Returns the inclusive lower key bound.

Source

pub fn maximum_key(&self) -> &u64

Returns the inclusive upper key bound.

Source

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.

Source

pub fn bucket_count(&self) -> usize

Returns the fixed number of radix buckets.

Source

pub fn try_insert( &mut self, key: u64, value: V, ) -> Result<RadixHandle, RadixHeapError>

Inserts a key-value entry and returns its handle.

Source

pub fn peek(&self) -> Option<(RadixHandle, &u64, &V)>

Returns the handle, key, and value of the minimum entry.

Source

pub fn pop(&mut self) -> Option<(u64, V)>

Removes and returns the minimum entry.

Source

pub fn key(&self, handle: RadixHandle) -> Result<&u64, InvalidHandle>

Returns the key addressed by handle.

Source

pub fn value(&self, handle: RadixHandle) -> Result<&V, InvalidHandle>

Returns the value addressed by handle.

Source

pub fn value_mut( &mut self, handle: RadixHandle, ) -> Result<&mut V, InvalidHandle>

Returns mutable access to the value addressed by handle.

Source

pub fn decrease_key( &mut self, handle: RadixHandle, key: u64, ) -> Result<(), RadixDecreaseKeyError>

Decreases an entry’s key while preserving the monotonicity restriction.

Source

pub fn delete(&mut self, handle: RadixHandle) -> Result<(u64, V), InvalidHandle>

Removes and returns the entry addressed by handle.

Source

pub fn len(&self) -> usize

Returns the number of live entries.

Source

pub fn is_empty(&self) -> bool

Returns whether the heap contains no entries.

Source

pub fn clear(&mut self)

Removes all entries, invalidates their handles, and resets the monotonicity constraint.

Trait Implementations§

Source§

impl<V> TryAddressableHeap<u64, V> for U64RadixAddressableHeap<V>

Source§

type Handle = RadixHandle

Opaque type that identifies a live entry in this heap.
Source§

type InsertError = RadixHeapError

Error returned when an entry cannot be inserted.
Source§

fn try_insert( &mut self, key: u64, value: V, ) -> Result<Self::Handle, Self::InsertError>

Attempts to insert an entry and returns its handle. Read more
Source§

fn peek(&self) -> Option<(Self::Handle, &u64, &V)>

Returns the handle, key, and value of a minimum entry, if present.
Source§

fn pop(&mut self) -> Option<(u64, V)>

Removes and returns a minimum entry, if present.
Source§

fn key(&self, handle: Self::Handle) -> Result<&u64, InvalidHandle>

Returns the key identified by handle. Read more
Source§

fn value(&self, handle: Self::Handle) -> Result<&V, InvalidHandle>

Returns the value identified by handle. Read more
Source§

fn value_mut(&mut self, handle: Self::Handle) -> Result<&mut V, InvalidHandle>

Returns mutable access to the value identified by handle. Read more
Source§

fn delete(&mut self, handle: Self::Handle) -> Result<(u64, V), InvalidHandle>

Removes and returns the entry identified by handle. Read more
Source§

fn len(&self) -> usize

Returns the number of live entries.
Source§

fn clear(&mut self)

Removes all entries and invalidates every outstanding handle.
Source§

fn is_empty(&self) -> bool

Returns whether the heap contains no entries.
Source§

impl<V> TryDecreaseKeyHeap<u64, V> for U64RadixAddressableHeap<V>

Source§

type DecreaseKeyError = RadixDecreaseKeyError

Error returned when a key decrease cannot be performed.
Source§

fn decrease_key( &mut self, handle: Self::Handle, key: u64, ) -> Result<(), Self::DecreaseKeyError>

Decreases the key identified by handle. Read more

Auto Trait Implementations§

§

impl<V> Freeze for U64RadixAddressableHeap<V>
where AddressableRadixHeapCore<u64, V>: Freeze,

§

impl<V> RefUnwindSafe for U64RadixAddressableHeap<V>
where AddressableRadixHeapCore<u64, V>: RefUnwindSafe,

§

impl<V> Send for U64RadixAddressableHeap<V>
where AddressableRadixHeapCore<u64, V>: Send,

§

impl<V> Sync for U64RadixAddressableHeap<V>
where AddressableRadixHeapCore<u64, V>: Sync,

§

impl<V> Unpin for U64RadixAddressableHeap<V>
where AddressableRadixHeapCore<u64, V>: Unpin,

§

impl<V> UnsafeUnpin for U64RadixAddressableHeap<V>
where AddressableRadixHeapCore<u64, V>: UnsafeUnpin,

§

impl<V> UnwindSafe for U64RadixAddressableHeap<V>
where AddressableRadixHeapCore<u64, V>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.