pub struct MapData(/* private fields */);Expand description
The contents of a map. Holds pairs of keys and values in insertion order, with an index for looking up keys (key →
where the pair is stored).
- Lookup, update, insertion and removal take time proportional to the size of the key (not a linear search). Keys are compared and hashed as values, without converting them to strings.
- Removal only empties the slot of the pair, without shifting the pairs after it. When the holes exceed the number of
pairs, they are compacted at once (amortized constant time per removal).
MapData::entriesgoes through the pairs in insertion order, skipping holes. - Cloning only shares the
Arc(the first update after cloning copies the contents). Reading a hugemapdoes not mean copying the whole thing every time. A clone is independent of the original (value semantics). - The index is not saved. It is rebuilt on restore (
From<Vec<_>>,Deserialize). - Keeps the total size of the pairs (the estimate of
Value::approx_bytes) incrementally, so checking value sizes is not proportional to the size of themap. When a value inside nesting is updated, the outer side reports it withadjust_bytes(within the crate). ==does not compare insertion order (equal if they have the same values for the same keys).
Implementations§
Source§impl MapData
impl MapData
Sourcepub fn from_pairs(pairs: Vec<(Value, Value)>) -> Self
pub fn from_pairs(pairs: Vec<(Value, Value)>) -> Self
Makes one from a sequence of pairs. If a key repeats, the later value updates it (the position stays the first one).
Sourcepub fn entries(&self) -> MapEntries<'_> ⓘ
pub fn entries(&self) -> MapEntries<'_> ⓘ
Goes through the pairs in insertion order.
Sourcepub fn iter(&self) -> MapEntries<'_> ⓘ
pub fn iter(&self) -> MapEntries<'_> ⓘ
Goes through the pairs in insertion order (same as MapData::entries).
Sourcepub fn into_entries(self) -> Vec<(Value, Value)>
pub fn into_entries(self) -> Vec<(Value, Value)>
Takes the pairs out (in insertion order). Does not copy the pairs if not shared.
Sourcepub fn contains_key(&self, key: &Value) -> bool
pub fn contains_key(&self, key: &Value) -> bool
Whether the key exists.
Trait Implementations§
Source§impl Debug for MapData
Shows only the sequence of pairs ([(key, value), …]), without the index or holes (so the output is stable).
impl Debug for MapData
Shows only the sequence of pairs ([(key, value), …]), without the index or holes (so the output is stable).
Source§impl<'de> Deserialize<'de> for MapData
impl<'de> Deserialize<'de> for MapData
Source§fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'a> IntoIterator for &'a MapData
impl<'a> IntoIterator for &'a MapData
Auto Trait Implementations§
impl Forget for MapData
impl Freeze for MapData
impl Move for MapData
impl RefUnwindSafe for MapData
impl Send for MapData
impl Sync for MapData
impl Unpin for MapData
impl UnsafeUnpin for MapData
impl UnwindSafe for MapData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more