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() -> AttrMap
pub fn with_capacity(capacity: usize) -> AttrMap
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 + ExactSizeIterator + Clone
pub fn values(&self) -> impl DoubleEndedIterator + ExactSizeIterator + Clone
pub fn values_mut(&mut self) -> impl DoubleEndedIterator + ExactSizeIterator
pub fn into_values(self) -> impl DoubleEndedIterator + ExactSizeIterator
Trait Implementations§
Source§impl<'de> Deserialize<'de> for AttrMap
impl<'de> Deserialize<'de> for AttrMap
Source§fn deserialize<D>(
deserializer: D,
) -> Result<AttrMap, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<AttrMap, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for AttrMap
Source§impl Extend<(String, CgseValue)> for AttrMap
impl Extend<(String, CgseValue)> for AttrMap
Source§fn extend<I>(&mut self, iter: I)
fn extend<I>(&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)Source§impl IntoIterator for AttrMap
impl IntoIterator for AttrMap
Source§impl<'a> IntoIterator for &'a AttrMap
impl<'a> IntoIterator for &'a AttrMap
Source§impl<'a> IntoIterator for &'a mut AttrMap
impl<'a> IntoIterator for &'a mut AttrMap
Source§impl Serialize for AttrMap
impl Serialize for AttrMap
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Auto Trait Implementations§
impl Freeze for AttrMap
impl RefUnwindSafe for AttrMap
impl Send for AttrMap
impl Sync for AttrMap
impl Unpin for AttrMap
impl UnsafeUnpin for AttrMap
impl UnwindSafe for AttrMap
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.