max-heap-typed 2.2.4 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +0 -36
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +0 -36
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +0 -36
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +0 -36
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +14 -57
- package/dist/types/data-structures/binary-tree/bst.d.ts +110 -96
- package/dist/umd/max-heap-typed.js +0 -33
- package/dist/umd/max-heap-typed.js.map +1 -1
- package/dist/umd/max-heap-typed.min.js +1 -1
- package/dist/umd/max-heap-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/index.ts +2 -4
- package/src/data-structures/base/iterable-entry-base.ts +9 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +3 -1
- package/src/data-structures/binary-tree/binary-tree.ts +67 -0
- package/src/data-structures/binary-tree/bst.ts +658 -71
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparator,
|
|
8
|
+
import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparator, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeCallback, NodePredicate, OptNode, RBTNColor } from '../../types';
|
|
9
9
|
import { BinaryTree } from './binary-tree';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { Range } from '../../common';
|
|
@@ -257,7 +257,7 @@ export declare class BSTNode<K = any, V = any> {
|
|
|
257
257
|
* return findFirstCommon(path1, path2);
|
|
258
258
|
* };
|
|
259
259
|
*
|
|
260
|
-
* function findFirstCommon(arr1: number[], arr2: number[]): number | undefined {
|
|
260
|
+
* function findFirstCommon(arr1: (number | undefined)[], arr2: (number | undefined)[]): number | undefined {
|
|
261
261
|
* for (const num of arr1) {
|
|
262
262
|
* if (arr2.indexOf(num) !== -1) {
|
|
263
263
|
* return num;
|
|
@@ -288,12 +288,6 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
288
288
|
* @returns The root node.
|
|
289
289
|
*/
|
|
290
290
|
get root(): OptNode<BSTNode<K, V>>;
|
|
291
|
-
/**
|
|
292
|
-
* (Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
293
|
-
* @remarks Time O(1) Space O(1)
|
|
294
|
-
* @returns The default comparator function.
|
|
295
|
-
*/
|
|
296
|
-
protected _createDefaultComparator(): Comparator<K>;
|
|
297
291
|
/**
|
|
298
292
|
* The comparator function used to determine the order of keys in the tree.
|
|
299
293
|
|
|
@@ -341,41 +335,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
341
335
|
* @returns True if the key is valid, false otherwise.
|
|
342
336
|
*/
|
|
343
337
|
isValidKey(key: any): key is K;
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
* @param [pattern='IN'] - The traversal order ('IN', 'PRE', 'POST').
|
|
351
|
-
* @param [onlyOne=false] - If true, stops after the first callback.
|
|
352
|
-
* @param [startNode=this._root] - The node to start from.
|
|
353
|
-
* @param [iterationType=this.iterationType] - The traversal method.
|
|
354
|
-
* @returns An array of callback results.
|
|
355
|
-
*/
|
|
356
|
-
dfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
357
|
-
/**
|
|
358
|
-
* Performs a Breadth-First Search (BFS) or Level-Order traversal.
|
|
359
|
-
* @remarks Time O(N), visits every node. Space O(N) in the worst case for the queue.
|
|
360
|
-
*
|
|
361
|
-
* @template C - The type of the callback function.
|
|
362
|
-
* @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on each node.
|
|
363
|
-
* @param [startNode=this._root] - The node to start from.
|
|
364
|
-
* @param [iterationType=this.iterationType] - The traversal method.
|
|
365
|
-
* @returns An array of callback results.
|
|
366
|
-
*/
|
|
367
|
-
bfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
368
|
-
/**
|
|
369
|
-
* Returns a 2D array of nodes, grouped by level.
|
|
370
|
-
* @remarks Time O(N), visits every node. Space O(N) for the result array and the queue/stack.
|
|
371
|
-
*
|
|
372
|
-
* @template C - The type of the callback function.
|
|
373
|
-
* @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on each node.
|
|
374
|
-
* @param [startNode=this._root] - The node to start from.
|
|
375
|
-
* @param [iterationType=this.iterationType] - The traversal method.
|
|
376
|
-
* @returns A 2D array of callback results.
|
|
377
|
-
*/
|
|
378
|
-
listLevels<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[][];
|
|
338
|
+
dfs(): (K | undefined)[];
|
|
339
|
+
dfs<C extends NodeCallback<BSTNode<K, V>>>(callback: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
340
|
+
bfs(): (K | undefined)[];
|
|
341
|
+
bfs<C extends NodeCallback<BSTNode<K, V>>>(callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
342
|
+
listLevels(): (K | undefined)[][];
|
|
343
|
+
listLevels<C extends NodeCallback<BSTNode<K, V>>>(callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[][];
|
|
379
344
|
/**
|
|
380
345
|
* Gets the first node matching a predicate.
|
|
381
346
|
* @remarks Time O(log N) if searching by key, O(N) if searching by predicate. Space O(log N) or O(N).
|
|
@@ -386,33 +351,10 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
386
351
|
* @returns The first matching node, or undefined if not found.
|
|
387
352
|
*/
|
|
388
353
|
getNode(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, startNode?: BSTNOptKeyOrNode<K, BSTNode<K, V>>, iterationType?: IterationType): OptNode<BSTNode<K, V>>;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
* Space O(log N) for the stack.
|
|
394
|
-
*
|
|
395
|
-
* @template C - The type of the callback function.
|
|
396
|
-
* @param keyNodeEntryOrPredicate - The key, node, entry, predicate, or range to search for.
|
|
397
|
-
* @param [onlyOne=false] - If true, stops after finding the first match.
|
|
398
|
-
* @param [callback=this._DEFAULT_NODE_CALLBACK] - A function to call on matching nodes.
|
|
399
|
-
* @param [startNode=this._root] - The node to start the search from.
|
|
400
|
-
* @param [iterationType=this.iterationType] - Whether to use 'RECURSIVE' or 'ITERATIVE' search.
|
|
401
|
-
* @returns An array of results from the callback function for each matching node.
|
|
402
|
-
*/
|
|
403
|
-
search<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean, callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
404
|
-
/**
|
|
405
|
-
* Performs an optimized search for nodes within a given key range.
|
|
406
|
-
* @remarks Time O(H + M), where H is tree height and M is the number of matches.
|
|
407
|
-
*
|
|
408
|
-
* @template C - The type of the callback function.
|
|
409
|
-
* @param range - A `Range` object or a `[low, high]` tuple.
|
|
410
|
-
* @param [callback=this._DEFAULT_NODE_CALLBACK] - A function to call on matching nodes.
|
|
411
|
-
* @param [startNode=this._root] - The node to start the search from.
|
|
412
|
-
* @param [iterationType=this.iterationType] - The traversal method.
|
|
413
|
-
* @returns An array of callback results.
|
|
414
|
-
*/
|
|
415
|
-
rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
354
|
+
search(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean): (K | undefined)[];
|
|
355
|
+
search<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne: boolean, callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
356
|
+
rangeSearch(range: Range<K> | [K, K]): (K | undefined)[];
|
|
357
|
+
rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
416
358
|
/**
|
|
417
359
|
* Adds a new node to the BST based on key comparison.
|
|
418
360
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -436,39 +378,59 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
436
378
|
*/
|
|
437
379
|
addMany(keysNodesEntriesOrRaws: Iterable<R | BTNRep<K, V, BSTNode<K, V>>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
|
|
438
380
|
/**
|
|
439
|
-
* Returns the first
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
* Time Complexity: O(log n) on average, O(h) where h is tree height.
|
|
381
|
+
* Returns the first key with a value >= target.
|
|
382
|
+
* Equivalent to Java TreeMap.ceiling.
|
|
383
|
+
* Time Complexity: O(log n) average, O(h) worst case.
|
|
443
384
|
* Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
444
|
-
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
445
|
-
* @param iterationType The iteration type (RECURSIVE or ITERATIVE). Defaults to this.iterationType.
|
|
446
|
-
* @returns The first node with key >= given key, or undefined if no such node exists.
|
|
447
385
|
*/
|
|
448
|
-
|
|
386
|
+
ceiling(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): K | undefined;
|
|
449
387
|
/**
|
|
450
|
-
* Returns the first node with a key
|
|
451
|
-
*
|
|
452
|
-
* Supports RECURSIVE and ITERATIVE implementations.
|
|
453
|
-
* Time Complexity: O(log n) on average, O(h) where h is tree height.
|
|
388
|
+
* Returns the first node with a key >= target and applies callback.
|
|
389
|
+
* Time Complexity: O(log n) average, O(h) worst case.
|
|
454
390
|
* Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
455
|
-
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
456
|
-
* @param iterationType The iteration type (RECURSIVE or ITERATIVE). Defaults to this.iterationType.
|
|
457
|
-
* @returns The first node with key > given key, or undefined if no such node exists.
|
|
458
391
|
*/
|
|
459
|
-
|
|
392
|
+
ceiling<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, callback: C, iterationType?: IterationType): ReturnType<C>;
|
|
460
393
|
/**
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
*
|
|
469
|
-
*
|
|
394
|
+
* Returns the first key with a value > target.
|
|
395
|
+
* Equivalent to Java TreeMap.higher.
|
|
396
|
+
* Time Complexity: O(log n) average, O(h) worst case.
|
|
397
|
+
* Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
398
|
+
*/
|
|
399
|
+
higher(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): K | undefined;
|
|
400
|
+
/**
|
|
401
|
+
* Returns the first node with a key > target and applies callback.
|
|
402
|
+
* Time Complexity: O(log n) average, O(h) worst case.
|
|
403
|
+
* Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
470
404
|
*/
|
|
471
|
-
|
|
405
|
+
higher<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, callback: C, iterationType?: IterationType): ReturnType<C>;
|
|
406
|
+
/**
|
|
407
|
+
* Returns the first key with a value <= target.
|
|
408
|
+
* Equivalent to Java TreeMap.floor.
|
|
409
|
+
* Time Complexity: O(log n) average, O(h) worst case.
|
|
410
|
+
* Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
411
|
+
*/
|
|
412
|
+
floor(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): K | undefined;
|
|
413
|
+
/**
|
|
414
|
+
* Returns the first node with a key <= target and applies callback.
|
|
415
|
+
* Time Complexity: O(log n) average, O(h) worst case.
|
|
416
|
+
* Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
417
|
+
*/
|
|
418
|
+
floor<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, callback: C, iterationType?: IterationType): ReturnType<C>;
|
|
419
|
+
/**
|
|
420
|
+
* Returns the first key with a value < target.
|
|
421
|
+
* Equivalent to Java TreeMap.lower.
|
|
422
|
+
* Time Complexity: O(log n) average, O(h) worst case.
|
|
423
|
+
* Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
424
|
+
*/
|
|
425
|
+
lower(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): K | undefined;
|
|
426
|
+
/**
|
|
427
|
+
* Returns the first node with a key < target and applies callback.
|
|
428
|
+
* Time Complexity: O(log n) average, O(h) worst case.
|
|
429
|
+
* Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
430
|
+
*/
|
|
431
|
+
lower<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, callback: C, iterationType?: IterationType): ReturnType<C>;
|
|
432
|
+
lesserOrGreaterTraverse(): (K | undefined)[];
|
|
433
|
+
lesserOrGreaterTraverse<C extends NodeCallback<BSTNode<K, V>>>(callback: C, lesserOrGreater?: number, targetNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
472
434
|
/**
|
|
473
435
|
* Rebuilds the tree to be perfectly balanced.
|
|
474
436
|
* @remarks Time O(N) (O(N) for DFS, O(N) for sorted build). Space O(N) for node array and recursion stack.
|
|
@@ -536,6 +498,58 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
536
498
|
* - If no nodes match the search criteria, the returned map is empty.
|
|
537
499
|
*/
|
|
538
500
|
deleteWhere(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): BinaryTreeDeleteResult<BSTNode<K, V>>[];
|
|
501
|
+
/**
|
|
502
|
+
* (Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
503
|
+
* @remarks Time O(1) Space O(1)
|
|
504
|
+
* @returns The default comparator function.
|
|
505
|
+
*/
|
|
506
|
+
protected _createDefaultComparator(): Comparator<K>;
|
|
507
|
+
/**
|
|
508
|
+
* (Protected) Binary search for floor by key with pruning optimization.
|
|
509
|
+
* Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
510
|
+
* Finds first node where key <= target.
|
|
511
|
+
* @remarks Time O(h) where h is tree height.
|
|
512
|
+
*
|
|
513
|
+
* @param key - The target key to search for.
|
|
514
|
+
* @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
|
|
515
|
+
* @returns The first node with key <= target, or undefined if none exists.
|
|
516
|
+
*/
|
|
517
|
+
protected _floorByKey(key: K, iterationType: IterationType): BSTNode<K, V> | undefined;
|
|
518
|
+
/**
|
|
519
|
+
* (Protected) In-order traversal search for floor by predicate.
|
|
520
|
+
* Falls back to linear in-order traversal when predicate-based search is required.
|
|
521
|
+
* Returns the last node that satisfies the predicate function.
|
|
522
|
+
* @remarks Time Complexity: O(n) since it may visit every node.
|
|
523
|
+
* Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
524
|
+
*
|
|
525
|
+
* @param predicate - The predicate function to test nodes.
|
|
526
|
+
* @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
|
|
527
|
+
* @returns The last node satisfying predicate (highest key), or undefined if none found.
|
|
528
|
+
*/
|
|
529
|
+
protected _floorByPredicate(predicate: NodePredicate<BSTNode<K, V>>, iterationType: IterationType): BSTNode<K, V> | undefined;
|
|
530
|
+
/**
|
|
531
|
+
* (Protected) Binary search for lower by key with pruning optimization.
|
|
532
|
+
* Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
533
|
+
* Finds first node where key < target.
|
|
534
|
+
* @remarks Time O(h) where h is tree height.
|
|
535
|
+
*
|
|
536
|
+
* @param key - The target key to search for.
|
|
537
|
+
* @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
|
|
538
|
+
* @returns The first node with key < target, or undefined if none exists.
|
|
539
|
+
*/
|
|
540
|
+
protected _lowerByKey(key: K, iterationType: IterationType): BSTNode<K, V> | undefined;
|
|
541
|
+
/**
|
|
542
|
+
* (Protected) In-order traversal search for lower by predicate.
|
|
543
|
+
* Falls back to linear in-order traversal when predicate-based search is required.
|
|
544
|
+
* Returns the node that satisfies the predicate and appears last in in-order traversal.
|
|
545
|
+
* @remarks Time Complexity: O(n) since it may visit every node.
|
|
546
|
+
* Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
547
|
+
*
|
|
548
|
+
* @param predicate - The predicate function to test nodes.
|
|
549
|
+
* @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
|
|
550
|
+
* @returns The last node satisfying predicate (highest key < target), or undefined if none found.
|
|
551
|
+
*/
|
|
552
|
+
protected _lowerByPredicate(predicate: NodePredicate<BSTNode<K, V>>, iterationType: IterationType): BSTNode<K, V> | undefined;
|
|
539
553
|
/**
|
|
540
554
|
* (Protected) Core bound search implementation supporting all parameter types.
|
|
541
555
|
* Unified logic for both lowerBound and upperBound.
|
|
@@ -932,37 +932,6 @@ var maxHeapTyped = (() => {
|
|
|
932
932
|
}
|
|
933
933
|
};
|
|
934
934
|
|
|
935
|
-
// src/utils/utils.ts
|
|
936
|
-
function isPrimitiveComparable(value) {
|
|
937
|
-
const valueType = typeof value;
|
|
938
|
-
if (valueType === "number") return true;
|
|
939
|
-
return valueType === "bigint" || valueType === "string" || valueType === "boolean";
|
|
940
|
-
}
|
|
941
|
-
function tryObjectToPrimitive(obj) {
|
|
942
|
-
if (typeof obj.valueOf === "function") {
|
|
943
|
-
const valueOfResult = obj.valueOf();
|
|
944
|
-
if (valueOfResult !== obj) {
|
|
945
|
-
if (isPrimitiveComparable(valueOfResult)) return valueOfResult;
|
|
946
|
-
if (typeof valueOfResult === "object" && valueOfResult !== null) return tryObjectToPrimitive(valueOfResult);
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
if (typeof obj.toString === "function") {
|
|
950
|
-
const stringResult = obj.toString();
|
|
951
|
-
if (stringResult !== "[object Object]") return stringResult;
|
|
952
|
-
}
|
|
953
|
-
return null;
|
|
954
|
-
}
|
|
955
|
-
function isComparable(value, isForceObjectComparable = false) {
|
|
956
|
-
if (value === null || value === void 0) return false;
|
|
957
|
-
if (isPrimitiveComparable(value)) return true;
|
|
958
|
-
if (typeof value !== "object") return false;
|
|
959
|
-
if (value instanceof Date) return true;
|
|
960
|
-
if (isForceObjectComparable) return true;
|
|
961
|
-
const comparableValue = tryObjectToPrimitive(value);
|
|
962
|
-
if (comparableValue === null || comparableValue === void 0) return false;
|
|
963
|
-
return isPrimitiveComparable(comparableValue);
|
|
964
|
-
}
|
|
965
|
-
|
|
966
935
|
// src/common/index.ts
|
|
967
936
|
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
968
937
|
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
@@ -975,8 +944,6 @@ var maxHeapTyped = (() => {
|
|
|
975
944
|
this.high = high;
|
|
976
945
|
this.includeLow = includeLow;
|
|
977
946
|
this.includeHigh = includeHigh;
|
|
978
|
-
if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
|
|
979
|
-
if (low > high) throw new RangeError("low must be less than or equal to high");
|
|
980
947
|
}
|
|
981
948
|
// Determine whether a key is within the range
|
|
982
949
|
isInRange(key, comparator) {
|