#[repr(C)]
pub struct PHashMap<K: Persistable, V: Persistable> { num_elements: usize, capacity: usize, num_buckets: usize, table: PhantomData<Bucket<K, V>>, table_offset: usize, /* private fields */ }
Expand description

A persistable hash map, which is safely movable between runtime instances.

This implementation leverages the PVec implementation to provide key/value pair backing storage for a collection of Buckets. Note that because of how resizing is currently performed, and the use of a stateless bump allocator to manage allocations, we end up leaking the space for all the Bucket tables we had allocated for all past capacities.

Fields§

§num_elements: usize§capacity: usize§num_buckets: usize§table: PhantomData<Bucket<K, V>>§table_offset: usize

Implementations§

source§

impl<K, V> PHashMap<K, V>where K: Eq + Default + Hash + Persistable + PersistentlyAllocatable, V: Persistable,

source

pub fn new() -> Self

Instantiates a new empty hashmap. No allocations are made as a result of this call.

source

pub fn len(&self) -> usize

Returns the number of elements in the map.

source

pub fn with_capacity(&mut self, capacity: usize)

Allocates space for the PHashMap to hold at least capacity elements before a reallocation is needed.

source

pub fn insert<T>(&mut self, k: T, v: V) -> Option<V>where T: Hash, K: CopyFrom<From = T> + PartialEq<T>,

Inserts a key-value pair into the PHashMap, resizing if necessary.

If the element was already in the PHashMap, the entry for the key is updated, and the old value is returned. Otherwise, None is returned.

source

pub fn clear(&mut self)

source

pub fn get<T>(&self, k: &T) -> Option<&V>where T: Hash, K: CopyFrom<From = T> + PartialEq<T>,

Returns a reference to the value corresponding to the key.

source

fn get_pkey(&self, k: &K) -> Option<&V>

source

pub fn get_mut(&self, k: &K) -> Option<&mut V>

Returns a mutable reference to the value corresponding to the (persistable) key.

source

pub fn get_mut_non_persistent_key<T>(&self, k: &T) -> Option<&mut V>where T: Hash, K: CopyFrom<From = T> + PartialEq<T>,

Returns a mutable reference to the value corresponding to the key.

source

pub fn contains(&self, k: &K) -> bool

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

source

pub fn contains_key<T>(&self, k: &T) -> boolwhere T: Hash, K: CopyFrom<From = T> + PartialEq<T>,

Returns true if the map contains a value for the specified key. Note that this supports keys that can be converted into the native key type (unlike [contains]).

source

fn get_hash_for_other_key<T>(&self, key: &T) -> usizewhere T: Hash, K: CopyFrom<From = T>,

source

unsafe fn get_bucket_at_index_ptr(&self, idx: usize) -> *mut Bucket<K, V>

source

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

source

pub fn group_buckets(&self, num_groups: usize) -> Vec<Range<usize>>

source

pub fn iter_for_bucket_range( &self, start_bucket: usize, end_bucket: usize ) -> PHashMapRangeIter<'_, K, V>

source

pub fn union_as_map<'a, F>( &'a self, other: &'a HashMap<K, V>, value_tiebreak_fn: F ) -> HashMap<K, V>where K: Copy, V: Copy, F: Fn((&'a K, &'a V), (&'a K, &'a V)) -> (&'a K, &'a V),

Trait Implementations§

source§

impl<K: Debug + Persistable, V: Debug + Persistable> Debug for PHashMap<K, V>

source§

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

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

impl<K, V> Into<HashMap<K, V>> for &PHashMap<K, V>where K: Eq + Default + Hash + Persistable + PersistentlyAllocatable + Copy, V: Persistable + Copy,

source§

fn into(self) -> HashMap<K, V>

Converts this type into the (usually inferred) input type.
source§

impl<'a, K, V> IntoIterator for &'a PHashMap<K, V>where K: Persistable, V: Persistable,

§

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

The type of the elements being iterated over.
§

type IntoIter = PHashMapIter<'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
source§

impl<K, V> Persistable for PHashMap<K, V>where K: Persistable, V: Persistable,

source§

fn as_bytes(&self) -> &[u8] where Self: Sized,

source§

fn from_bytes(src: *mut [u8]) -> *mut Selfwhere Self: Sized,

source§

fn from_bytes_ref(src: *const [u8]) -> &'static Selfwhere Self: Sized,

source§

fn adjust_from(&mut self, _other: &Self)

Used for object moves.
source§

impl<K, V> PersistentlyAllocatable for PHashMap<K, V>where K: Eq + Default + Hash + Persistable + PersistentlyAllocatable, V: Persistable,

source§

fn set_allocator(&mut self, allocator: Arc<RwLock<BumpAllocator>>)

Sets the allocator that is going to be used by the PHashMap instance whenever it needs to extend its internal capacity.

NOTE This needs to be set before any subsequent calls are made that would trigger an allocation.

source§

fn get_allocator(&self) -> Option<Arc<RwLock<BumpAllocator>>>

Auto Trait Implementations§

§

impl<K, V> !RefUnwindSafe for PHashMap<K, V>

§

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

§

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

§

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

§

impl<K, V> !UnwindSafe for PHashMap<K, V>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

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

§

fn vzip(self) -> V