[][src]Struct skew_forest::SkewMap

pub struct SkewMap<T> { /* fields omitted */ }

A mapping from the nodes in a SkewForest to values.

Synchronization

The SkewMap must be kept synchronized with the underlying SkewForest. This means that when a node is pushed onto a path in the SkewForest, then a value must also be pushed onto this SkewMap.

Example

use skew_forest::{SkewForest, SkewPath, SkewPathNode, SkewMap};
 
let mut forest = SkewForest::default();
let mut path = SkewPath::<[SkewPathNode; 8]>::default();
let mut map = SkewMap::default();
 
map.push(forest.push(&mut path), "some value");
map.push(forest.push(&mut path), "some other value");
 
assert_eq!(
    forest.iter(&path).map(|ix| map[ix]).collect::<Vec<_>>(),
    vec!["some value", "some other value"],
);

Methods

impl<T> SkewMap<T>[src]

pub fn synchronize<Idx: Index>(
    &mut self,
    forest: &SkewForest<Idx>,
    f: impl FnMut() -> T
)
[src]

Synchronizes this SkewMap with the given SkewForest, inserting new elements by calling a function.

Example

use skew_forest::{SkewForest, SkewPath, SkewPathNode, SkewMap};
 
let mut forest = SkewForest::default();
let mut path = SkewPath::<[SkewPathNode; 8]>::default();
let mut map = SkewMap::default();
 
forest.push(&mut path);
 
// A value has been inserted in the forest without being inserted in the map - they are not
// synchronized!
assert!(!map.is_synchronized(&forest));
 
map.synchronize(&forest, || "some value");
 
// A value for each node has been inserted - we are synchronized again.
assert!(map.is_synchronized(&forest));

pub fn is_synchronized<Idx: Index>(&self, forest: &SkewForest<Idx>) -> bool[src]

Whether this SkewMap is synchronized with the corresponding SkewForest.

pub fn push<Idx: Index>(&mut self, index: SkewIndex<Idx>, value: T) -> Option<T>[src]

Pushes a value with the given index onto this map. If the returned index is one that previously contained a value (due to being reused after garbage collected), then the old value is returned, otherwise None.

Panics

May panic if the SkewMap was not synchronized with the SkewForest that created the SkewIndex prior to the push operation that created the SkewIndex.

Example

use skew_forest::{SkewForest, SkewPath, SkewPathNode, SkewMap};
 
let mut forest = SkewForest::default();
let mut path = SkewPath::<[SkewPathNode; 8]>::default();
let mut map = SkewMap::default();
 
map.push(forest.push(&mut path), "some value");
 
assert_eq!(map[path.last().unwrap()], "some value");

Trait Implementations

impl<T: Clone> Clone for SkewMap<T>[src]

impl<T: Debug> Debug for SkewMap<T>[src]

impl<T: Default> Default for SkewMap<T>[src]

impl<T, Idx: Index> Index<SkewIndex<Idx>> for SkewMap<T>[src]

type Output = T

The returned type after indexing.

impl<T, Idx: Index> IndexMut<SkewIndex<Idx>> for SkewMap<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for SkewMap<T> where
    T: RefUnwindSafe

impl<T> Send for SkewMap<T> where
    T: Send

impl<T> Sync for SkewMap<T> where
    T: Sync

impl<T> Unpin for SkewMap<T> where
    T: Unpin

impl<T> UnwindSafe for SkewMap<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.