Skip to main content

AttrMap

Struct AttrMap 

Source
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

Source

pub fn new() -> AttrMap

Source

pub fn with_capacity(capacity: usize) -> AttrMap

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn get(&self, key: &str) -> Option<&CgseValue>

Source

pub fn get_key_value(&self, key: &str) -> Option<(&String, &CgseValue)>

Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut CgseValue>

Source

pub fn contains_key(&self, key: &str) -> bool

Source

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.

Source

pub fn remove(&mut self, key: &str) -> Option<CgseValue>

Remove key, keeping every other key where it was (a dict’s del).

Source

pub fn clear(&mut self)

Source

pub fn retain(&mut self, keep: impl FnMut(&String, &mut CgseValue) -> bool)

Source

pub fn iter(&self) -> AttrMapIter<'_> ⓘ

Source

pub fn iter_mut(&mut self) -> AttrMapIterMut<'_> ⓘ

Source

pub fn keys(&self) -> impl DoubleEndedIterator + ExactSizeIterator + Clone

Source

pub fn values(&self) -> impl DoubleEndedIterator + ExactSizeIterator + Clone

Source

pub fn values_mut(&mut self) -> impl DoubleEndedIterator + ExactSizeIterator

Source

pub fn into_values(self) -> impl DoubleEndedIterator + ExactSizeIterator

Trait Implementations§

Source§

impl Clone for AttrMap

Source§

fn clone(&self) -> AttrMap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for AttrMap

Source§

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

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

impl Default for AttrMap

Source§

fn default() -> AttrMap

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

impl<'de> Deserialize<'de> for AttrMap

Source§

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

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

impl Eq for AttrMap

Source§

impl Extend<(String, CgseValue)> for AttrMap

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = (String, CgseValue)>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<const N: usize> From<[(String, CgseValue); N]> for AttrMap

Source§

fn from(entries: [(String, CgseValue); N]) -> AttrMap

Converts to this type from the input type.
Source§

impl FromIterator<(String, CgseValue)> for AttrMap

Source§

fn from_iter<I>(iter: I) -> AttrMap
where I: IntoIterator<Item = (String, CgseValue)>,

Creates a value from an iterator. Read more
Source§

impl Index<&str> for AttrMap

Source§

fn index(&self, key: &str) -> &CgseValue

The value for key; panics when there is none, as a map’s index does.

Source§

type Output = CgseValue

The returned type after indexing.
Source§

impl IntoIterator for AttrMap

Source§

type Item = (String, CgseValue)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<(String, CgseValue)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <AttrMap as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a AttrMap

Source§

type Item = (&'a String, &'a CgseValue)

The type of the elements being iterated over.
Source§

type IntoIter = AttrMapIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a AttrMap as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut AttrMap

Source§

type Item = (&'a String, &'a mut CgseValue)

The type of the elements being iterated over.
Source§

type IntoIter = AttrMapIterMut<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a mut AttrMap as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for AttrMap

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for AttrMap

Source§

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.