diff --git a/gemla/src/bracket/mod.rs b/gemla/src/bracket/mod.rs index 275e835..857cf17 100644 --- a/gemla/src/bracket/mod.rs +++ b/gemla/src/bracket/mod.rs @@ -1,11 +1,13 @@ mod tree; mod state; +use uuid::Uuid; + fn build_tree(h: u32) -> Option> { let mut result: Option> = None; if h != 0 { - result = Some(tree::concat_trees(state::create(), build_tree(h - 1), build_tree(h - 1))); + result = Some(tree::concat_trees(Uuid::new_v4(), build_tree(h - 1), build_tree(h - 1))); match &result { Some(r) => (*r).run_simulation(), _ => () @@ -23,7 +25,7 @@ pub fn run_bracket() { println!("========================================="); println!("Running bracket..."); height += 1; - tree = *tree::concat_trees(state::create(), Some(Box::new(tree)), build_tree(height)); + tree = *tree::concat_trees(Uuid::new_v4(), Some(Box::new(tree)), build_tree(height)); tree.run_simulation(); } } \ No newline at end of file diff --git a/gemla/src/bracket/state.rs b/gemla/src/bracket/state.rs index 6ccf5e9..b1e2820 100644 --- a/gemla/src/bracket/state.rs +++ b/gemla/src/bracket/state.rs @@ -11,8 +11,8 @@ impl fmt::Display for State { } } -pub fn create() -> State { +pub fn create(id: &Uuid) -> State { State { - id: Uuid::new_v4() + id: id.clone() } } \ No newline at end of file diff --git a/gemla/src/bracket/tree.rs b/gemla/src/bracket/tree.rs index a4bfe58..a9fea8f 100644 --- a/gemla/src/bracket/tree.rs +++ b/gemla/src/bracket/tree.rs @@ -1,15 +1,15 @@ use std::fmt; -use super::state; +use uuid::Uuid; pub struct Tree { - state: state::State, + id: Uuid, left: Option>, right: Option> } -pub fn concat_trees(s: state::State, l: Option>, r: Option>) -> Box { +pub fn concat_trees(id: Uuid, l: Option>, r: Option>) -> Box { Box::new(Tree { - state: s, + id: id, left: l, right: r }) @@ -24,13 +24,13 @@ impl fmt::Display for Tree { } }; - write!(f, "({} :{}|{})", self.state, node_str(&self.left), node_str(&self.right)) + write!(f, "({} :{}|{})", self.id, node_str(&self.left), node_str(&self.right)) } } fn fmt_node(t: &Option>) -> String { match t { - Some(n) => format!("{}", (*n).state), + Some(n) => format!("{}", (*n).id), _ => String::from("_") } } @@ -38,7 +38,7 @@ fn fmt_node(t: &Option>) -> String { impl Tree { pub fn run_simulation(&self) { println!("================================"); - println!("Running simulation for node: {}", self.state); + println!("Running simulation for node: {}", self.id); println!("With children {} and {}", fmt_node(&self.left), fmt_node(&self.right)); } } \ No newline at end of file