graph-typed 1.51.7 → 1.51.9
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/data-structures/binary-tree/avl-tree-multi-map.d.ts +103 -74
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +116 -93
- package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
- package/dist/data-structures/binary-tree/avl-tree.js +90 -71
- package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -233
- package/dist/data-structures/binary-tree/binary-tree.js +492 -392
- package/dist/data-structures/binary-tree/bst.d.ts +204 -251
- package/dist/data-structures/binary-tree/bst.js +256 -358
- package/dist/data-structures/binary-tree/rb-tree.d.ts +74 -85
- package/dist/data-structures/binary-tree/rb-tree.js +111 -119
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -76
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
- package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
- package/dist/data-structures/graph/abstract-graph.js +10 -15
- package/dist/data-structures/hash/hash-map.d.ts +31 -38
- package/dist/data-structures/hash/hash-map.js +40 -55
- package/dist/data-structures/heap/heap.d.ts +1 -3
- package/dist/data-structures/queue/deque.d.ts +2 -3
- package/dist/data-structures/queue/deque.js +2 -3
- package/dist/data-structures/trie/trie.d.ts +1 -1
- package/dist/data-structures/trie/trie.js +1 -1
- package/dist/interfaces/binary-tree.d.ts +7 -7
- package/dist/types/common.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +4 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +6 -5
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -3
- package/dist/types/utils/utils.d.ts +10 -1
- package/dist/utils/utils.d.ts +2 -1
- package/dist/utils/utils.js +27 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -100
- package/src/data-structures/binary-tree/avl-tree.ts +109 -80
- package/src/data-structures/binary-tree/binary-tree.ts +556 -433
- package/src/data-structures/binary-tree/bst.ts +286 -375
- package/src/data-structures/binary-tree/rb-tree.ts +132 -125
- package/src/data-structures/binary-tree/tree-multi-map.ts +129 -102
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +42 -49
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/trie/trie.ts +2 -2
- package/src/interfaces/binary-tree.ts +11 -9
- package/src/types/common.ts +2 -3
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +4 -3
- package/src/types/data-structures/binary-tree/avl-tree.ts +4 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +7 -6
- package/src/types/data-structures/binary-tree/bst.ts +6 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -3
- package/src/types/utils/utils.ts +14 -1
- package/src/utils/utils.ts +20 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
|
-
import { IterationType } from
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
2
|
+
import { BTNEntry, IterationType } from '../../common';
|
|
3
|
+
import { Comparable } from '../../utils';
|
|
4
|
+
export type BinaryTreeNodeNested<K extends Comparable, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type BinaryTreeNested<K extends Comparable, V, R, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type BinaryTreeOptions<K, V, R> = {
|
|
6
7
|
iterationType?: IterationType;
|
|
7
|
-
|
|
8
|
+
toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
8
9
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BST, BSTNode } from '../../../data-structures';
|
|
2
2
|
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
7
|
-
|
|
3
|
+
import { Comparator } from '../../common';
|
|
4
|
+
import { Comparable } from '../../utils';
|
|
5
|
+
export type BSTNodeNested<K extends Comparable, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type BSTNested<K extends Comparable, V, R, NODE extends BSTNode<K, V, NODE>> = BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
7
|
+
export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
|
|
8
|
+
comparator?: Comparator<K>;
|
|
8
9
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RedBlackTree, RedBlackTreeNode } from '../../../data-structures';
|
|
2
2
|
import type { BSTOptions } from "./bst";
|
|
3
|
+
import { Comparable } from "../../utils";
|
|
3
4
|
export type RBTNColor = 'RED' | 'BLACK';
|
|
4
|
-
export type RedBlackTreeNodeNested<K, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
-
export type RedBlackTreeNested<K, V,
|
|
6
|
-
export type RBTreeOptions<K> =
|
|
5
|
+
export type RedBlackTreeNodeNested<K extends Comparable, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type RedBlackTreeNested<K extends Comparable, V, R, NODE extends RedBlackTreeNode<K, V, NODE>> = RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
7
|
+
export type RBTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TreeMultiMap, TreeMultiMapNode } from '../../../data-structures';
|
|
2
2
|
import type { RBTreeOptions } from './rb-tree';
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
3
|
+
import { Comparable } from '../../utils';
|
|
4
|
+
export type TreeMultiMapNodeNested<K extends Comparable, V> = TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type TreeMultiMapNested<K extends Comparable, V, R, NODE extends TreeMultiMapNode<K, V, NODE>> = TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type TreeMultiMapOptions<K, V, R> = RBTreeOptions<K, V, R> & {};
|
|
@@ -5,4 +5,13 @@ export type Thunk = () => ReturnType<ToThunkFn> & {
|
|
|
5
5
|
export type TrlFn = (...args: any[]) => any;
|
|
6
6
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
7
7
|
export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
8
|
-
export type Any = string | number |
|
|
8
|
+
export type Any = string | number | bigint | boolean | symbol | undefined | object;
|
|
9
|
+
export type Comparable = number | string | bigint | boolean | ({
|
|
10
|
+
[key in string]: any;
|
|
11
|
+
} & {
|
|
12
|
+
valueOf(): Comparable;
|
|
13
|
+
}) | ({
|
|
14
|
+
[key in string]: any;
|
|
15
|
+
} & {
|
|
16
|
+
toString(): Comparable;
|
|
17
|
+
}) | (() => Comparable);
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
|
|
8
|
+
import type { Comparable, Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
|
|
9
9
|
export declare const uuidV4: () => string;
|
|
10
10
|
export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean) => T[];
|
|
11
11
|
export declare const THUNK_SYMBOL: unique symbol;
|
|
@@ -23,3 +23,4 @@ export declare const throwRangeError: (message?: string) => void;
|
|
|
23
23
|
export declare const isWeakKey: (input: unknown) => input is object;
|
|
24
24
|
export declare const calcMinUnitsRequired: (totalQuantity: number, unitSize: number) => number;
|
|
25
25
|
export declare const roundFixed: (num: number, digit?: number) => number;
|
|
26
|
+
export declare function isComparable(key: any): key is Comparable;
|
package/dist/utils/utils.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.roundFixed = exports.calcMinUnitsRequired = exports.isWeakKey = exports.throwRangeError = exports.rangeCheck = exports.getMSB = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
|
|
12
|
+
exports.isComparable = exports.roundFixed = exports.calcMinUnitsRequired = exports.isWeakKey = exports.throwRangeError = exports.rangeCheck = exports.getMSB = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
|
|
13
13
|
const uuidV4 = function () {
|
|
14
14
|
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
|
15
15
|
const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
@@ -92,3 +92,29 @@ const roundFixed = (num, digit = 10) => {
|
|
|
92
92
|
return Math.round(num * multiplier) / multiplier;
|
|
93
93
|
};
|
|
94
94
|
exports.roundFixed = roundFixed;
|
|
95
|
+
function isComparable(key) {
|
|
96
|
+
const keyType = typeof key;
|
|
97
|
+
if (keyType === 'number')
|
|
98
|
+
return !isNaN(key);
|
|
99
|
+
if (keyType === 'string')
|
|
100
|
+
return true;
|
|
101
|
+
if (keyType === 'bigint')
|
|
102
|
+
return true;
|
|
103
|
+
if (keyType === 'boolean')
|
|
104
|
+
return true;
|
|
105
|
+
if (keyType === 'symbol')
|
|
106
|
+
return false;
|
|
107
|
+
if (keyType === 'undefined')
|
|
108
|
+
return false;
|
|
109
|
+
if (keyType === 'function')
|
|
110
|
+
return isComparable(key());
|
|
111
|
+
if (keyType === 'object') {
|
|
112
|
+
if (key === null)
|
|
113
|
+
return true;
|
|
114
|
+
// if (typeof key.valueOf === 'function') return isComparable(key.valueOf()); // This will keep recursing because every object has a valueOf method.
|
|
115
|
+
// if (typeof key.toString === 'function') return isComparable(key.toString()); // This will also keep recursing because every string type has a toString method.
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
exports.isComparable = isComparable;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graph-typed",
|
|
3
|
-
"version": "1.51.
|
|
3
|
+
"version": "1.51.9",
|
|
4
4
|
"description": "Graph. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -136,6 +136,6 @@
|
|
|
136
136
|
"typescript": "^4.9.5"
|
|
137
137
|
},
|
|
138
138
|
"dependencies": {
|
|
139
|
-
"data-structure-typed": "^1.51.
|
|
139
|
+
"data-structure-typed": "^1.51.9"
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -12,14 +12,16 @@ import type {
|
|
|
12
12
|
BinaryTreeDeleteResult,
|
|
13
13
|
BSTNKeyOrNode,
|
|
14
14
|
BTNCallback,
|
|
15
|
+
Comparable,
|
|
15
16
|
IterationType,
|
|
16
17
|
KeyOrNodeOrEntry
|
|
17
18
|
} from '../../types';
|
|
19
|
+
import { BTNEntry } from '../../types';
|
|
18
20
|
import { IBinaryTree } from '../../interfaces';
|
|
19
21
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
20
22
|
|
|
21
23
|
export class AVLTreeMultiMapNode<
|
|
22
|
-
K
|
|
24
|
+
K extends Comparable,
|
|
23
25
|
V = any,
|
|
24
26
|
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>
|
|
25
27
|
> extends AVLTreeNode<K, V, NODE> {
|
|
@@ -62,21 +64,38 @@ export class AVLTreeMultiMapNode<
|
|
|
62
64
|
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
63
65
|
*/
|
|
64
66
|
export class AVLTreeMultiMap<
|
|
65
|
-
K
|
|
67
|
+
K extends Comparable,
|
|
66
68
|
V = any,
|
|
69
|
+
R = BTNEntry<K, V>,
|
|
67
70
|
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
|
|
68
|
-
TREE extends AVLTreeMultiMap<K, V, NODE, TREE> = AVLTreeMultiMap<
|
|
71
|
+
TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<
|
|
72
|
+
K,
|
|
73
|
+
V,
|
|
74
|
+
R,
|
|
75
|
+
NODE,
|
|
76
|
+
AVLTreeMultiMapNested<K, V, R, NODE>
|
|
77
|
+
>
|
|
69
78
|
>
|
|
70
|
-
extends AVLTree<K, V, NODE, TREE>
|
|
71
|
-
implements IBinaryTree<K, V, NODE, TREE> {
|
|
72
|
-
|
|
79
|
+
extends AVLTree<K, V, R, NODE, TREE>
|
|
80
|
+
implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
81
|
+
/**
|
|
82
|
+
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
83
|
+
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
|
|
84
|
+
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
85
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
86
|
+
* behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
|
|
87
|
+
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
88
|
+
*/
|
|
89
|
+
constructor(
|
|
90
|
+
keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>> = [],
|
|
91
|
+
options?: AVLTreeMultiMapOptions<K, V, R>
|
|
92
|
+
) {
|
|
73
93
|
super([], options);
|
|
74
|
-
if (
|
|
94
|
+
if (keysOrNodesOrEntriesOrRawElements) this.addMany(keysOrNodesOrEntriesOrRawElements);
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
protected _count = 0;
|
|
78
98
|
|
|
79
|
-
// TODO the _count is not accurate after nodes count modified
|
|
80
99
|
/**
|
|
81
100
|
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
82
101
|
* search.
|
|
@@ -106,13 +125,15 @@ export class AVLTreeMultiMap<
|
|
|
106
125
|
}
|
|
107
126
|
|
|
108
127
|
/**
|
|
109
|
-
* The function creates a new
|
|
110
|
-
* @param {K} key - The key parameter
|
|
111
|
-
*
|
|
112
|
-
* @param {
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
128
|
+
* The function creates a new AVLTreeMultiMapNode with the specified key, value, and count.
|
|
129
|
+
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
130
|
+
* which is a generic type that can be replaced with any specific type when using the function.
|
|
131
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
132
|
+
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
133
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of a
|
|
134
|
+
* key-value pair in the AVLTreeMultiMapNode. It is an optional parameter, so it can be omitted when
|
|
135
|
+
* calling the `createNode` method. If provided, it specifies the initial count for the node.
|
|
136
|
+
* @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
|
|
116
137
|
*/
|
|
117
138
|
override createNode(key: K, value?: V, count?: number): NODE {
|
|
118
139
|
return new AVLTreeMultiMapNode(key, value, count) as NODE;
|
|
@@ -121,64 +142,65 @@ export class AVLTreeMultiMap<
|
|
|
121
142
|
/**
|
|
122
143
|
* The function creates a new AVLTreeMultiMap object with the specified options and returns it.
|
|
123
144
|
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
124
|
-
* configuration options for creating the
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @returns a new instance of the `AVLTreeMultiMap` class, with the provided options merged with the
|
|
128
|
-
* default options. The returned value is casted as `TREE`.
|
|
145
|
+
* configuration options for creating the AVLTreeMultiMap. It can have the following properties:
|
|
146
|
+
* @returns a new instance of the AVLTreeMultiMap class, with the specified options, as a TREE
|
|
147
|
+
* object.
|
|
129
148
|
*/
|
|
130
|
-
override createTree(options?: AVLTreeMultiMapOptions<K>): TREE {
|
|
131
|
-
return new AVLTreeMultiMap<K, V, NODE, TREE>([], {
|
|
149
|
+
override createTree(options?: AVLTreeMultiMapOptions<K, V, R>): TREE {
|
|
150
|
+
return new AVLTreeMultiMap<K, V, R, NODE, TREE>([], {
|
|
132
151
|
iterationType: this.iterationType,
|
|
133
|
-
|
|
152
|
+
comparator: this.comparator,
|
|
134
153
|
...options
|
|
135
154
|
}) as TREE;
|
|
136
155
|
}
|
|
137
156
|
|
|
138
157
|
/**
|
|
139
|
-
* The function
|
|
140
|
-
* @param
|
|
141
|
-
* can be
|
|
142
|
-
* @
|
|
143
|
-
*
|
|
144
|
-
|
|
158
|
+
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
159
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
160
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
161
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
162
|
+
* an instance of the `AVLTreeMultiMapNode` class.
|
|
163
|
+
*/
|
|
164
|
+
override isNode(
|
|
165
|
+
keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>
|
|
166
|
+
): keyOrNodeOrEntryOrRawElement is NODE {
|
|
167
|
+
return keyOrNodeOrEntryOrRawElement instanceof AVLTreeMultiMapNode;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
172
|
+
* a node object.
|
|
173
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
174
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
175
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
176
|
+
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
177
|
+
* value is provided, it will default to `undefined`.
|
|
145
178
|
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
146
|
-
* times the value should be added to the
|
|
147
|
-
* @returns a
|
|
179
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
180
|
+
* @returns either a NODE object or undefined.
|
|
148
181
|
*/
|
|
149
|
-
override
|
|
150
|
-
|
|
182
|
+
override keyValueOrEntryOrRawElementToNode(
|
|
183
|
+
keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>,
|
|
151
184
|
value?: V,
|
|
152
185
|
count = 1
|
|
153
186
|
): NODE | undefined {
|
|
154
|
-
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const [key, value] = keyOrNodeOrEntry;
|
|
161
|
-
if (key === undefined || key === null) {
|
|
162
|
-
return;
|
|
163
|
-
} else {
|
|
164
|
-
node = this.createNode(key, value, count);
|
|
165
|
-
}
|
|
166
|
-
} else if (!this.isNode(keyOrNodeOrEntry)) {
|
|
167
|
-
node = this.createNode(keyOrNodeOrEntry, value, count);
|
|
168
|
-
} else {
|
|
169
|
-
return;
|
|
187
|
+
if (keyOrNodeOrEntryOrRawElement === undefined || keyOrNodeOrEntryOrRawElement === null) return;
|
|
188
|
+
if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
|
|
189
|
+
|
|
190
|
+
if (this.toEntryFn) {
|
|
191
|
+
const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
|
|
192
|
+
if (key) return this.createNode(key, entryValue ?? value, count);
|
|
170
193
|
}
|
|
171
|
-
return node;
|
|
172
|
-
}
|
|
173
194
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
195
|
+
if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
|
|
196
|
+
const [key, value] = keyOrNodeOrEntryOrRawElement;
|
|
197
|
+
if (key === undefined || key === null) return;
|
|
198
|
+
else return this.createNode(key, value, count);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (this.isKey(keyOrNodeOrEntryOrRawElement)) return this.createNode(keyOrNodeOrEntryOrRawElement, value, count);
|
|
202
|
+
|
|
203
|
+
return;
|
|
182
204
|
}
|
|
183
205
|
|
|
184
206
|
/**
|
|
@@ -190,20 +212,21 @@ export class AVLTreeMultiMap<
|
|
|
190
212
|
* Time Complexity: O(log n)
|
|
191
213
|
* Space Complexity: O(1)
|
|
192
214
|
*
|
|
193
|
-
* The function overrides the add method of a
|
|
194
|
-
*
|
|
195
|
-
*
|
|
215
|
+
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
216
|
+
* and update the count.
|
|
217
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
218
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
|
|
219
|
+
* can also accept a value of type `KeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
220
|
+
* entry, or raw element
|
|
196
221
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
197
|
-
*
|
|
198
|
-
* method.
|
|
222
|
+
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
199
223
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
200
|
-
* be added to the
|
|
201
|
-
* added once. However, you can specify a different value for `count` if you want to add
|
|
202
|
-
* @returns
|
|
203
|
-
* was not successful.
|
|
224
|
+
* be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
|
|
225
|
+
* be added once. However, you can specify a different value for `count` if you want to add
|
|
226
|
+
* @returns a boolean value.
|
|
204
227
|
*/
|
|
205
|
-
override add(
|
|
206
|
-
const newNode = this.
|
|
228
|
+
override add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count = 1): boolean {
|
|
229
|
+
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
|
|
207
230
|
if (newNode === undefined) return false;
|
|
208
231
|
|
|
209
232
|
const orgNodeCount = newNode?.count || 0;
|
|
@@ -223,19 +246,19 @@ export class AVLTreeMultiMap<
|
|
|
223
246
|
* Time Complexity: O(log n)
|
|
224
247
|
* Space Complexity: O(1)
|
|
225
248
|
*
|
|
226
|
-
* The `delete` function in
|
|
227
|
-
*
|
|
228
|
-
* @param identifier - The identifier is the value
|
|
229
|
-
*
|
|
249
|
+
* The `delete` function in a binary tree data structure deletes a node based on its identifier and
|
|
250
|
+
* returns the deleted node along with the parent node that needs to be balanced.
|
|
251
|
+
* @param identifier - The identifier parameter is the value used to identify the node that needs to
|
|
252
|
+
* be deleted from the binary tree. It can be of any type and is the return type of the callback
|
|
230
253
|
* function.
|
|
231
|
-
* @param {C} callback - The `callback` parameter is a function that is used to determine
|
|
232
|
-
*
|
|
233
|
-
* function takes
|
|
234
|
-
*
|
|
254
|
+
* @param {C} callback - The `callback` parameter is a function that is used to determine the
|
|
255
|
+
* equality of nodes in the binary tree. It is optional and has a default value of
|
|
256
|
+
* `this._DEFAULT_CALLBACK`. The `callback` function takes a single argument, which is the identifier
|
|
257
|
+
* of a node, and returns a value that
|
|
235
258
|
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
|
|
236
259
|
* being deleted. If set to true, the count of the node will not be considered and the node will be
|
|
237
|
-
* deleted regardless of its count. If set to false (default), the count of the node will be
|
|
238
|
-
*
|
|
260
|
+
* deleted regardless of its count. If set to false (default), the count of the node will be taken
|
|
261
|
+
* into account and the node
|
|
239
262
|
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
|
|
240
263
|
*/
|
|
241
264
|
override delete<C extends BTNCallback<NODE>>(
|
|
@@ -308,7 +331,8 @@ export class AVLTreeMultiMap<
|
|
|
308
331
|
* Time Complexity: O(1)
|
|
309
332
|
* Space Complexity: O(1)
|
|
310
333
|
*
|
|
311
|
-
* The clear
|
|
334
|
+
* The "clear" function overrides the parent class's "clear" function and also resets the count to
|
|
335
|
+
* zero.
|
|
312
336
|
*/
|
|
313
337
|
override clear() {
|
|
314
338
|
super.clear();
|
|
@@ -323,13 +347,14 @@ export class AVLTreeMultiMap<
|
|
|
323
347
|
/**
|
|
324
348
|
* Time Complexity: O(n log n)
|
|
325
349
|
* Space Complexity: O(log n)
|
|
326
|
-
*
|
|
327
350
|
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
328
351
|
* tree using either a recursive or iterative approach.
|
|
329
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that
|
|
330
|
-
* type of iteration to use when building the balanced binary search tree. It
|
|
331
|
-
*
|
|
332
|
-
*
|
|
352
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
353
|
+
* specifies the type of iteration to use when building the balanced binary search tree. It has a
|
|
354
|
+
* default value of `this.iterationType`, which means it will use the iteration type currently set in
|
|
355
|
+
* the object.
|
|
356
|
+
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
357
|
+
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
333
358
|
*/
|
|
334
359
|
override perfectlyBalance(iterationType: IterationType = this.iterationType): boolean {
|
|
335
360
|
const sorted = this.dfs(node => node, 'IN'),
|
|
@@ -378,7 +403,7 @@ export class AVLTreeMultiMap<
|
|
|
378
403
|
* Time complexity: O(n)
|
|
379
404
|
* Space complexity: O(n)
|
|
380
405
|
*
|
|
381
|
-
* The
|
|
406
|
+
* The function overrides the clone method to create a deep copy of a tree object.
|
|
382
407
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
383
408
|
*/
|
|
384
409
|
override clone(): TREE {
|
|
@@ -388,17 +413,26 @@ export class AVLTreeMultiMap<
|
|
|
388
413
|
}
|
|
389
414
|
|
|
390
415
|
/**
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
*
|
|
397
|
-
*
|
|
416
|
+
* Time Complexity: O(1)
|
|
417
|
+
* Space Complexity: O(1)
|
|
418
|
+
*/
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Time Complexity: O(1)
|
|
422
|
+
* Space Complexity: O(1)
|
|
423
|
+
*
|
|
424
|
+
* The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
|
|
425
|
+
* in a binary search tree.
|
|
426
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
|
|
427
|
+
* that will be swapped with the `destNode`.
|
|
428
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
|
|
429
|
+
* node where the properties will be swapped with the source node.
|
|
430
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
431
|
+
* If either `srcNode` or `destNode` is undefined, it returns `undefined`.
|
|
398
432
|
*/
|
|
399
433
|
protected override _swapProperties(
|
|
400
|
-
srcNode: BSTNKeyOrNode<K, NODE>,
|
|
401
|
-
destNode: BSTNKeyOrNode<K, NODE>
|
|
434
|
+
srcNode: R | BSTNKeyOrNode<K, NODE>,
|
|
435
|
+
destNode: R | BSTNKeyOrNode<K, NODE>
|
|
402
436
|
): NODE | undefined {
|
|
403
437
|
srcNode = this.ensureNode(srcNode);
|
|
404
438
|
destNode = this.ensureNode(destNode);
|
|
@@ -425,12 +459,20 @@ export class AVLTreeMultiMap<
|
|
|
425
459
|
}
|
|
426
460
|
|
|
427
461
|
/**
|
|
462
|
+
* Time Complexity: O(1)
|
|
463
|
+
* Space Complexity: O(1)
|
|
464
|
+
*/
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Time Complexity: O(1)
|
|
468
|
+
* Space Complexity: O(1)
|
|
469
|
+
*
|
|
428
470
|
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
429
|
-
* @param {NODE} oldNode - The
|
|
430
|
-
*
|
|
431
|
-
* @param {NODE} newNode - The `newNode` parameter is an
|
|
471
|
+
* @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
472
|
+
* data structure. It is of type NODE.
|
|
473
|
+
* @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
|
|
432
474
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
433
|
-
* superclass,
|
|
475
|
+
* superclass, which is of type `NODE`.
|
|
434
476
|
*/
|
|
435
477
|
protected override _replaceNode(oldNode: NODE, newNode: NODE): NODE {
|
|
436
478
|
newNode.count = oldNode.count + newNode.count;
|