Struct indexmap::map::core::IndexMapCore
source · pub(crate) struct IndexMapCore<K, V> {
indices: RawTable<usize>,
entries: Vec<Bucket<K, V>>,
}
Expand description
Core of the map that does not depend on S
Fields§
§indices: RawTable<usize>
indices mapping from the entry hash to its index.
entries: Vec<Bucket<K, V>>
entries is a dense vec of entries in their order.
Implementations§
source§impl<K, V> IndexMapCore<K, V>
impl<K, V> IndexMapCore<K, V>
source§impl<K, V> IndexMapCore<K, V>
impl<K, V> IndexMapCore<K, V>
sourcepub(super) fn erase_indices_sweep(&mut self, start: usize, end: usize)
pub(super) fn erase_indices_sweep(&mut self, start: usize, end: usize)
Sweep the whole table to erase indices start..end
sourcepub(crate) fn find_or_insert(
&mut self,
hash: HashValue,
key: &K,
) -> Result<usize, usize>where
K: Eq,
pub(crate) fn find_or_insert(
&mut self,
hash: HashValue,
key: &K,
) -> Result<usize, usize>where
K: Eq,
Search for a key in the table and return Ok(entry_index)
if found.
Otherwise, insert the key and return Err(new_index)
.
Note that hashbrown may resize the table to reserve space for insertion, even before checking if it’s already present, so this is somewhat biased towards new items.
pub(super) fn raw_entry( &mut self, hash: HashValue, is_match: impl FnMut(&K) -> bool, ) -> Result<RawTableEntry<'_, K, V>, &mut Self>
pub(super) fn index_raw_entry( &mut self, index: usize, ) -> Option<RawTableEntry<'_, K, V>>
pub(super) fn indices_mut(&mut self) -> impl Iterator<Item = &mut usize>
source§impl<K, V> IndexMapCore<K, V>
impl<K, V> IndexMapCore<K, V>
sourceconst MAX_ENTRIES_CAPACITY: usize = _
const MAX_ENTRIES_CAPACITY: usize = _
The maximum capacity before the entries
allocation would exceed isize::MAX
.
pub(crate) const fn new() -> Self
pub(crate) fn with_capacity(n: usize) -> Self
pub(crate) fn len(&self) -> usize
pub(crate) fn capacity(&self) -> usize
pub(crate) fn clear(&mut self)
pub(crate) fn truncate(&mut self, len: usize)
pub(crate) fn drain<R>(&mut self, range: R) -> Drain<'_, Bucket<K, V>>where
R: RangeBounds<usize>,
pub(crate) fn split_off(&mut self, at: usize) -> Self
pub(crate) fn split_splice<R>(
&mut self,
range: R,
) -> (Self, IntoIter<Bucket<K, V>>)where
R: RangeBounds<usize>,
sourcepub(crate) fn append_unchecked(&mut self, other: &mut Self)
pub(crate) fn append_unchecked(&mut self, other: &mut Self)
Append from another map without checking whether items already exist.
sourcepub(crate) fn reserve(&mut self, additional: usize)
pub(crate) fn reserve(&mut self, additional: usize)
Reserve capacity for additional
more key-value pairs.
sourcefn reserve_entries(&mut self, additional: usize)
fn reserve_entries(&mut self, additional: usize)
Reserve entries capacity, rounded up to match the indices
sourcepub(crate) fn reserve_exact(&mut self, additional: usize)
pub(crate) fn reserve_exact(&mut self, additional: usize)
Reserve capacity for additional
more key-value pairs, without over-allocating.
sourcepub(crate) fn try_reserve(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
pub(crate) fn try_reserve( &mut self, additional: usize, ) -> Result<(), TryReserveError>
Try to reserve capacity for additional
more key-value pairs.
sourcefn try_reserve_entries(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
fn try_reserve_entries( &mut self, additional: usize, ) -> Result<(), TryReserveError>
Try to reserve entries capacity, rounded up to match the indices
sourcepub(crate) fn try_reserve_exact(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
pub(crate) fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>
Try to reserve capacity for additional
more key-value pairs, without over-allocating.
sourcepub(crate) fn shrink_to(&mut self, min_capacity: usize)
pub(crate) fn shrink_to(&mut self, min_capacity: usize)
Shrink the capacity of the map with a lower bound
sourcefn push_entry(&mut self, hash: HashValue, key: K, value: V)
fn push_entry(&mut self, hash: HashValue, key: K, value: V)
Append a key-value pair to entries
, without checking whether it already exists.
sourcefn insert_entry(&mut self, index: usize, hash: HashValue, key: K, value: V)
fn insert_entry(&mut self, index: usize, hash: HashValue, key: K, value: V)
Insert a key-value pair in entries
at a particular index,
without checking whether it already exists.
sourcepub(crate) fn get_index_of<Q>(&self, hash: HashValue, key: &Q) -> Option<usize>where
Q: ?Sized + Equivalent<K>,
pub(crate) fn get_index_of<Q>(&self, hash: HashValue, key: &Q) -> Option<usize>where
Q: ?Sized + Equivalent<K>,
Return the index in entries
where an equivalent key can be found
pub(crate) fn insert_full(
&mut self,
hash: HashValue,
key: K,
value: V,
) -> (usize, Option<V>)where
K: Eq,
sourcepub(crate) fn replace_full(
&mut self,
hash: HashValue,
key: K,
value: V,
) -> (usize, Option<(K, V)>)where
K: Eq,
pub(crate) fn replace_full(
&mut self,
hash: HashValue,
key: K,
value: V,
) -> (usize, Option<(K, V)>)where
K: Eq,
Same as insert_full
, except it also replaces the key
fn insert_unique(&mut self, hash: HashValue, key: K, value: V) -> usize
fn shift_insert_unique( &mut self, index: usize, hash: HashValue, key: K, value: V, )
sourcepub(crate) fn shift_remove_full<Q>(
&mut self,
hash: HashValue,
key: &Q,
) -> Option<(usize, K, V)>where
Q: ?Sized + Equivalent<K>,
pub(crate) fn shift_remove_full<Q>(
&mut self,
hash: HashValue,
key: &Q,
) -> Option<(usize, K, V)>where
Q: ?Sized + Equivalent<K>,
Remove an entry by shifting all entries that follow it
sourcepub(crate) fn shift_remove_index(&mut self, index: usize) -> Option<(K, V)>
pub(crate) fn shift_remove_index(&mut self, index: usize) -> Option<(K, V)>
Remove an entry by shifting all entries that follow it
sourcefn shift_remove_finish(&mut self, index: usize) -> (K, V)
fn shift_remove_finish(&mut self, index: usize) -> (K, V)
Remove an entry by shifting all entries that follow it
The index should already be removed from self.indices
.
sourcefn decrement_indices(&mut self, start: usize, end: usize)
fn decrement_indices(&mut self, start: usize, end: usize)
Decrement all indices in the range start..end
.
The index start - 1
should not exist in self.indices
.
All entries should still be in their original positions.
sourcefn increment_indices(&mut self, start: usize, end: usize)
fn increment_indices(&mut self, start: usize, end: usize)
Increment all indices in the range start..end
.
The index end
should not exist in self.indices
.
All entries should still be in their original positions.
pub(super) fn move_index(&mut self, from: usize, to: usize)
pub(crate) fn swap_indices(&mut self, a: usize, b: usize)
sourcepub(crate) fn swap_remove_full<Q>(
&mut self,
hash: HashValue,
key: &Q,
) -> Option<(usize, K, V)>where
Q: ?Sized + Equivalent<K>,
pub(crate) fn swap_remove_full<Q>(
&mut self,
hash: HashValue,
key: &Q,
) -> Option<(usize, K, V)>where
Q: ?Sized + Equivalent<K>,
Remove an entry by swapping it with the last
sourcepub(crate) fn swap_remove_index(&mut self, index: usize) -> Option<(K, V)>
pub(crate) fn swap_remove_index(&mut self, index: usize) -> Option<(K, V)>
Remove an entry by swapping it with the last
sourcefn swap_remove_finish(&mut self, index: usize) -> (K, V)
fn swap_remove_finish(&mut self, index: usize) -> (K, V)
Finish removing an entry by swapping it with the last
The index should already be removed from self.indices
.
sourcefn erase_indices(&mut self, start: usize, end: usize)
fn erase_indices(&mut self, start: usize, end: usize)
Erase start..end
from indices
, and shift end..
indices down to start..
All of these items should still be at their original location in entries
.
This is used by drain
, which will let Vec::drain
do the work on entries
.