@@ -244,12 +244,11 @@ where
244
244
Empty => TernaryTreeList :: Empty ,
245
245
Tree ( t) => {
246
246
if t. len ( ) == 1 {
247
- TernaryTreeList :: Empty
247
+ Self :: Empty
248
248
} else {
249
- // TernaryTreeList::Tree(t.drop_left())
250
249
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 ,
253
252
}
254
253
}
255
254
}
@@ -259,14 +258,14 @@ where
259
258
/// optimized for amortized `O(1)` at best cases
260
259
pub fn drop_right ( & self ) -> Self {
261
260
match self {
262
- Empty => TernaryTreeList :: Empty ,
261
+ Empty => Self :: Empty ,
263
262
Tree ( t) => {
264
263
if t. len ( ) == 1 {
265
- TernaryTreeList :: Empty
264
+ Self :: Empty
266
265
} else {
267
266
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 ,
270
269
}
271
270
}
272
271
}
@@ -386,7 +385,7 @@ where
386
385
fn next ( & mut self ) -> Option < Self :: Item > {
387
386
if self . index < self . value . len ( ) {
388
387
// 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 ) ;
390
389
self . index += 1 ;
391
390
ret
392
391
} else {
@@ -437,9 +436,13 @@ where
437
436
type Output = T ;
438
437
439
438
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
+ }
443
446
}
444
447
}
445
448
}
@@ -449,7 +452,6 @@ where
449
452
T : Clone + Display + Eq + PartialEq + Debug + Ord + PartialOrd + Hash ,
450
453
{
451
454
fn hash < H : Hasher > ( & self , state : & mut H ) {
452
- "ternary" . hash ( state) ;
453
455
match self {
454
456
Empty => { }
455
457
Tree ( t) => t. hash ( state) ,
0 commit comments