IterableMap

Struct IterableMap 

Source
pub struct IterableMap<K, V> { /* private fields */ }
Expand description

A map over global state that allows iteration. Each entry at key K_n stores (K_{n}, V, K_{n-1}), where V is the value and K_{n-1} is the key hash of the previous entry.

This creates a constant spatial overhead; every entry stores a pointer to the one inserted before it.

Enables iteration without a guaranteed ordering; updating an existing key does not affect position.

Under the hood, this is a singly-linked HashMap with linear probing for collision resolution. Supports full traversal, typically in reverse-insertion order.

Implementations§

Source§

impl<K, V> IterableMap<K, V>

Source

pub fn new<S: Into<String>>(prefix: S) -> Self

Creates an empty IterableMap with the given prefix.

Source

pub fn insert(&mut self, key: K, value: V) -> Option<V>

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned.

This has an amortized complexity of O(1), with a worst-case of O(n) when running into collisions.

Source

pub fn get(&self, key: &K) -> Option<V>

Returns a value corresponding to the key.

Source

pub fn remove(&mut self, key: &K) -> Option<V>

Removes a key from the map. Returns the associated value if the key exists.

Has a worst-case runtime of O(n).

Source

pub fn clear(&mut self)

Clears the map, removing all key-value pairs.

Source

pub fn contains_key(&self, key: &K) -> bool

Returns true if the map contains a value for the specified key.

Source

pub fn keys(&self) -> impl Iterator<Item = K> + '_

Creates an iterator visiting all the values in arbitrary order.

Source

pub fn values(&self) -> impl Iterator<Item = V> + '_

Creates an iterator visiting all the values in arbitrary order.

Source

pub fn is_empty(&self) -> bool

Source

pub fn iter(&self) -> IterableMapIter<'_, K, V>

Returns an iterator over the entries in the map.

Traverses entries in reverse-insertion order. Each item is a tuple of the hashed key and the value.

Source

pub fn len(&self) -> usize

Returns the number of entries in the map.

This is an O(n) operation.

Trait Implementations§

Source§

impl<K, V> BorshDeserialize for IterableMap<K, V>

Source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl<K, V> BorshSerialize for IterableMap<K, V>

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl<K: Clone, V: Clone> Clone for IterableMap<K, V>

Source§

fn clone(&self) -> IterableMap<K, V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, V: Debug> Debug for IterableMap<K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, K, V> IntoIterator for &'a IterableMap<K, V>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IterableMapIter<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for IterableMap<K, V>

§

impl<K, V> RefUnwindSafe for IterableMap<K, V>

§

impl<K, V> Send for IterableMap<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for IterableMap<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for IterableMap<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for IterableMap<K, V>
where K: UnwindSafe, 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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V