[−][src]Struct generational_indextree::Arena
An Arena structure containing certain Nodes.
Implementations
impl<T> Arena<T>[src]
pub fn new() -> Arena<T>[src]
Creates a new empty Arena.
pub fn with_capacity(n: usize) -> Arena<T>[src]
Create a new empty Arena with pre-allocated memory for n items.
pub fn new_node(&mut self, data: T) -> NodeId[src]
Creates a new node from its associated data.
Panics
Panics if the arena already has usize::max_value() nodes.
Examples
let mut arena = Arena::new(); let foo = arena.new_node("foo"); assert_eq!(*arena[foo].get(), "foo");
pub fn count(&self) -> usize[src]
Counts the number of nodes in arena and returns it.
Examples
let mut arena = Arena::new(); let foo = arena.new_node("foo"); let _bar = arena.new_node("bar"); assert_eq!(arena.count(), 2); foo.remove(&mut arena); assert_eq!(arena.count(), 1);
pub fn is_empty(&self) -> bool[src]
Returns true if arena has no nodes, false otherwise.
Examples
let mut arena = Arena::new(); assert!(arena.is_empty()); let foo = arena.new_node("foo"); assert!(!arena.is_empty()); foo.remove(&mut arena); assert!(arena.is_empty());
pub fn get(&self, id: NodeId) -> Option<&Node<T>>[src]
Returns a reference to the node with the given id if in the arena.
Returns None if not available.
Examples
let mut arena = Arena::new(); let foo = arena.new_node("foo"); assert_eq!(arena.get(foo).map(|node| *node.get()), Some("foo"));
Note that this does not check whether the given node ID is created by the arena.
let mut arena = Arena::new(); let foo = arena.new_node("foo"); let bar = arena.new_node("bar"); assert_eq!(arena.get(foo).map(|node| *node.get()), Some("foo")); let mut another_arena = Arena::new(); let _ = another_arena.new_node("Another arena"); assert_eq!(another_arena.get(foo).map(|node| *node.get()), Some("Another arena")); assert!(another_arena.get(bar).is_none());
pub fn get_mut(&mut self, id: NodeId) -> Option<&mut Node<T>>[src]
Returns a mutable reference to the node with the given id if in the arena.
Returns None if not available.
Examples
let mut arena = Arena::new(); let foo = arena.new_node("foo"); assert_eq!(arena.get(foo).map(|node| *node.get()), Some("foo")); *arena.get_mut(foo).expect("The `foo` node exists").get_mut() = "FOO!"; assert_eq!(arena.get(foo).map(|node| *node.get()), Some("FOO!"));
pub fn get2_mut(
&mut self,
i1: NodeId,
i2: NodeId
) -> (Option<&mut Node<T>>, Option<&mut Node<T>>)[src]
&mut self,
i1: NodeId,
i2: NodeId
) -> (Option<&mut Node<T>>, Option<&mut Node<T>>)
Get a pair of exclusive references to the elements at index i1 and i2 if it is in the
arena.
If the element at index i1 or i2 is not in the arena, then None is returned for this
element.
Panics
Panics if i1 and i2 are pointing to the same item of the arena.
Examples
use generational_indextree::Arena; let mut arena = Arena::new(); let idx1 = arena.new_node("foo"); let idx2 = arena.new_node("bar"); { let (item1, item2) = arena.get2_mut(idx1, idx2); *item1.unwrap().get_mut() = "jig"; *item2.unwrap().get_mut() = "saw"; } assert_eq!(arena[idx1].get(), &"jig"); assert_eq!(arena[idx2].get(), &"saw");
pub fn iter(&self) -> impl Iterator<Item = &Node<T>>[src]
Returns an iterator of all nodes in the arena in storage-order.
Examples
let mut arena = Arena::new(); let _foo = arena.new_node("foo"); let _bar = arena.new_node("bar"); let mut iter = arena.iter(); assert_eq!(iter.next().map(|node| *node.get()), Some("foo")); assert_eq!(iter.next().map(|node| *node.get()), Some("bar")); assert_eq!(iter.next().map(|node| *node.get()), None);
let mut arena = Arena::new(); let _foo = arena.new_node("foo"); let bar = arena.new_node("bar"); bar.remove(&mut arena); let mut iter = arena.iter(); assert_eq!(iter.next().map(|node| *node.get()), Some("foo")); assert_eq!(iter.next().map(|node| *node.get()), None);
Trait Implementations
impl<T: Clone> Clone for Arena<T>[src]
impl<T: Debug> Debug for Arena<T>[src]
impl<T> Default for Arena<T>[src]
impl<T: PartialEq> Eq for Arena<T>[src]
impl<T> Index<NodeId> for Arena<T>[src]
type Output = Node<T>
The returned type after indexing.
fn index(&self, node: NodeId) -> &Node<T>[src]
impl<T> IndexMut<NodeId> for Arena<T>[src]
impl<T: PartialEq> PartialEq<Arena<T>> for Arena<T>[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Arena<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Arena<T> where
T: Send,
T: Send,
impl<T> Sync for Arena<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Arena<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Arena<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>,