pub struct AttrMap { /* private fields */ }Expand description
An attribute map that keeps its keys in INSERTION order, as the Python dict it stands for does (br-r37-c1-6hyf1).
It was a BTreeMap, which lists keys sorted. networkx hands out dicts in
the order their keys were set, so every attribute dict with two or more
keys that were not already sorted needed a Python mirror dict beside the
store just to remember that order - an extra dict, a write-watch adoption
and a (String, String) map entry per edge, about 30% of a multi-key
add_edges_from. With the order kept here, a dict rebuilt from the store
is the caller’s dict, and only a value the store cannot hold (a tuple, a
nested dict, an object) still needs a mirror.
The entries live in one Vec, in insertion order: an attribute map almost
always holds a handful of keys, which a scan finds faster than a hash, and
one allocation per map is what the batch and copy kernels pay per edge (an
IndexMap made two and grew CgseValue from 32 to 64 bytes, and single-key
add_edges_from measured ~10% slower on it). Past INDEXED_LEN keys a
hash index is kept beside the entries, so a map with thousands of keys -
an adversarial graph - still finds one in O(1) rather than O(keys).
Removal keeps the other keys in order (a dict’s del). Equality ignores
order, as a dict’s does.
Implementations§
Source§impl AttrMap
impl AttrMap
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn get(&self, key: &str) -> Option<&CgseValue>
pub fn get_key_value(&self, key: &str) -> Option<(&String, &CgseValue)>
pub fn get_mut(&mut self, key: &str) -> Option<&mut CgseValue>
pub fn contains_key(&self, key: &str) -> bool
Sourcepub fn insert(&mut self, key: String, value: CgseValue) -> Option<CgseValue>
pub fn insert(&mut self, key: String, value: CgseValue) -> Option<CgseValue>
Set key: an existing key keeps its place, a new one goes last (a
dict’s d[k] = v). Returns the value it replaced.
Sourcepub fn remove(&mut self, key: &str) -> Option<CgseValue>
pub fn remove(&mut self, key: &str) -> Option<CgseValue>
Remove key, keeping every other key where it was (a dict’s del).
pub fn clear(&mut self)
pub fn retain(&mut self, keep: impl FnMut(&String, &mut CgseValue) -> bool)
pub fn iter(&self) -> AttrMapIter<'_> ⓘ
pub fn iter_mut(&mut self) -> AttrMapIterMut<'_> ⓘ
pub fn keys( &self, ) -> impl DoubleEndedIterator<Item = &String> + ExactSizeIterator + Clone
pub fn values( &self, ) -> impl DoubleEndedIterator<Item = &CgseValue> + ExactSizeIterator + Clone
pub fn values_mut( &mut self, ) -> impl DoubleEndedIterator<Item = &mut CgseValue> + ExactSizeIterator
pub fn into_values( self, ) -> impl DoubleEndedIterator<Item = CgseValue> + ExactSizeIterator
Trait Implementations§
Source§impl<'de> Deserialize<'de> for AttrMap
impl<'de> Deserialize<'de> for AttrMap
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for AttrMap
Source§impl Extend<(String, CgseValue)> for AttrMap
impl Extend<(String, CgseValue)> for AttrMap
Source§fn extend<I: IntoIterator<Item = (String, CgseValue)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (String, CgseValue)>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)