aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2023-12-27 08:45:36 -0800
committerRose Hogenson <rosehogenson@posteo.net>2023-12-27 08:45:36 -0800
commitb0aaa173bdd2137d7cdd7aa55f5aa7d7222b4c03 (patch)
treeadbeb1c8b9f0143939be133d7a8282b05bfd2172
parent82913ff77a7fc8a4489128cc61b23c1b18b31690 (diff)
downloadeditor-b0aaa173bdd2137d7cdd7aa55f5aa7d7222b4c03.tar.zst
Remove unnecessary length field.
-rw-r--r--src/rope.rs20
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,
})));