graph-typed 1.51.5 → 1.51.8
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 +3 -12
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +2 -10
- package/dist/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/avl-tree.js +12 -14
- package/dist/data-structures/binary-tree/binary-tree.d.ts +7 -13
- package/dist/data-structures/binary-tree/binary-tree.js +46 -78
- package/dist/data-structures/binary-tree/bst.d.ts +51 -96
- package/dist/data-structures/binary-tree/bst.js +120 -218
- package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -4
- package/dist/data-structures/binary-tree/rb-tree.js +4 -2
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/data-structures/binary-tree/tree-multi-map.js +1 -0
- package/dist/data-structures/heap/heap.d.ts +1 -3
- package/dist/interfaces/binary-tree.d.ts +3 -3
- package/dist/types/common.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- 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 +3 -2
- package/dist/types/utils/utils.d.ts +10 -1
- package/dist/utils/utils.d.ts +2 -1
- package/dist/utils/utils.js +29 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +5 -12
- package/src/data-structures/binary-tree/avl-tree.ts +15 -15
- package/src/data-structures/binary-tree/binary-tree.ts +56 -76
- package/src/data-structures/binary-tree/bst.ts +132 -224
- package/src/data-structures/binary-tree/rb-tree.ts +9 -6
- package/src/data-structures/binary-tree/tree-multi-map.ts +5 -3
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/interfaces/binary-tree.ts +4 -3
- package/src/types/common.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -2
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +5 -5
- 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 +3 -2
- package/src/types/utils/utils.ts +14 -1
- package/src/utils/utils.ts +20 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AVLTree, AVLTreeNode } from '../../../data-structures';
|
|
2
2
|
import { BSTOptions } from './bst';
|
|
3
|
-
|
|
4
|
-
export type
|
|
3
|
+
import { Comparable } from "../../utils";
|
|
4
|
+
export type AVLTreeNodeNested<K extends Comparable, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type AVLTreeNested<K extends Comparable, V, N extends AVLTreeNode<K, V, N>> = AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
6
|
export type AVLTreeOptions<K> = BSTOptions<K> & {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
2
|
import { IterationType } from "../../common";
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
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, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type BinaryTreeOptions = {
|
|
6
7
|
iterationType?: IterationType;
|
|
7
|
-
extractor?: (key: K) => number;
|
|
8
8
|
};
|
|
@@ -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, N extends BSTNode<K, V, N>> = BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
7
|
+
export type BSTOptions<K> = BinaryTreeOptions & {
|
|
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, N extends RedBlackTreeNode<K, V, N>> = RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
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, N extends RedBlackTreeNode<K, V, N>> = RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
7
|
+
export type RBTreeOptions<K> = BSTOptions<K> & {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TreeMultiMap, TreeMultiMapNode } from '../../../data-structures';
|
|
2
2
|
import type { RBTreeOptions } from './rb-tree';
|
|
3
|
-
|
|
4
|
-
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, N extends TreeMultiMapNode<K, V, N>> = TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
6
|
export type TreeMultiMapOptions<K> = RBTreeOptions<K> & {};
|
|
@@ -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,31 @@ 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')
|
|
115
|
+
return isComparable(key.valueOf());
|
|
116
|
+
if (typeof key.toString === 'function')
|
|
117
|
+
return isComparable(key.toString());
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
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.8",
|
|
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.8"
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
BinaryTreeDeleteResult,
|
|
13
13
|
BSTNKeyOrNode,
|
|
14
14
|
BTNCallback,
|
|
15
|
+
Comparable,
|
|
15
16
|
IterationType,
|
|
16
17
|
KeyOrNodeOrEntry
|
|
17
18
|
} from '../../types';
|
|
@@ -19,7 +20,7 @@ import { IBinaryTree } from '../../interfaces';
|
|
|
19
20
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
20
21
|
|
|
21
22
|
export class AVLTreeMultiMapNode<
|
|
22
|
-
K
|
|
23
|
+
K extends Comparable,
|
|
23
24
|
V = any,
|
|
24
25
|
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>
|
|
25
26
|
> extends AVLTreeNode<K, V, NODE> {
|
|
@@ -62,7 +63,7 @@ export class AVLTreeMultiMapNode<
|
|
|
62
63
|
* 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
64
|
*/
|
|
64
65
|
export class AVLTreeMultiMap<
|
|
65
|
-
K
|
|
66
|
+
K extends Comparable,
|
|
66
67
|
V = any,
|
|
67
68
|
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
|
|
68
69
|
TREE extends AVLTreeMultiMap<K, V, NODE, TREE> = AVLTreeMultiMap<K, V, NODE, AVLTreeMultiMapNested<K, V, NODE>>
|
|
@@ -118,19 +119,10 @@ export class AVLTreeMultiMap<
|
|
|
118
119
|
return new AVLTreeMultiMapNode(key, value, count) as NODE;
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
/**
|
|
122
|
-
* The function creates a new AVLTreeMultiMap object with the specified options and returns it.
|
|
123
|
-
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
124
|
-
* configuration options for creating the `AVLTreeMultiMap` object. It can include properties such as
|
|
125
|
-
* `iterationType` and `variant`, which are used to specify the type of iteration and the variant of
|
|
126
|
-
* the tree, respectively. These properties can be
|
|
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`.
|
|
129
|
-
*/
|
|
130
122
|
override createTree(options?: AVLTreeMultiMapOptions<K>): TREE {
|
|
131
123
|
return new AVLTreeMultiMap<K, V, NODE, TREE>([], {
|
|
132
124
|
iterationType: this.iterationType,
|
|
133
|
-
|
|
125
|
+
comparator: this.comparator,
|
|
134
126
|
...options
|
|
135
127
|
}) as TREE;
|
|
136
128
|
}
|
|
@@ -245,6 +237,7 @@ export class AVLTreeMultiMap<
|
|
|
245
237
|
): BinaryTreeDeleteResult<NODE>[] {
|
|
246
238
|
const deletedResult: BinaryTreeDeleteResult<NODE>[] = [];
|
|
247
239
|
if (!this.root) return deletedResult;
|
|
240
|
+
callback = this._ensureCallback(identifier, callback);
|
|
248
241
|
|
|
249
242
|
const curr: NODE | undefined = this.getNode(identifier, callback) ?? undefined;
|
|
250
243
|
if (!curr) return deletedResult;
|
|
@@ -13,12 +13,13 @@ import type {
|
|
|
13
13
|
BinaryTreeDeleteResult,
|
|
14
14
|
BSTNKeyOrNode,
|
|
15
15
|
BTNCallback,
|
|
16
|
+
Comparable,
|
|
16
17
|
KeyOrNodeOrEntry
|
|
17
18
|
} from '../../types';
|
|
18
19
|
import { IBinaryTree } from '../../interfaces';
|
|
19
20
|
|
|
20
21
|
export class AVLTreeNode<
|
|
21
|
-
K
|
|
22
|
+
K extends Comparable,
|
|
22
23
|
V = any,
|
|
23
24
|
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>
|
|
24
25
|
> extends BSTNode<K, V, NODE> {
|
|
@@ -65,7 +66,7 @@ export class AVLTreeNode<
|
|
|
65
66
|
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
|
|
66
67
|
*/
|
|
67
68
|
export class AVLTree<
|
|
68
|
-
K
|
|
69
|
+
K extends Comparable,
|
|
69
70
|
V = any,
|
|
70
71
|
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>,
|
|
71
72
|
TREE extends AVLTree<K, V, NODE, TREE> = AVLTree<K, V, NODE, AVLTreeNested<K, V, NODE>>
|
|
@@ -109,7 +110,7 @@ export class AVLTree<
|
|
|
109
110
|
override createTree(options?: AVLTreeOptions<K>): TREE {
|
|
110
111
|
return new AVLTree<K, V, NODE, TREE>([], {
|
|
111
112
|
iterationType: this.iterationType,
|
|
112
|
-
|
|
113
|
+
comparator: this.comparator,
|
|
113
114
|
...options
|
|
114
115
|
}) as TREE;
|
|
115
116
|
}
|
|
@@ -172,7 +173,6 @@ export class AVLTree<
|
|
|
172
173
|
identifier: ReturnType<C>,
|
|
173
174
|
callback: C = this._DEFAULT_CALLBACK as C
|
|
174
175
|
): BinaryTreeDeleteResult<NODE>[] {
|
|
175
|
-
if ((identifier as any) instanceof AVLTreeNode) callback = (node => node) as C;
|
|
176
176
|
const deletedResults = super.delete(identifier, callback);
|
|
177
177
|
for (const { needBalanced } of deletedResults) {
|
|
178
178
|
if (needBalanced) {
|
|
@@ -196,26 +196,26 @@ export class AVLTree<
|
|
|
196
196
|
srcNode: BSTNKeyOrNode<K, NODE>,
|
|
197
197
|
destNode: BSTNKeyOrNode<K, NODE>
|
|
198
198
|
): NODE | undefined {
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
const srcNodeEnsured = this.ensureNode(srcNode);
|
|
200
|
+
const destNodeEnsured = this.ensureNode(destNode);
|
|
201
201
|
|
|
202
|
-
if (
|
|
203
|
-
const { key, value, height } =
|
|
202
|
+
if (srcNodeEnsured && destNodeEnsured) {
|
|
203
|
+
const { key, value, height } = destNodeEnsured;
|
|
204
204
|
const tempNode = this.createNode(key, value);
|
|
205
205
|
|
|
206
206
|
if (tempNode) {
|
|
207
207
|
tempNode.height = height;
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
destNodeEnsured.key = srcNodeEnsured.key;
|
|
210
|
+
destNodeEnsured.value = srcNodeEnsured.value;
|
|
211
|
+
destNodeEnsured.height = srcNodeEnsured.height;
|
|
212
212
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
srcNodeEnsured.key = tempNode.key;
|
|
214
|
+
srcNodeEnsured.value = tempNode.value;
|
|
215
|
+
srcNodeEnsured.height = tempNode.height;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
return
|
|
218
|
+
return destNodeEnsured;
|
|
219
219
|
}
|
|
220
220
|
return undefined;
|
|
221
221
|
}
|