Struct object_lib::collections::pmap::PHashMap
source · #[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: usizeImplementations§
source§impl<K, V> PHashMap<K, V>where
K: Eq + Default + Hash + Persistable + PersistentlyAllocatable,
V: Persistable,
impl<K, V> PHashMap<K, V>where K: Eq + Default + Hash + Persistable + PersistentlyAllocatable, V: Persistable,
sourcepub fn new() -> Self
pub fn new() -> Self
Instantiates a new empty hashmap. No allocations are made as a result of this call.
sourcepub fn with_capacity(&mut self, capacity: usize)
pub fn with_capacity(&mut self, capacity: usize)
Allocates space for the PHashMap to hold at least capacity elements before a
reallocation is needed.
sourcepub fn insert<T>(&mut self, k: T, v: V) -> Option<V>where
T: Hash,
K: CopyFrom<From = T> + PartialEq<T>,
pub fn insert<T>(&mut self, k: T, v: V) -> Option<V>where T: Hash, K: CopyFrom<From = T> + PartialEq<T>,
pub fn clear(&mut self)
sourcepub fn get<T>(&self, k: &T) -> Option<&V>where
T: Hash,
K: CopyFrom<From = T> + PartialEq<T>,
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.
fn get_pkey(&self, k: &K) -> Option<&V>
sourcepub fn get_mut(&self, k: &K) -> Option<&mut V>
pub fn get_mut(&self, k: &K) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the (persistable) key.
sourcepub fn get_mut_non_persistent_key<T>(&self, k: &T) -> Option<&mut V>where
T: Hash,
K: CopyFrom<From = T> + PartialEq<T>,
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.
sourcepub fn contains(&self, k: &K) -> bool
pub fn contains(&self, k: &K) -> bool
Returns true if the map contains a value for the specified key.
sourcepub fn contains_key<T>(&self, k: &T) -> boolwhere
T: Hash,
K: CopyFrom<From = T> + PartialEq<T>,
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]).
fn get_hash_for_other_key<T>(&self, key: &T) -> usizewhere T: Hash, K: CopyFrom<From = T>,
unsafe fn get_bucket_at_index_ptr(&self, idx: usize) -> *mut Bucket<K, V>
pub fn iter(&self) -> PHashMapIter<'_, K, V> ⓘ
pub fn group_buckets(&self, num_groups: usize) -> Vec<Range<usize>>
pub fn iter_for_bucket_range( &self, start_bucket: usize, end_bucket: usize ) -> PHashMapRangeIter<'_, K, V> ⓘ
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>
impl<K: Debug + Persistable, V: Debug + Persistable> Debug for PHashMap<K, V>
source§impl<K, V> Into<HashMap<K, V>> for &PHashMap<K, V>where
K: Eq + Default + Hash + Persistable + PersistentlyAllocatable + Copy,
V: Persistable + Copy,
impl<K, V> Into<HashMap<K, V>> for &PHashMap<K, V>where K: Eq + Default + Hash + Persistable + PersistentlyAllocatable + Copy, V: Persistable + Copy,
source§impl<'a, K, V> IntoIterator for &'a PHashMap<K, V>where
K: Persistable,
V: Persistable,
impl<'a, K, V> IntoIterator for &'a PHashMap<K, V>where K: Persistable, V: Persistable,
source§impl<K, V> Persistable for PHashMap<K, V>where
K: Persistable,
V: Persistable,
impl<K, V> Persistable for PHashMap<K, V>where K: Persistable, V: Persistable,
source§impl<K, V> PersistentlyAllocatable for PHashMap<K, V>where
K: Eq + Default + Hash + Persistable + PersistentlyAllocatable,
V: Persistable,
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>>)
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.