File tree Expand file tree Collapse file tree 4 files changed +30
-20
lines changed
0-core/_fast/fast-iterators Expand file tree Collapse file tree 4 files changed +30
-20
lines changed Original file line number Diff line number Diff line change @@ -29,14 +29,7 @@ BackwardIterator.prototype._upwardStep = function () {
29
29
} ;
30
30
31
31
BackwardIterator . prototype . _traverse = function ( level , x ) {
32
- if ( x instanceof Node3 ) {
33
- this . _level . push ( level , level ) ;
34
- this . _stack . push ( x . a , x . b ) ;
35
- return x . c ;
36
- }
37
-
38
- assert ( x instanceof Node2 ) ;
39
- this . _level . push ( level ) ;
40
- this . _stack . push ( x . a ) ;
41
- return x . b ;
32
+ assert ( Number . isInteger ( level ) && level >= 0 ) ;
33
+ assert ( x instanceof Node2 || x instanceof Node3 ) ;
34
+ return x . _backward ( level , this ) ;
42
35
} ;
Original file line number Diff line number Diff line change @@ -29,14 +29,7 @@ ForwardIterator.prototype._upwardStep = function () {
29
29
} ;
30
30
31
31
ForwardIterator . prototype . _traverse = function ( level , x ) {
32
- if ( x instanceof Node3 ) {
33
- this . _level . push ( level , level ) ;
34
- this . _stack . push ( x . c , x . b ) ;
35
- return x . a ;
36
- }
37
-
38
- assert ( x instanceof Node2 ) ;
39
- this . _level . push ( level ) ;
40
- this . _stack . push ( x . b ) ;
41
- return x . a ;
32
+ assert ( Number . isInteger ( level ) && level >= 0 ) ;
33
+ assert ( x instanceof Node2 || x instanceof Node3 ) ;
34
+ return x . _forward ( level , this ) ;
42
35
} ;
Original file line number Diff line number Diff line change @@ -13,3 +13,15 @@ Node2.prototype.measure = function () {
13
13
Node2 . prototype . _digit = function ( ) {
14
14
return new Two ( this . a , this . b ) ;
15
15
} ;
16
+
17
+ Node2 . prototype . _forward = function ( level , iterator ) {
18
+ iterator . _level . push ( level ) ;
19
+ iterator . _stack . push ( this . b ) ;
20
+ return this . a ;
21
+ } ;
22
+
23
+ Node2 . prototype . _backward = function ( level , iterator ) {
24
+ iterator . _level . push ( level ) ;
25
+ iterator . _stack . push ( this . a ) ;
26
+ return this . b ;
27
+ } ;
Original file line number Diff line number Diff line change @@ -14,3 +14,15 @@ Node3.prototype.measure = function () {
14
14
Node3 . prototype . _digit = function ( ) {
15
15
return new Three ( this . a , this . b , this . c ) ;
16
16
} ;
17
+
18
+ Node3 . prototype . _forward = function ( level , iterator ) {
19
+ iterator . _level . push ( level , level ) ;
20
+ iterator . _stack . push ( this . c , this . b ) ;
21
+ return this . a ;
22
+ } ;
23
+
24
+ Node3 . prototype . _backward = function ( level , iterator ) {
25
+ iterator . _level . push ( level , level ) ;
26
+ iterator . _stack . push ( this . a , this . b ) ;
27
+ return this . c ;
28
+ } ;
You can’t perform that action at this time.
0 commit comments