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 () {
2929} ;
3030
3131BackwardIterator . 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 ) ;
4235} ;
Original file line number Diff line number Diff line change @@ -29,14 +29,7 @@ ForwardIterator.prototype._upwardStep = function () {
2929} ;
3030
3131ForwardIterator . 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 ) ;
4235} ;
Original file line number Diff line number Diff line change @@ -13,3 +13,15 @@ Node2.prototype.measure = function () {
1313Node2 . prototype . _digit = function ( ) {
1414 return new Two ( this . a , this . b ) ;
1515} ;
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 () {
1414Node3 . prototype . _digit = function ( ) {
1515 return new Three ( this . a , this . b , this . c ) ;
1616} ;
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