@@ -931,11 +931,11 @@ export default class BTree<K=any, V=any> implements ISortedMapF<K,V>, ISortedMap
931
931
* avoid creating a new array on every iteration.
932
932
*/
933
933
nextHigherPair ( key : K | undefined , reusedArray ?: [ K , V ] ) : [ K , V ] | undefined {
934
- const pair = reusedArray ?? ( [ ] as unknown as [ K , V ] ) ;
934
+ reusedArray = reusedArray || ( [ ] as unknown as [ K , V ] ) ;
935
935
if ( key === undefined ) {
936
- return this . _root . minPair ( pair ) ;
936
+ return this . _root . minPair ( reusedArray ) ;
937
937
}
938
- return this . _root . getPairOrNextHigher ( key , this , false , pair ) ;
938
+ return this . _root . getPairOrNextHigher ( key , this , false , reusedArray ) ;
939
939
}
940
940
941
941
/** Returns the next key larger than the specified key (or undefined if there is none) */
@@ -948,14 +948,14 @@ export default class BTree<K=any, V=any> implements ISortedMapF<K,V>, ISortedMap
948
948
* If key === undefined, this function returns the highest pair.
949
949
* @param key The key to search for.
950
950
* @param reusedArray Optional array used repeatedly to store key-value pairs, to
951
- * avoid creating a new array on every iteration .
951
+ * avoid creating a new array each time you call this method .
952
952
*/
953
953
nextLowerPair ( key : K | undefined , reusedArray ?: [ K , V ] ) : [ K , V ] | undefined {
954
- const pair = reusedArray ?? ( [ ] as unknown as [ K , V ] ) ;
954
+ reusedArray = reusedArray || ( [ ] as unknown as [ K , V ] ) ;
955
955
if ( key === undefined ) {
956
- return this . _root . maxPair ( pair ) ;
956
+ return this . _root . maxPair ( reusedArray ) ;
957
957
}
958
- return this . _root . getPairOrNextLower ( key , this , false , pair ) ;
958
+ return this . _root . getPairOrNextLower ( key , this , false , reusedArray ) ;
959
959
}
960
960
961
961
/** Returns the next key smaller than the specified key (or undefined if there is none) */
@@ -968,10 +968,10 @@ export default class BTree<K=any, V=any> implements ISortedMapF<K,V>, ISortedMap
968
968
* and the next lower pair otherwise (or undefined if there is none)
969
969
* @param key The key to search for.
970
970
* @param reusedArray Optional array used repeatedly to store key-value pairs, to
971
- * avoid creating a new array on every iteration .
971
+ * avoid creating a new array each time you call this method .
972
972
* */
973
973
getPairOrNextLower ( key : K , reusedArray ?: [ K , V ] ) : [ K , V ] | undefined {
974
- return this . _root . getPairOrNextLower ( key , this , true , reusedArray ?? ( [ ] as unknown as [ K , V ] ) ) ;
974
+ return this . _root . getPairOrNextLower ( key , this , true , reusedArray || ( [ ] as unknown as [ K , V ] ) ) ;
975
975
}
976
976
977
977
/** Edits the value associated with a key in the tree, if it already exists.
@@ -1311,7 +1311,7 @@ class BNode<K,V> {
1311
1311
1312
1312
getPairOrNextLower ( key : K , tree : BTree < K , V > , inclusive : boolean , reusedArray : [ K , V ] ) : [ K , V ] | undefined {
1313
1313
var i = this . indexOf ( key , - 1 , tree . _compare ) ;
1314
- const indexOrLower = i < 0 ? ( i ^ - 1 ) - 1 : ( inclusive ? i : i - 1 ) ;
1314
+ const indexOrLower = i < 0 ? ~ i - 1 : ( inclusive ? i : i - 1 ) ;
1315
1315
if ( indexOrLower >= 0 ) {
1316
1316
reusedArray [ 0 ] = this . keys [ indexOrLower ] ;
1317
1317
reusedArray [ 1 ] = this . values [ indexOrLower ] ;
@@ -1322,7 +1322,7 @@ class BNode<K,V> {
1322
1322
1323
1323
getPairOrNextHigher ( key : K , tree : BTree < K , V > , inclusive : boolean , reusedArray : [ K , V ] ) : [ K , V ] | undefined {
1324
1324
var i = this . indexOf ( key , - 1 , tree . _compare ) ;
1325
- const indexOrLower = i < 0 ? i ^ - 1 : ( inclusive ? i : i + 1 ) ;
1325
+ const indexOrLower = i < 0 ? ~ i : ( inclusive ? i : i + 1 ) ;
1326
1326
const keys = this . keys ;
1327
1327
if ( indexOrLower < keys . length ) {
1328
1328
reusedArray [ 0 ] = keys [ indexOrLower ] ;
0 commit comments