Skip to content

Commit 5c6e91b

Browse files
committed
trivial changes in checking and loops; tag 0.0.8
1 parent 73d3b80 commit 5c6e91b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[package]
33
name = "im_ternary_tree"
4-
version = "0.0.7"
4+
version = "0.0.8"
55
edition = "2021"
66
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
77
license = "MIT"

src/lib.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,11 @@ where
244244
Empty => TernaryTreeList::Empty,
245245
Tree(t) => {
246246
if t.len() == 1 {
247-
TernaryTreeList::Empty
247+
Self::Empty
248248
} else {
249-
// TernaryTreeList::Tree(t.drop_left())
250249
match t.split_left_some(1).1 {
251-
Some(v) => TernaryTreeList::Tree(v),
252-
None => unreachable!("got not body"),
250+
Some(v) => Self::Tree(v),
251+
None => Self::Empty,
253252
}
254253
}
255254
}
@@ -259,14 +258,14 @@ where
259258
/// optimized for amortized `O(1)` at best cases
260259
pub fn drop_right(&self) -> Self {
261260
match self {
262-
Empty => TernaryTreeList::Empty,
261+
Empty => Self::Empty,
263262
Tree(t) => {
264263
if t.len() == 1 {
265-
TernaryTreeList::Empty
264+
Self::Empty
266265
} else {
267266
match t.split_right_some(1).0 {
268-
Some(v) => TernaryTreeList::Tree(v),
269-
None => unreachable!("got not body"),
267+
Some(v) => Self::Tree(v),
268+
None => Self::Empty,
270269
}
271270
}
272271
}
@@ -386,7 +385,7 @@ where
386385
fn next(&mut self) -> Option<Self::Item> {
387386
if self.index < self.value.len() {
388387
// println!("get: {} {}", self.value.format_inline(), self.index);
389-
let ret = self.value.ref_get(self.index);
388+
let ret = self.value.loop_get(self.index);
390389
self.index += 1;
391390
ret
392391
} else {
@@ -437,9 +436,13 @@ where
437436
type Output = T;
438437

439438
fn index<'b>(&self, idx: usize) -> &Self::Output {
440-
match self {
441-
Empty => panic!("index out of bounds"),
442-
Tree(t) => t.ref_get(idx),
439+
if idx >= self.len() {
440+
panic!("{} is out of bound at length {}", idx, self.len())
441+
} else {
442+
match self {
443+
Empty => panic!("list is empty to index"),
444+
Tree(t) => t.loop_get(idx),
445+
}
443446
}
444447
}
445448
}
@@ -449,7 +452,6 @@ where
449452
T: Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash,
450453
{
451454
fn hash<H: Hasher>(&self, state: &mut H) {
452-
"ternary".hash(state);
453455
match self {
454456
Empty => {}
455457
Tree(t) => t.hash(state),

0 commit comments

Comments
 (0)