293
return tmp;
294
}
296
>
updateHeight() {
297
this.height = 1 + Math.max(this.heightLeft, this.heightRight);
298
}
300
>
balanceFactor() {
301
return this.heightRight - this.heightLeft;
302
}
304
>
get heightLeft() {
305
return this.left?.height ?? 0;
306
}
308
>
get heightRight() {
309
return this.right?.height ?? 0;
310
}
312
>
313
>
const enum Dir {
314
>
Left = -1,
315
>
Mid = 0,
316
>
Right = 1
317
>
}
318
>
319
>
export class TernarySearchTree<K, V> {
320
>
321
>
static forUris<E>(ignorePathCasing: (key: URI) => boolean = () => false, ignoreQueryAndFragment: (key: URI) => boolean = () => false): TernarySearchTree<URI, E> {
322
return new TernarySearchTree<URI, E>(new UriIterator(ignorePathCasing, ignoreQueryAndFragment));
323
}
325
>
static forPaths<E>(ignorePathCasing = false): TernarySearchTree<string, E> {
326
return new TernarySearchTree<string, E>(new PathIterator(undefined, !ignorePathCasing));
327
}
329
>
static forStrings<E>(): TernarySearchTree<string, E> {
330
return new TernarySearchTree<string, E>(new StringIterator());
331
}
333
>
static forConfigKeys<E>(): TernarySearchTree<string, E> {
334
return new TernarySearchTree<string, E>(new ConfigKeysIterator());
335
}
337
>
private _iter: IKeyIterator<K>;
338
>
private _root: TernarySearchTreeNode<K, V> | undefined;
339
>
340
>
constructor(segments: IKeyIterator<K>) {
341
this._iter = segments;
342
}
344
>
clear(): void {
345
this._root = undefined;
346
}
348
>
/**
349
>
* Fill the tree with the same value of the given keys
350
>
*/
351
>
fill(element: V, keys: readonly K[]): void;
352
>
/**
353
>
* Fill the tree with given [key,value]-tuples
354
>
*/
355
>
fill(values: readonly [K, V][]): void;
356
>
fill(values: readonly [K, V][] | V, keys?: readonly K[]): void {
357
if (keys) {
358
const arr = keys.slice(0);