pub struct PackedMap<K: ?Sized + Ord + PackedItem, V> { /* private fields */ }Expand description
A map with keys stored in a sorted PackedVec<K> and values in a Vec<V>.
This map is optimized for reducing memory usage by using a packed representation for keys. It does not support modification after creation.
Implementations§
Source§impl<K, V> PackedMap<K, V>
impl<K, V> PackedMap<K, V>
Sourcepub fn builder() -> PackedMapBuilder<K, V>
pub fn builder() -> PackedMapBuilder<K, V>
Creates a new PackedMapBuilder.
Sourcepub fn builder_with_capacity(
element_capacity: usize,
buffer_capacity: usize,
) -> PackedMapBuilder<K, V>
pub fn builder_with_capacity( element_capacity: usize, buffer_capacity: usize, ) -> PackedMapBuilder<K, V>
Creates a new PackedMapBuilder with the specified capacities.
The element_capacity argument specifies the number of slices that can be
stored without reallocating the offsets vector. The buffer_capacity
argument specifies the cumulative length of slices that can be stored
without reallocating the data vector.
Sourcepub fn with_capacity(element_capacity: usize, buffer_capacity: usize) -> Self
pub fn with_capacity(element_capacity: usize, buffer_capacity: usize) -> Self
Creates a new PackedMap with the specified capacities.
The element_capacity argument specifies the number of slices that can be
stored without reallocating the offsets vector. The buffer_capacity
argument specifies the cumulative length of slices that can be stored
without reallocating the data vector.
Sourcepub fn element_len(&self) -> usize
pub fn element_len(&self) -> usize
Returns the number of elements in the map.
Sourcepub fn buffer_len(&self) -> usize
pub fn buffer_len(&self) -> usize
Returns the cumulative length of all keys in the map in bytes.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the map contains a value for the specified key.
Sourcepub fn append_or_update(&mut self, key: &K, value: V) -> Result<Option<V>, V>
pub fn append_or_update(&mut self, key: &K, value: V) -> Result<Option<V>, V>
Inserts a key-value pair into the map.
If the key is already present, updates the value and returns Ok(Some(old_value)).
If the key is greater than the last key, appends it and returns Ok(None).
Otherwise, returns Err(value).
§Complexity
O(1)if the key is greater than or equal to the last key in the map.O(log N)otherwise, whereNis the number of elements in the map.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible.
Sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
Returns an iterator over the entries of the map, sorted by key.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>
Returns an iterator over the entries of the map, sorted by key, with mutable values.
Sourcepub fn drain(&mut self) -> Drain<'_, K, V>
pub fn drain(&mut self) -> Drain<'_, K, V>
Drains all elements from the map, returning a lending iterator that yields them.
The elements are yielded in sorted order by key. After the iterator is dropped, the map is left empty.
§Leaked
If the returned Drain iterator is leaked (e.g. via std::mem::forget),
any elements that have not been yielded yet will be leaked (their destructors
will not run). However, memory safety is still preserved as the map will be left empty.
Sourcepub fn range<'a, Q, R>(&'a self, range: R) -> Range<'a, K, V>
pub fn range<'a, Q, R>(&'a self, range: R) -> Range<'a, K, V>
Constructs a double-ended iterator over a sub-range of elements in the map.
Sourcepub fn range_mut<'a, Q, R>(&'a mut self, range: R) -> RangeMut<'a, K, V>
pub fn range_mut<'a, Q, R>(&'a mut self, range: R) -> RangeMut<'a, K, V>
Constructs a mutable double-ended iterator over a sub-range of elements in the map.
Sourcepub fn keys(&self) -> Keys<'_, K>
pub fn keys(&self) -> Keys<'_, K>
Returns an iterator over the keys of the map, in sorted order.
Sourcepub fn values(&self) -> Values<'_, V>
pub fn values(&self) -> Values<'_, V>
Returns an iterator over the values of the map, sorted by key.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, V>
pub fn values_mut(&mut self) -> ValuesMut<'_, V>
Returns a mutable iterator over the values of the map, sorted by key.
Sourcepub fn into_values(self) -> IntoValues<V>
pub fn into_values(self) -> IntoValues<V>
Returns an iterator that takes ownership of the map’s values, sorted by key.