[−][src]Struct indextree::Arena
An Arena
structure containing certain Node
s.
Implementations
impl<T> Arena<T>
[src]
pub fn new() -> Arena<T>
[src]
Creates a new empty Arena
.
pub fn get_node_id(&self, node: &Node<T>) -> Option<NodeId> where
T: PartialEq,
[src]
T: PartialEq,
Retrieves the NodeId
correspoding to a Node
in the Arena
.
Note that this method can only be used if the datatype of the Node
implements
the PartialEq
trait.
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(), 2);
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 iter(&self) -> impl Iterator<Item = &Node<T>>
[src]
Returns an iterator of all nodes in the arena in storage-order.
Note that this iterator returns also removed elements, which can be
tested with the is_removed()
method on the node.
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(), node.is_removed())), Some(("foo", false))); assert_eq!(iter.next().map(|node| (*node.get(), node.is_removed())), Some(("bar", true))); assert_eq!(iter.next().map(|node| (*node.get(), node.is_removed())), 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: Eq> 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]
impl<T> StructuralEq for Arena<T>
[src]
impl<T> StructuralPartialEq 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>,