[−][src]Struct lockfreehashmap::map_inner::MapInner
A map containing a unique, non-resizable array to the Key/Value pairs. If the map needs to be
resized, a new MapInner
must be created and its Key/Value pairs must be copied from this one.
Logically, this struct owns its keys and values, and so is responsible for freeing them when
dropped.
Fields
map: Vec<(AtomicPtr<KeySlot<K>>, AtomicPtr<ValueSlot<'v, V>>)>
The key/value pairs in this map, allocated as an array of pairs.
size: AtomicUsize
The amount of key/value pairs in the array, if any.
newer_map: AtomicPtr<MapInner<'v, K, V, S>>
Points to the newer map or null if none.
resizers_count: AtomicUsize
Any thread can allocate memory to resize the map and create newer_map
. Thus, we want to
try and limit the amount of allocations done. This is a monotonically increasing count of
the number of threads currently trying to allocate a new map, which is used as a heuristic.
See its use in the MapInner::create_newer_map()
function.
chunks_copied: AtomicUsize
The number of ::COPY_CHUNK_SIZE = 32
element chunks that some thread has commited to
copying to the newer table. Once this reaches capacity/COPY_CHUNK_SIZE
, we know that the
entire map has been copied into the large newer_map
.
slots_copied: AtomicUsize
The actual number of key/value pairs that have been copied into the newer map.
hash_builder: S
The hasher used to hash keys.
Methods
impl<'v, K, V, S> MapInner<'v, K, V, S>
[src]
impl<'v, K, V, S> MapInner<'v, K, V, S>
pub const DEFAULT_CAPACITY: usize
[src]
The default size of a new LockFreeHashMap
.
pub fn capacity(&self) -> usize
[src]
pub fn capacity(&self) -> usize
Returns the capacity of the current map; i.e. the length of the Vec
storing the key/value
pairs.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the size of the current map at some point in time; i.e. the number of key/value pairs in the map.
pub fn get_at(
&self,
pos: usize
) -> Option<&(AtomicPtr<KeySlot<K>>, AtomicPtr<ValueSlot<'v, V>>)>
[src]
pub fn get_at(
&self,
pos: usize
) -> Option<&(AtomicPtr<KeySlot<K>>, AtomicPtr<ValueSlot<'v, V>>)>
pub unsafe fn drop_newer_maps(&self, guard: &Guard)
[src]
pub unsafe fn drop_newer_maps(&self, guard: &Guard)
Drops self.newer_map
and any newer maps that self.newer_map
points to.
pub unsafe fn drop_self_and_newer_maps(self, guard: &Guard)
[src]
pub unsafe fn drop_self_and_newer_maps(self, guard: &Guard)
Drops self, self.newer_map
and any newer maps that self.newer_map
points to.
impl<'v, K: Hash + Eq, V: PartialEq> MapInner<'v, K, V, RandomState>
[src]
impl<'v, K: Hash + Eq, V: PartialEq> MapInner<'v, K, V, RandomState>
pub fn with_capacity(size: usize) -> Self
[src]
pub fn with_capacity(size: usize) -> Self
Creates a new MapInner
. Uses the next power of two if size is not a power of two.
impl<'guard, 'v: 'guard, K, V, S> MapInner<'v, K, V, S> where
K: Hash + Eq,
V: PartialEq,
S: BuildHasher + Clone,
[src]
impl<'guard, 'v: 'guard, K, V, S> MapInner<'v, K, V, S> where
K: Hash + Eq,
V: PartialEq,
S: BuildHasher + Clone,
pub fn with_capacity_and_hasher(size: usize, hasher: S) -> Self
[src]
pub fn with_capacity_and_hasher(size: usize, hasher: S) -> Self
pub fn help_copy(
&self,
newer_map: NotNull<Self>,
copy_everything: bool,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
)
[src]
pub fn help_copy(
&self,
newer_map: NotNull<Self>,
copy_everything: bool,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
)
Help copy a small chunk of the map to the newer_map
. See ::COPY_CHUNK_SIZE
for the
default chunk size.
pub fn promote(
&self,
new_map: NotNull<Self>,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> bool
[src]
pub fn promote(
&self,
new_map: NotNull<Self>,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> bool
Once a MapInner
has had all its elements copied to its newer_map
field,
the LockFreeHashMap's inner
field must be promoted so that its effects are visible
globally.
fn ensure_slot_copied(
&self,
copy_index: usize,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> NotNull<'guard, Self>
[src]
fn ensure_slot_copied(
&self,
copy_index: usize,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> NotNull<'guard, Self>
pub fn try_promote(
&self,
new_map: NotNull<Self>,
current_slots_copied: usize,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> bool
[src]
pub fn try_promote(
&self,
new_map: NotNull<Self>,
current_slots_copied: usize,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> bool
pub fn copy_slot(
&self,
new_map: &Self,
old_map_index: usize,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> bool
[src]
pub fn copy_slot(
&self,
new_map: &Self,
old_map_index: usize,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> bool
Copies a single key/value pair from the map in &self
to the map in &self.newer_map
.
Returns whether or not this thread was the one to copy the slot. Since copying takes several transitions that could happen from any thread, it doesn't matter which transition we pick as long as exactly one thread reports true for copying a specific slot.
pub fn create_newer_map(&self, guard: &'guard Guard) -> NotNull<'guard, Self>
[src]
pub fn create_newer_map(&self, guard: &'guard Guard) -> NotNull<'guard, Self>
If newer_map
doesn't exist, then this function tries to allocate a newer map that's
double the size of self
.
Returns a Shared
pointer to the newer map
pub fn hash_key<Q: ?Sized>(&self, key: &Q) -> usize where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
pub fn hash_key<Q: ?Sized>(&self, key: &Q) -> usize where
K: Borrow<Q>,
Q: Hash + Eq,
pub fn keys_are_equal<T1: ?Sized, T2: ?Sized>(
&self,
first: &T1,
second: &T2
) -> bool where
T2: PartialEq<T1>,
[src]
pub fn keys_are_equal<T1: ?Sized, T2: ?Sized>(
&self,
first: &T1,
second: &T2
) -> bool where
T2: PartialEq<T1>,
pub fn get<Q: ?Sized>(
&self,
key: &Q,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
[src]
pub fn get<Q: ?Sized>(
&self,
key: &Q,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
Returns the current value associated with some key, if any.
pub fn update_size_and_defer(
&'guard self,
old_value_slot: MaybeNull<'guard, ValueSlot<V>>,
insert_tombstone: bool,
guard: &'guard Guard
) -> Option<&'guard ValueSlot<V>>
[src]
pub fn update_size_and_defer(
&'guard self,
old_value_slot: MaybeNull<'guard, ValueSlot<V>>,
insert_tombstone: bool,
guard: &'guard Guard
) -> Option<&'guard ValueSlot<V>>
Increments or decrements the current size of the map, returning the previous value in the map.
pub fn put_if_match<Q: ?Sized>(
&'guard self,
key: KeyCompare<K, Q>,
put: PutValue<'v, V>,
matcher: Match,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> Option<&'guard ValueSlot<V>> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
[src]
pub fn put_if_match<Q: ?Sized>(
&'guard self,
key: KeyCompare<K, Q>,
put: PutValue<'v, V>,
matcher: Match,
outer_map: &AtomicBox<Self>,
guard: &'guard Guard
) -> Option<&'guard ValueSlot<V>> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
pub fn clone_hasher(&self) -> S
[src]
pub fn clone_hasher(&self) -> S
Trait Implementations
impl<'v, K, V, S> Drop for MapInner<'v, K, V, S>
[src]
impl<'v, K, V, S> Drop for MapInner<'v, K, V, S>
impl<'v, K: Debug, V: Debug + 'v, S: Debug> Debug for MapInner<'v, K, V, S>
[src]
impl<'v, K: Debug, V: Debug + 'v, S: Debug> Debug for MapInner<'v, K, V, S>
Auto Trait Implementations
impl<'v, K, V, S> Send for MapInner<'v, K, V, S> where
K: Send + Sync,
S: Send + Sync,
V: Send + Sync,
impl<'v, K, V, S> Send for MapInner<'v, K, V, S> where
K: Send + Sync,
S: Send + Sync,
V: Send + Sync,
impl<'v, K, V, S> Sync for MapInner<'v, K, V, S> where
K: Send + Sync,
S: Send + Sync,
V: Send + Sync,
impl<'v, K, V, S> Sync for MapInner<'v, K, V, S> where
K: Send + Sync,
S: Send + Sync,
V: Send + Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more