Skip to main content

ChampMap

Struct ChampMap 

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

Persistent hash map based on a CHAMP trie, single-threaded.

Same set of key-value pairs always produces the same trie structure (canonical form), enabling O(1) structural equality via adhash.

Implementations§

Source§

impl<K, V> ChampMap<K, V>

Source

pub const fn new() -> Self

Creates an empty map.

Source

pub const fn len(&self) -> usize

Returns the number of key-value pairs.

Source

pub const fn is_empty(&self) -> bool

Returns true if the map contains no entries.

Source

pub const fn adhash(&self) -> u64

Returns the current AdHash value.

Two maps with the same AdHash and the same length contain the same entries with overwhelming probability (2⁻⁶⁴ collision chance).

Source

pub fn checkpoint(&self) -> ChampCheckpoint<K, V>

Saves the current map state for later rollback.

Source

pub fn arena_len(&self) -> (usize, usize, usize)

Returns the total number of allocated items in each arena: (nodes, entries, children).

Includes dead COW copies — reflects true memory footprint.

Source

pub fn rollback(&mut self, cp: ChampCheckpoint<K, V>)

Restores the map to a previously saved checkpoint.

All changes made after the checkpoint are discarded.

Source§

impl<K: Hash + Eq, V> ChampMap<K, V>

Source

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

Returns a reference to the value associated with key.

Source

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

Returns true if the map contains the given key.

Source§

impl<K: Hash + Eq + Clone, V: Hash + Clone> ChampMap<K, V>

Source

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

Inserts a key-value pair into the map.

Returns None if the key was new, or Some(old_value) if an existing value was replaced.

§Panics

Panics if internal arena allocation returns an unexpected None.

Source

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

Removes a key from the map. Returns the removed value, or None if the key was not present.

Source§

impl<K, V> ChampMap<K, V>

Source

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

Returns an iterator over (&K, &V) pairs.

Trait Implementations§

Source§

impl<K, V> Debug for ChampMap<K, V>

Source§

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

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

impl<K, V> Default for ChampMap<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K: Hash + Eq + Clone, V: Hash + Clone> Extend<(K, V)> for ChampMap<K, V>

Source§

fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K: Hash + Eq + Clone, V: Hash + Clone> FromIterator<(K, V)> for ChampMap<K, V>

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<K: Hash + Eq, V> Index<&K> for ChampMap<K, V>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, key: &K) -> &V

Performs the indexing (container[index]) operation. Read more
Source§

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

Source§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
Source§

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

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

fn into_iter(self) -> Iter<'a, K, V>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<K, V> UnsafeUnpin for ChampMap<K, V>

§

impl<K, V> UnwindSafe for ChampMap<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<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 = 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.