Struct bag::GraphStore
[−]
[src]
pub struct GraphStore<T> { /* fields omitted */ }
A generic container for a graph
A GraphStore<T>
is a struct that contains the actual graph representation.
Try not to loose it.
Example
use bag::{GraphStore, Node}; let root_node = Node::new("String".to_string()); let (mut graph, root_node_id) = GraphStore::new(root_node); assert_eq!(*graph.get(root_node_id).unwrap().parent(), None);
Methods
impl<T> GraphStore<T>
[src]
pub fn new(root_node: Node<T>) -> (Self, NodeID)
[src]
Constructs a new GraphStore<T>
and handle to the root Node<T>
Accepts a root node of type Node<T>
(this is the only node held in the graph that can have a None
for it's parent (though it may have a Some(parent)
if the graph is cyclic at the root.
pub fn get(&self, node: NodeID) -> Option<&Node<T>>
[src]
Returns an option with a reference to the node represented by NodeID
, if found
get
searches the GraphStore<T>
for a node with the NodeID
passed as node
.
If it is found, a non-mutable reference to it is returned in a Some
, otherwise a None
is returned.
pub fn get_mut(&mut self, node: NodeID) -> Option<&mut Node<T>>
[src]
Returns an option with a mutable reference to the node represented by NodeID
, if found
get_mut
searches the GraphStore<T>
for a node with the NodeID
passed as node
.
If it is found, a mutable reference to it is returned in a Some
, otherwise a None
is returned.
pub fn get_siblings_id(&self, node: NodeID) -> Option<&Vec<NodeID>>
[src]
Returns an option with a reference to a Vec of a Node<T>
s sublings, if found
get_siblings_id
searches the GraphStore<T>
for a node with the NodeID
passed as node
.
If it is found, a non-mutable reference to it's parent's children is returned in a Some
, otherwise a None
is returned.
Note that node
is itself included in the returned Vec<NodeID>
.
pub fn insert_child(
&mut self,
parent_id: &NodeID,
inserted: Node<T>
) -> Result<NodeID, &'static str>
[src]
&mut self,
parent_id: &NodeID,
inserted: Node<T>
) -> Result<NodeID, &'static str>
Inserts a node into the graph
insert_child
accepts a parent NodeID
and takes ownership of an inserted Node<T>
.
If the parent NodeID
is valid, the Node<T>
is inserted into the graph. The child's parent
pointer is then set to the NodeID
of the parent, and the parent's child Vec<NodeID
is updated
to include the NodeID
of the child. Returns a Result<NodeID, &'static str
representing success or failure
of the insertion.
Trait Implementations
impl<T: Debug> Debug for GraphStore<T>
[src]
Auto Trait Implementations
impl<T> Send for GraphStore<T> where
T: Send,
T: Send,
impl<T> Sync for GraphStore<T> where
T: Sync,
T: Sync,