File tree Expand file tree Collapse file tree 3 files changed +9
-9
lines changed Expand file tree Collapse file tree 3 files changed +9
-9
lines changed Original file line number Diff line number Diff line change 1
1
2
2
[package ]
3
3
name = " im_ternary_tree"
4
- version = " 0.0.14 "
4
+ version = " 0.0.15 "
5
5
edition = " 2021"
6
6
authors = [" jiyinyiyong <jiyinyiyong@gmail.com>" ]
7
7
license = " MIT"
Original file line number Diff line number Diff line change @@ -548,7 +548,7 @@ where
548
548
} else {
549
549
match self {
550
550
Empty => panic ! ( "list is empty to index" ) ,
551
- Tree ( t) => t. ref_get ( idx) ,
551
+ Tree ( t) => t. loop_get ( idx) ,
552
552
}
553
553
}
554
554
}
Original file line number Diff line number Diff line change @@ -292,34 +292,34 @@ where
292
292
/// get am element via drilling down the branch with a mutable loop,
293
293
/// supposed to be faster than `ref_get` since it's more like VM instructions
294
294
pub fn loop_get ( & ' a self , original_idx : usize ) -> & ' a T {
295
- let tree_parent = Cell :: new ( self ) ;
295
+ let mut tree_parent = self ;
296
296
let mut idx = original_idx;
297
297
loop {
298
- match tree_parent. get ( ) {
298
+ match tree_parent {
299
299
Leaf ( value) => {
300
300
return value;
301
301
}
302
302
Branch2 { left, middle, .. } => {
303
303
if idx < left. len ( ) {
304
- tree_parent. set ( left) ;
304
+ tree_parent = left;
305
305
} else {
306
- tree_parent. set ( middle) ;
306
+ tree_parent = middle;
307
307
idx -= left. len ( ) ;
308
308
}
309
309
}
310
310
Branch3 { left, middle, right, .. } => {
311
311
if idx < left. len ( ) {
312
- tree_parent. set ( left) ;
312
+ tree_parent = left;
313
313
continue ;
314
314
}
315
315
idx -= left. len ( ) ;
316
316
317
317
if idx < middle. len ( ) {
318
- tree_parent. set ( middle) ;
318
+ tree_parent = middle;
319
319
continue ;
320
320
}
321
321
322
- tree_parent. set ( right) ;
322
+ tree_parent = right;
323
323
idx -= middle. len ( ) ;
324
324
}
325
325
}
You can’t perform that action at this time.
0 commit comments