Skip to content

Commit

Permalink
[graph] Add insert_node() to Graph #235 (#236)
Browse files Browse the repository at this point in the history
* Update graph.rs

* Update graph.rs
  • Loading branch information
michaelvlach authored Sep 22, 2022
1 parent f47f709 commit 0620501
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,45 @@ mod graph_edge;
mod graph_element;
mod graph_node;

pub(crate) struct Graph {
from: Vec<i64>,
to: Vec<i64>,
from_meta: Vec<i64>,
to_meta: Vec<i64>,
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);
}
}

0 comments on commit 0620501

Please sign in to comment.