diff options
| -rw-r--r-- | src/rope.rs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/rope.rs b/src/rope.rs index f26457c..320cd14 100644 --- a/src/rope.rs +++ b/src/rope.rs @@ -8,7 +8,6 @@ use std::rc::Rc; const MAX_NODE_SIZE: usize = 4; struct Branch { - len: usize, left: Rc<Node>, right: Rc<Node>, } @@ -19,13 +18,6 @@ enum Node { } impl Node { - fn len(&self) -> usize { - return match self { - Node::Leaf(v) => v.len(), - Node::Branch(b) => b.len, - }; - } - fn write(&self, out: &mut Vec<u8>) { match self { Node::Leaf(v) => { @@ -37,6 +29,13 @@ impl Node { } } } + + fn empty(&self) -> bool { + return match self { + Node::Leaf(v) => v.len() == 0, + _ => false, + }; + } } impl Display for Node { @@ -52,14 +51,13 @@ pub struct Rope(Rc<Node>); impl Rope { fn concat(self, Rope(other): Rope) -> Rope { let Rope(me) = self; - if me.len() == 0 { + if me.empty() { return Rope(other); } - if other.len() == 0 { + if other.empty() { return Rope(me); } return Rope(Rc::new(Node::Branch(Branch { - len: me.len() + other.len(), left: me, right: other, }))); |
