Skip to main content

TryAddressableHeap

Trait TryAddressableHeap 

Source
pub trait TryAddressableHeap<K, V> {
    type Handle: Copy + Eq;
    type InsertError;

    // Required methods
    fn try_insert(
        &mut self,
        key: K,
        value: V,
    ) -> Result<Self::Handle, Self::InsertError>;
    fn peek(&self) -> Option<(Self::Handle, &K, &V)>;
    fn pop(&mut self) -> Option<(K, V)>;
    fn key(&self, handle: Self::Handle) -> Result<&K, InvalidHandle>;
    fn value(&self, handle: Self::Handle) -> Result<&V, InvalidHandle>;
    fn value_mut(
        &mut self,
        handle: Self::Handle,
    ) -> Result<&mut V, InvalidHandle>;
    fn delete(&mut self, handle: Self::Handle) -> Result<(K, V), InvalidHandle>;
    fn len(&self) -> usize;
    fn clear(&mut self);

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A min-oriented heap whose entries are addressed by stable handles and whose insertion can fail because of algorithm-specific key restrictions.

Complements AddressableHeap the same way TryHeap complements Heap.

Required Associated Types§

Source

type Handle: Copy + Eq

Opaque type that identifies a live entry in this heap.

Source

type InsertError

Error returned when an entry cannot be inserted.

Required Methods§

Source

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

Attempts to insert an entry and returns its handle.

§Errors

Returns an error if key violates this heap’s key restrictions.

Source

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

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

Source

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

Removes and returns a minimum entry, if present.

Source

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

Returns the key identified by handle.

§Errors

Returns an error if handle is stale or belongs to another heap.

Source

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

Returns the value identified by handle.

§Errors

Returns an error if handle is stale or belongs to another heap.

Source

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

Returns mutable access to the value identified by handle.

§Errors

Returns an error if handle is stale or belongs to another heap.

Source

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

Removes and returns the entry identified by handle.

§Errors

Returns an error if handle is stale or belongs to another heap.

Source

fn len(&self) -> usize

Returns the number of live entries.

Source

fn clear(&mut self)

Removes all entries and invalidates every outstanding handle.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns whether the heap contains no entries.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§