pub struct DirectedLabelGraph<D> { /* private fields */ }Expand description
Holds the nodes of the graph
Implementations§
Source§impl<D> DirectedLabelGraph<D>
impl<D> DirectedLabelGraph<D>
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/make_graph.rs (line 7)
6fn main() {
7 let mut g = DirectedLabelGraph::new();
8
9 let n1 = NodeData(2);
10 let n2 = NodeData(3);
11 let n3 = NodeData(4);
12
13 g.create_node("n1", n1);
14 g.create_node("n2", n2);
15 g.create_node("n3", n3);
16
17 println!("linking: n1 -> n2\n");
18 g.link_nodes("n1", "n2", 1);
19
20 println!(
21 "n1's data before being modified: {:?}",
22 g.get_node_data("n1")
23 );
24 {
25 // modify n1's data
26 let n1_data = g.get_mut_node_data("n1").unwrap();
27 n1_data.0 = 100;
28 }
29 println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31 println!("Iter through node label and data:");
32 for nd in g.iter_node_label_and_data() {
33 println!("node data -> {:?}", nd)
34 }
35 println!();
36
37 println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38 println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}pub fn check_node_exists(&self, node_label: &str) -> bool
Sourcepub fn create_node(&mut self, node_label: &str, node_data: D)
pub fn create_node(&mut self, node_label: &str, node_data: D)
Examples found in repository?
examples/make_graph.rs (line 13)
6fn main() {
7 let mut g = DirectedLabelGraph::new();
8
9 let n1 = NodeData(2);
10 let n2 = NodeData(3);
11 let n3 = NodeData(4);
12
13 g.create_node("n1", n1);
14 g.create_node("n2", n2);
15 g.create_node("n3", n3);
16
17 println!("linking: n1 -> n2\n");
18 g.link_nodes("n1", "n2", 1);
19
20 println!(
21 "n1's data before being modified: {:?}",
22 g.get_node_data("n1")
23 );
24 {
25 // modify n1's data
26 let n1_data = g.get_mut_node_data("n1").unwrap();
27 n1_data.0 = 100;
28 }
29 println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31 println!("Iter through node label and data:");
32 for nd in g.iter_node_label_and_data() {
33 println!("node data -> {:?}", nd)
34 }
35 println!();
36
37 println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38 println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}Sourcepub fn get_node_data(&self, node_label: &str) -> Option<&D>
pub fn get_node_data(&self, node_label: &str) -> Option<&D>
Examples found in repository?
examples/make_graph.rs (line 22)
6fn main() {
7 let mut g = DirectedLabelGraph::new();
8
9 let n1 = NodeData(2);
10 let n2 = NodeData(3);
11 let n3 = NodeData(4);
12
13 g.create_node("n1", n1);
14 g.create_node("n2", n2);
15 g.create_node("n3", n3);
16
17 println!("linking: n1 -> n2\n");
18 g.link_nodes("n1", "n2", 1);
19
20 println!(
21 "n1's data before being modified: {:?}",
22 g.get_node_data("n1")
23 );
24 {
25 // modify n1's data
26 let n1_data = g.get_mut_node_data("n1").unwrap();
27 n1_data.0 = 100;
28 }
29 println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31 println!("Iter through node label and data:");
32 for nd in g.iter_node_label_and_data() {
33 println!("node data -> {:?}", nd)
34 }
35 println!();
36
37 println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38 println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}Sourcepub fn get_mut_node_data(&mut self, node_label: &str) -> Option<&mut D>
pub fn get_mut_node_data(&mut self, node_label: &str) -> Option<&mut D>
Examples found in repository?
examples/make_graph.rs (line 26)
6fn main() {
7 let mut g = DirectedLabelGraph::new();
8
9 let n1 = NodeData(2);
10 let n2 = NodeData(3);
11 let n3 = NodeData(4);
12
13 g.create_node("n1", n1);
14 g.create_node("n2", n2);
15 g.create_node("n3", n3);
16
17 println!("linking: n1 -> n2\n");
18 g.link_nodes("n1", "n2", 1);
19
20 println!(
21 "n1's data before being modified: {:?}",
22 g.get_node_data("n1")
23 );
24 {
25 // modify n1's data
26 let n1_data = g.get_mut_node_data("n1").unwrap();
27 n1_data.0 = 100;
28 }
29 println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31 println!("Iter through node label and data:");
32 for nd in g.iter_node_label_and_data() {
33 println!("node data -> {:?}", nd)
34 }
35 println!();
36
37 println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38 println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}Sourcepub fn link_nodes(
&mut self,
from_node_label: &str,
to_node_label: &str,
weight: i64,
)
pub fn link_nodes( &mut self, from_node_label: &str, to_node_label: &str, weight: i64, )
Examples found in repository?
examples/make_graph.rs (line 18)
6fn main() {
7 let mut g = DirectedLabelGraph::new();
8
9 let n1 = NodeData(2);
10 let n2 = NodeData(3);
11 let n3 = NodeData(4);
12
13 g.create_node("n1", n1);
14 g.create_node("n2", n2);
15 g.create_node("n3", n3);
16
17 println!("linking: n1 -> n2\n");
18 g.link_nodes("n1", "n2", 1);
19
20 println!(
21 "n1's data before being modified: {:?}",
22 g.get_node_data("n1")
23 );
24 {
25 // modify n1's data
26 let n1_data = g.get_mut_node_data("n1").unwrap();
27 n1_data.0 = 100;
28 }
29 println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31 println!("Iter through node label and data:");
32 for nd in g.iter_node_label_and_data() {
33 println!("node data -> {:?}", nd)
34 }
35 println!();
36
37 println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38 println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}Sourcepub fn get_inputs_for_node(
&self,
node_label: &str,
) -> Option<Vec<&LabelGraphEdge>>
pub fn get_inputs_for_node( &self, node_label: &str, ) -> Option<Vec<&LabelGraphEdge>>
Examples found in repository?
examples/make_graph.rs (line 38)
6fn main() {
7 let mut g = DirectedLabelGraph::new();
8
9 let n1 = NodeData(2);
10 let n2 = NodeData(3);
11 let n3 = NodeData(4);
12
13 g.create_node("n1", n1);
14 g.create_node("n2", n2);
15 g.create_node("n3", n3);
16
17 println!("linking: n1 -> n2\n");
18 g.link_nodes("n1", "n2", 1);
19
20 println!(
21 "n1's data before being modified: {:?}",
22 g.get_node_data("n1")
23 );
24 {
25 // modify n1's data
26 let n1_data = g.get_mut_node_data("n1").unwrap();
27 n1_data.0 = 100;
28 }
29 println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31 println!("Iter through node label and data:");
32 for nd in g.iter_node_label_and_data() {
33 println!("node data -> {:?}", nd)
34 }
35 println!();
36
37 println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38 println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}Sourcepub fn get_outputs_for_node(
&self,
node_label: &str,
) -> Option<Vec<&LabelGraphEdge>>
pub fn get_outputs_for_node( &self, node_label: &str, ) -> Option<Vec<&LabelGraphEdge>>
Examples found in repository?
examples/make_graph.rs (line 37)
6fn main() {
7 let mut g = DirectedLabelGraph::new();
8
9 let n1 = NodeData(2);
10 let n2 = NodeData(3);
11 let n3 = NodeData(4);
12
13 g.create_node("n1", n1);
14 g.create_node("n2", n2);
15 g.create_node("n3", n3);
16
17 println!("linking: n1 -> n2\n");
18 g.link_nodes("n1", "n2", 1);
19
20 println!(
21 "n1's data before being modified: {:?}",
22 g.get_node_data("n1")
23 );
24 {
25 // modify n1's data
26 let n1_data = g.get_mut_node_data("n1").unwrap();
27 n1_data.0 = 100;
28 }
29 println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31 println!("Iter through node label and data:");
32 for nd in g.iter_node_label_and_data() {
33 println!("node data -> {:?}", nd)
34 }
35 println!();
36
37 println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38 println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}pub fn iter_node_data(&self) -> impl Iterator<Item = &D>
Sourcepub fn iter_node_label_and_data(&self) -> impl Iterator<Item = (&String, &D)>
pub fn iter_node_label_and_data(&self) -> impl Iterator<Item = (&String, &D)>
Examples found in repository?
examples/make_graph.rs (line 32)
6fn main() {
7 let mut g = DirectedLabelGraph::new();
8
9 let n1 = NodeData(2);
10 let n2 = NodeData(3);
11 let n3 = NodeData(4);
12
13 g.create_node("n1", n1);
14 g.create_node("n2", n2);
15 g.create_node("n3", n3);
16
17 println!("linking: n1 -> n2\n");
18 g.link_nodes("n1", "n2", 1);
19
20 println!(
21 "n1's data before being modified: {:?}",
22 g.get_node_data("n1")
23 );
24 {
25 // modify n1's data
26 let n1_data = g.get_mut_node_data("n1").unwrap();
27 n1_data.0 = 100;
28 }
29 println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31 println!("Iter through node label and data:");
32 for nd in g.iter_node_label_and_data() {
33 println!("node data -> {:?}", nd)
34 }
35 println!();
36
37 println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38 println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}Trait Implementations§
Source§impl<D: Debug> Debug for DirectedLabelGraph<D>
impl<D: Debug> Debug for DirectedLabelGraph<D>
Auto Trait Implementations§
impl<D> Freeze for DirectedLabelGraph<D>
impl<D> RefUnwindSafe for DirectedLabelGraph<D>where
D: RefUnwindSafe,
impl<D> Send for DirectedLabelGraph<D>where
D: Send,
impl<D> Sync for DirectedLabelGraph<D>where
D: Sync,
impl<D> Unpin for DirectedLabelGraph<D>
impl<D> UnwindSafe for DirectedLabelGraph<D>where
D: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more