Skip to main content

PackedMap

Struct PackedMap 

Source
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>
where K: ?Sized + Ord + PackedItem,

Source

pub fn builder() -> PackedMapBuilder<K, V>
where K: ToOwned, K::Owned: Ord,

Creates a new PackedMapBuilder.

Source

pub fn builder_with_capacity( element_capacity: usize, buffer_capacity: usize, ) -> PackedMapBuilder<K, V>
where K: ToOwned, K::Owned: Ord,

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.

Source

pub fn new() -> Self

Creates a new empty PackedMap.

Source

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.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Source

pub fn element_len(&self) -> usize

Returns the number of elements in the map.

Source

pub fn buffer_len(&self) -> usize

Returns the cumulative length of all keys in the map in bytes.

Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Ord + ?Sized,

Returns a reference to the value corresponding to the key.

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Ord + ?Sized,

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

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Ord + ?Sized,

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

Source

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, where N is the number of elements in the map.
Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the map as much as possible.

Source

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

Returns an iterator over the entries of the map, sorted by key.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Returns an iterator over the entries of the map, sorted by key, with mutable values.

Source

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.

Source

pub fn range<'a, Q, R>(&'a self, range: R) -> Range<'a, K, V>
where K: Borrow<Q>, Q: Ord + ?Sized + 'a, R: RangeBounds<&'a Q>,

Constructs a double-ended iterator over a sub-range of elements in the map.

Source

pub fn range_mut<'a, Q, R>(&'a mut self, range: R) -> RangeMut<'a, K, V>
where K: Borrow<Q>, Q: Ord + ?Sized + 'a, R: RangeBounds<&'a Q>,

Constructs a mutable double-ended iterator over a sub-range of elements in the map.

Source

pub fn keys(&self) -> Keys<'_, K>

Returns an iterator over the keys of the map, in sorted order.

Source

pub fn values(&self) -> Values<'_, V>

Returns an iterator over the values of the map, sorted by key.

Source

pub fn values_mut(&mut self) -> ValuesMut<'_, V>

Returns a mutable iterator over the values of the map, sorted by key.

Source

pub fn into_values(self) -> IntoValues<V>

Returns an iterator that takes ownership of the map’s values, sorted by key.

Trait Implementations§

Source§

impl<K: ?Sized + Ord + PackedItem, V: Clone> Clone for PackedMap<K, V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V: Debug> Debug for PackedMap<K, V>
where K: Debug + ?Sized + Ord + PackedItem,

Source§

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

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

impl<K: ?Sized + Ord + PackedItem, V> Default for PackedMap<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, K, V> Deserialize<'de> for PackedMap<K, V>
where K: ?Sized + PackedItem + Ord + ToOwned, Box<K>: Deserialize<'de> + Ord + AsRef<K>, V: Deserialize<'de>, K::Owned: Ord,

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K, V, U, const N: usize> From<[(U, V); N]> for PackedMap<K, V>
where K: ?Sized + Ord + PackedItem + ToOwned, U: AsRef<K>, K::Owned: Ord,

Source§

fn from(arr: [(U, V); N]) -> Self

Converts to this type from the input type.
Source§

impl<K, V, U> FromIterator<(U, V)> for PackedMap<K, V>
where K: ?Sized + Ord + PackedItem + ToOwned, U: AsRef<K>, K::Owned: Ord,

Source§

fn from_iter<T: IntoIterator<Item = (U, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<K: ?Sized + Ord + PackedItem, V: Hash> Hash for PackedMap<K, V>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<K, V, Q> Index<&Q> for PackedMap<K, V>
where K: ?Sized + Ord + PackedItem + Borrow<Q>, Q: Ord + ?Sized,

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, key: &Q) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, K: ?Sized + Ord + PackedItem, V> IntoIterator for &'a PackedMap<K, V>

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'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<'a, K: ?Sized + Ord + PackedItem, V> IntoIterator for &'a mut PackedMap<K, V>

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'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: ?Sized + Ord + PackedItem, V: PartialEq> PartialEq for PackedMap<K, V>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, V> Serialize for PackedMap<K, V>
where K: Serialize + ?Sized + Ord + PackedItem, V: Serialize,

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<K: ?Sized + Ord + PackedItem, V: Eq> Eq for PackedMap<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for PackedMap<K, V>
where K: ?Sized,

§

impl<K, V> RefUnwindSafe for PackedMap<K, V>
where V: RefUnwindSafe, K: ?Sized,

§

impl<K, V> Send for PackedMap<K, V>
where V: Send, K: ?Sized,

§

impl<K, V> Sync for PackedMap<K, V>
where V: Sync, K: ?Sized,

§

impl<K, V> Unpin for PackedMap<K, V>
where V: Unpin, K: ?Sized,

§

impl<K, V> UnsafeUnpin for PackedMap<K, V>
where K: ?Sized,

§

impl<K, V> UnwindSafe for PackedMap<K, V>
where V: UnwindSafe, K: ?Sized,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,