From 9eff579ec0ec5644106febe19bc14e0d076d7a24 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 31 Oct 2014 23:39:57 -0400 Subject: [PATCH] Remove ToString debugging --- src/lib.rs | 56 +++++++++++++++++------------------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1e508c8..ed5ae99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,13 +3,12 @@ use std::cmp::Ord; use std::option::{None, Option, Some}; -use std::to_string::ToString; /// Four -struct Four(V, V, V, Option<(Box>, Box>, Box>, Box>)>); +struct Four(V, V, V, Option<(Box>, Box>, Box>, Box>)>); -impl Four { +impl Four { /// Convert a Split into a TwoNode with the middle value as the value of the new parent node fn to_two(self) -> Two { @@ -28,7 +27,7 @@ impl Four { /// InsertResult -enum InsertResult { +enum InsertResult { Fit(Node), // box this node? Split(Four), // split should always contain a ThreeNode/LeafThreeNode. box this? } @@ -44,9 +43,9 @@ enum Direction { /// Two -pub struct Two(pub V, pub Box>, pub Box>); +pub struct Two(pub V, pub Box>, pub Box>); -impl Two { +impl Two { fn to_node(self) -> Node { TwoNode(self) } fn to_three(self, other_value: V, other_node: Box>) -> Three { @@ -61,9 +60,9 @@ impl Two { /// Three -pub struct Three(pub V, pub V, pub Box>, pub Box>, pub Box>); +pub struct Three(pub V, pub V, pub Box>, pub Box>, pub Box>); -impl Three { +impl Three { fn to_node(self) -> Node { ThreeNode(self) } fn to_four(self, other_value: V, other_node: Box>) -> Four { @@ -78,13 +77,13 @@ impl Three { /// LeafTwo -pub struct LeafTwo(pub V); +pub struct LeafTwo(pub V); /// LeafThree -pub struct LeafThree(pub V, pub V); +pub struct LeafThree(pub V, pub V); -impl LeafThree { +impl LeafThree { fn to_four(self, value: V) -> Four { let LeafThree(value1, value2) = self; if value > value2 { Four(value1, value2, value, None) } @@ -95,27 +94,16 @@ impl LeafThree { /// Node -pub enum Node { +pub enum Node { LeafTwoNode(LeafTwo), LeafThreeNode(LeafThree), TwoNode(Two), ThreeNode(Three), } -impl ToString for Node { - fn to_string(&self) -> String { - match *self { - LeafTwoNode(LeafTwo(ref v)) => format!("LeafTwoNode({:s})", v.to_string()), - LeafThreeNode(LeafThree(ref v1, ref v2)) => format!("LeafThreeNode({:s}, {:s})", v1.to_string(), v2.to_string()), - TwoNode(Two(ref v, ref left, ref middle)) => format!("TwoNode({:s}, {:s}, {:s})", v.to_string(), left.to_string(), middle.to_string()), - ThreeNode(Three(_, _, ref left, ref middle, ref right)) => format!("ThreeNode({:s}, {:s}, {:s})", left.to_string(), middle.to_string(), right.to_string()), - } - } -} - -impl Node { +impl Node { // PRIVATE fn next_direction(&self, to_insert: &V) -> Direction { @@ -182,10 +170,10 @@ impl Node { let new_node = match insert_result { Fit(returned_node) => match next_direction { - Left => Two(value, box returned_node, box other_node).to_node(), - Middle => Two(value, box other_node, box returned_node).to_node(), + Left => Two(value, box returned_node, box other_node), + Middle => Two(value, box other_node, box returned_node), _ => fail!(""), - }, + }.to_node(), Split(four_node) => four_node.to_two().to_three(value, box other_node).to_node(), }; @@ -233,20 +221,11 @@ impl Node { /// TTTree -pub struct TTTree { +pub struct TTTree { pub root: Option>, } -impl ToString for TTTree { - fn to_string(&self) -> String { - match self.root { - Some(ref node) => node.to_string(), - None => "TTTree()".to_string(), - } - } -} - -impl TTTree { +impl TTTree { pub fn new() -> TTTree { TTTree { root: None } } @@ -271,4 +250,3 @@ impl TTTree { // TODO: // Collection trait // convert this to Key/Value K/V -// remove ToString debugging stuffs -- 2.51.2