@@ -553,7 +553,7 @@ var BTree = /** @class */ (function () {
553
553
var valOther = otherLeaf . values [ otherLevelIndices [ otherLevelIndices . length - 1 ] ] ;
554
554
if ( ! Object . is ( valThis , valOther ) ) {
555
555
var result = different ( thisCursor . currentKey , valThis , valOther ) ;
556
- if ( result && ( result === null || result === void 0 ? void 0 : result . break ) )
556
+ if ( result && result . break )
557
557
return result . break ;
558
558
}
559
559
}
@@ -828,12 +828,14 @@ var BTree = /** @class */ (function () {
828
828
if ( key === undefined ) {
829
829
return this . _root . minPair ( reusedArray ) ;
830
830
}
831
- return this . _root . getPairOrNextHigher ( key , this , false , reusedArray ) ;
831
+ return this . _root . getPairOrNextHigher ( key , this . _compare , false , reusedArray ) ;
832
832
} ;
833
- /** Returns the next key larger than the specified key (or undefined if there is none) */
833
+ /** Returns the next key larger than the specified key, or undefined if there is none.
834
+ * Also, nextHigherKey(undefined) returns the lowest key.
835
+ */
834
836
BTree . prototype . nextHigherKey = function ( key ) {
835
837
var p = this . nextHigherPair ( key , ReusedArray ) ;
836
- return p ? p [ 0 ] : p ;
838
+ return p && p [ 0 ] ;
837
839
} ;
838
840
/** Returns the next pair whose key is smaller than the specified key (or undefined if there is none).
839
841
* If key === undefined, this function returns the highest pair.
@@ -846,21 +848,34 @@ var BTree = /** @class */ (function () {
846
848
if ( key === undefined ) {
847
849
return this . _root . maxPair ( reusedArray ) ;
848
850
}
849
- return this . _root . getPairOrNextLower ( key , this , false , reusedArray ) ;
851
+ return this . _root . getPairOrNextLower ( key , this . _compare , false , reusedArray ) ;
850
852
} ;
851
- /** Returns the next key smaller than the specified key (or undefined if there is none) */
853
+ /** Returns the next key smaller than the specified key, or undefined if there is none.
854
+ * Also, nextLowerKey(undefined) returns the highest key.
855
+ */
852
856
BTree . prototype . nextLowerKey = function ( key ) {
853
857
var p = this . nextLowerPair ( key , ReusedArray ) ;
854
- return p ? p [ 0 ] : p ;
858
+ return p && p [ 0 ] ;
855
859
} ;
856
860
/** Returns the key-value pair associated with the supplied key if it exists
857
- * and the next lower pair otherwise (or undefined if there is none)
861
+ * or the pair associated with the next lower pair otherwise. If there is no
862
+ * next lower pair, undefined is returned.
858
863
* @param key The key to search for.
859
864
* @param reusedArray Optional array used repeatedly to store key-value pairs, to
860
865
* avoid creating a new array each time you call this method.
861
866
* */
862
867
BTree . prototype . getPairOrNextLower = function ( key , reusedArray ) {
863
- return this . _root . getPairOrNextLower ( key , this , true , reusedArray || [ ] ) ;
868
+ return this . _root . getPairOrNextLower ( key , this . _compare , true , reusedArray || [ ] ) ;
869
+ } ;
870
+ /** Returns the key-value pair associated with the supplied key if it exists
871
+ * or the pair associated with the next lower pair otherwise. If there is no
872
+ * next lower pair, undefined is returned.
873
+ * @param key The key to search for.
874
+ * @param reusedArray Optional array used repeatedly to store key-value pairs, to
875
+ * avoid creating a new array each time you call this method.
876
+ * */
877
+ BTree . prototype . getPairOrNextHigher = function ( key , reusedArray ) {
878
+ return this . _root . getPairOrNextHigher ( key , this . _compare , true , reusedArray || [ ] ) ;
864
879
} ;
865
880
/** Edits the value associated with a key in the tree, if it already exists.
866
881
* @returns true if the key existed, false if not.
@@ -1179,8 +1194,8 @@ var BNode = /** @class */ (function () {
1179
1194
var i = this . indexOf ( key , - 1 , tree . _compare ) ;
1180
1195
return i < 0 ? defaultValue : this . values [ i ] ;
1181
1196
} ;
1182
- BNode . prototype . getPairOrNextLower = function ( key , tree , inclusive , reusedArray ) {
1183
- var i = this . indexOf ( key , - 1 , tree . _compare ) ;
1197
+ BNode . prototype . getPairOrNextLower = function ( key , compare , inclusive , reusedArray ) {
1198
+ var i = this . indexOf ( key , - 1 , compare ) ;
1184
1199
var indexOrLower = i < 0 ? ~ i - 1 : ( inclusive ? i : i - 1 ) ;
1185
1200
if ( indexOrLower >= 0 ) {
1186
1201
reusedArray [ 0 ] = this . keys [ indexOrLower ] ;
@@ -1189,8 +1204,8 @@ var BNode = /** @class */ (function () {
1189
1204
}
1190
1205
return undefined ;
1191
1206
} ;
1192
- BNode . prototype . getPairOrNextHigher = function ( key , tree , inclusive , reusedArray ) {
1193
- var i = this . indexOf ( key , - 1 , tree . _compare ) ;
1207
+ BNode . prototype . getPairOrNextHigher = function ( key , compare , inclusive , reusedArray ) {
1208
+ var i = this . indexOf ( key , - 1 , compare ) ;
1194
1209
var indexOrLower = i < 0 ? ~ i : ( inclusive ? i : i + 1 ) ;
1195
1210
var keys = this . keys ;
1196
1211
if ( indexOrLower < keys . length ) {
@@ -1404,21 +1419,21 @@ var BNodeInternal = /** @class */ (function (_super) {
1404
1419
var i = this . indexOf ( key , 0 , tree . _compare ) , children = this . children ;
1405
1420
return i < children . length ? children [ i ] . get ( key , defaultValue , tree ) : undefined ;
1406
1421
} ;
1407
- BNodeInternal . prototype . getPairOrNextLower = function ( key , tree , inclusive , reusedArray ) {
1408
- var i = this . indexOf ( key , 0 , tree . _compare ) , children = this . children ;
1422
+ BNodeInternal . prototype . getPairOrNextLower = function ( key , compare , inclusive , reusedArray ) {
1423
+ var i = this . indexOf ( key , 0 , compare ) , children = this . children ;
1409
1424
if ( i >= children . length )
1410
1425
return undefined ;
1411
- var result = children [ i ] . getPairOrNextLower ( key , tree , inclusive , reusedArray ) ;
1426
+ var result = children [ i ] . getPairOrNextLower ( key , compare , inclusive , reusedArray ) ;
1412
1427
if ( result === undefined && i > 0 ) {
1413
1428
return children [ i - 1 ] . maxPair ( reusedArray ) ;
1414
1429
}
1415
1430
return result ;
1416
1431
} ;
1417
- BNodeInternal . prototype . getPairOrNextHigher = function ( key , tree , inclusive , reusedArray ) {
1418
- var i = this . indexOf ( key , 0 , tree . _compare ) , children = this . children , length = children . length ;
1432
+ BNodeInternal . prototype . getPairOrNextHigher = function ( key , compare , inclusive , reusedArray ) {
1433
+ var i = this . indexOf ( key , 0 , compare ) , children = this . children , length = children . length ;
1419
1434
if ( i >= length )
1420
1435
return undefined ;
1421
- var result = children [ i ] . getPairOrNextHigher ( key , tree , inclusive , reusedArray ) ;
1436
+ var result = children [ i ] . getPairOrNextHigher ( key , compare , inclusive , reusedArray ) ;
1422
1437
if ( result === undefined && i < length - 1 ) {
1423
1438
return children [ i + 1 ] . minPair ( reusedArray ) ;
1424
1439
}
0 commit comments