[−][src]Struct skew_forest::SkewMap
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]
&mut self,
forest: &SkewForest<Idx>,
f: impl FnMut() -> T
)
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]
impl<T, Idx: Index> IndexMut<SkewIndex<Idx>> for SkewMap<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for SkewMap<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for SkewMap<T> where
T: Send,
T: Send,
impl<T> Sync for SkewMap<T> where
T: Sync,
T: Sync,
impl<T> Unpin for SkewMap<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for SkewMap<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,