From 06205014d2b8d3567759809e829e84ce195e7685 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Thu, 22 Sep 2022 11:48:00 +0200 Subject: [PATCH] [graph] Add insert_node() to Graph #235 (#236) * Update graph.rs * Update graph.rs --- src/graph.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/graph.rs b/src/graph.rs index d48da2175..e66572191 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -2,15 +2,45 @@ mod graph_edge; mod graph_element; mod graph_node; +pub(crate) struct Graph { + from: Vec, + to: Vec, + from_meta: Vec, + to_meta: Vec, + node_count: u64, +} + #[allow(dead_code)] -pub(crate) struct Graph {} +impl Graph { + pub(crate) fn new() -> Graph { + Graph { + from: vec![0], + to: vec![0], + from_meta: vec![0], + to_meta: vec![0], + node_count: 0, + } + } + + pub(crate) fn insert_node(&mut self) -> i64 { + self.from.push(0); + self.to.push(0); + self.from_meta.push(0); + self.to_meta.push(0); + self.node_count += 1; + self.node_count as i64 + } +} #[cfg(test)] mod tests { use super::*; #[test] - fn new() { - let _graph = Graph {}; + fn insert_node() { + let mut graph = Graph::new(); + let id = graph.insert_node(); + + assert_eq!(id, 1); } }