@@ -1175,15 +1175,6 @@ export default class BTree<K=any, V=any> implements ISortedMapF<K,V>, ISortedMap
1175
1175
return this . hasOwnProperty ( 'editRange' ) ;
1176
1176
}
1177
1177
1178
- /** A TypeScript helper function that returns `this as ISortedSet<K>` if this
1179
- * BTree implements it, which it does if `V extends undefined`. If `V` cannot
1180
- * be `undefined`, it returns `unknown` instead. Or at least, that was the
1181
- * intention, but TypeScript is acting weird and may return `ISortedSet<K>`
1182
- * even if `V` can't be `undefined` (discussion: btree-typescript issue #14) */
1183
- get asSet ( ) : undefined extends V ? ISortedSet < K > : unknown {
1184
- return this as any ;
1185
- }
1186
-
1187
1178
/** Scans the tree for signs of serious bugs (e.g. this.size doesn't match
1188
1179
* number of elements, internal nodes not caching max element properly...)
1189
1180
* Computational complexity: O(number of nodes), i.e. O(size). This method
@@ -1195,20 +1186,29 @@ export default class BTree<K=any, V=any> implements ISortedMapF<K,V>, ISortedMap
1195
1186
}
1196
1187
}
1197
1188
1189
+ /** A TypeScript helper function that simply returns its argument, typed as
1190
+ * `ISortedSet<K>` if the BTree implements it, as it does if `V extends undefined`.
1191
+ * If `V` cannot be `undefined`, it returns `unknown` instead. Or at least, that
1192
+ * was the intention, but TypeScript is acting weird and may return `ISortedSet<K>`
1193
+ * even if `V` can't be `undefined` (discussion: btree-typescript issue #14) */
1194
+ export function asSet < K , V > ( btree : BTree < K , V > ) : undefined extends V ? ISortedSet < K > : unknown {
1195
+ return btree as any ;
1196
+ }
1197
+
1198
1198
declare const Symbol : any ;
1199
1199
if ( Symbol && Symbol . iterator ) // iterator is equivalent to entries()
1200
1200
( BTree as any ) . prototype [ Symbol . iterator ] = BTree . prototype . entries ;
1201
1201
( BTree as any ) . prototype . where = BTree . prototype . filter ;
1202
1202
( BTree as any ) . prototype . setRange = BTree . prototype . setPairs ;
1203
- ( BTree as any ) . prototype . add = BTree . prototype . set ;
1203
+ ( BTree as any ) . prototype . add = BTree . prototype . set ; // for compatibility with ISetSink<K>
1204
1204
1205
1205
function iterator < T > ( next : ( ) => IteratorResult < T > = ( ( ) => ( { done :true , value :undefined } ) ) ) : IterableIterator < T > {
1206
1206
var result : any = { next } ;
1207
1207
if ( Symbol && Symbol . iterator )
1208
1208
result [ Symbol . iterator ] = function ( ) { return this ; } ;
1209
1209
return result ;
1210
1210
}
1211
-
1211
+
1212
1212
1213
1213
/** Leaf node / base class. **************************************************/
1214
1214
class BNode < K , V > {
0 commit comments