From 29a6ec6725541832e0145b21d8fb21c1e3c5ca6f Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Thu, 16 Nov 2017 15:43:45 +0100 Subject: [PATCH] Cleanup, more descriptive names --- src/merge.rs | 55 +++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/src/merge.rs b/src/merge.rs index 78f5067..371bca9 100644 --- a/src/merge.rs +++ b/src/merge.rs @@ -38,9 +38,8 @@ struct MergeIterator { left: Vec>, right: Vec>, - a: usize, - o: usize, - b: usize, + li: usize, + ri: usize, } impl MergeIterator { @@ -48,9 +47,8 @@ impl MergeIterator { MergeIterator { left, right, - a: 0, - o: 0, - b: 0, + li: 0, + ri: 0, } } } @@ -63,50 +61,45 @@ where fn next(&mut self) -> Option { let mut i = 0; - while let (Some(&Both(..)), Some(&Both(..))) = (self.left.get(self.a+i), self.right.get(self.b+i)) { + while let (Some(&Both(..)), Some(&Both(..))) = (self.left.get(self.li+i), self.right.get(self.ri+i)) { i += 1; } if i > 0 { - let chunk = ChunkItem::stable(Chunk(self.a..self.a+i, self.b..self.b+i)); - self.a += i; - self.o += i; - self.b += i; + let chunk = ChunkItem::stable(Chunk(self.li..self.li+i, self.ri..self.ri+i)); + self.li += i; + self.ri += i; return Some(chunk); } - let mut a = self.a; - let mut o = self.o; - let mut b = self.b; + let mut li = self.li; + let mut ri = self.ri; loop { - match (self.left.get(a), self.right.get(b)) { + match (self.left.get(li), self.right.get(ri)) { (Some(&Right(_)), _) => { - a += 1; + li += 1; }, (_, Some(&Right(_))) => { - b += 1; + ri += 1; }, (Some(&Left(_)), Some(_)) => { - a += 1; - o += 1; - b += 1; + li += 1; + ri += 1; }, (Some(_), Some(&Left(_))) => { - a += 1; - o += 1; - b += 1; + li += 1; + ri += 1; }, (Some(&Both(..)), Some(&Both(..))) => { - let chunk = ChunkItem::unstable(Chunk(self.a..a, self.b..b)); - self.a = a; - self.o = o; - self.b = b; + let chunk = ChunkItem::unstable(Chunk(self.li..li, self.ri..ri)); + self.li = li; + self.ri = ri; return Some(chunk); } _ => { - if self.a < self.left.len() || self.b < self.right.len() { - let chunk = ChunkItem::unstable(Chunk(self.a..self.left.len(), self.b..self.right.len())); - self.a = self.left.len(); - self.b = self.right.len(); + if self.li < self.left.len() || self.ri < self.right.len() { + let chunk = ChunkItem::unstable(Chunk(self.li..self.left.len(), self.ri..self.right.len())); + self.li = self.left.len(); + self.ri = self.right.len(); return Some(chunk); } return None;