data-structure-typed 1.52.5 → 1.52.7
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/CHANGELOG.md +1 -1
- package/README.md +33 -30
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +156 -156
- package/dist/cjs/constants/index.d.ts +4 -0
- package/dist/cjs/constants/index.js +9 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +8 -1
- package/dist/cjs/data-structures/base/iterable-element-base.js +10 -1
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +8 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.js +10 -10
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +71 -64
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +669 -598
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +72 -65
- package/dist/cjs/data-structures/binary-tree/bst.js +115 -113
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +40 -39
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +44 -43
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/abstract-graph.js +7 -4
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js +4 -2
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js +3 -3
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +7 -7
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +6 -6
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/matrix.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/navigator.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/navigator.js +4 -2
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +3 -3
- package/dist/cjs/data-structures/queue/deque.js +29 -29
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +2 -2
- package/dist/cjs/data-structures/tree/tree.js +2 -0
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +2 -2
- package/dist/cjs/data-structures/trie/trie.js +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -6
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/mjs/constants/index.d.ts +4 -0
- package/dist/mjs/constants/index.js +5 -0
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +8 -1
- package/dist/mjs/data-structures/base/iterable-element-base.js +10 -1
- package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +8 -1
- package/dist/mjs/data-structures/base/iterable-entry-base.js +10 -10
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +44 -44
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +72 -64
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +668 -592
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +72 -65
- package/dist/mjs/data-structures/binary-tree/bst.js +116 -112
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +41 -38
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +45 -42
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/abstract-graph.js +7 -4
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/directed-graph.js +4 -2
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/mjs/data-structures/hash/hash-map.js +1 -1
- package/dist/mjs/data-structures/heap/heap.js +3 -3
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +7 -7
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +6 -6
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/navigator.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/navigator.js +4 -2
- package/dist/mjs/data-structures/queue/deque.d.ts +3 -3
- package/dist/mjs/data-structures/queue/deque.js +29 -29
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/stack/stack.d.ts +2 -2
- package/dist/mjs/data-structures/tree/tree.js +2 -0
- package/dist/mjs/data-structures/trie/trie.d.ts +2 -2
- package/dist/mjs/data-structures/trie/trie.js +1 -1
- package/dist/mjs/index.d.ts +1 -0
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -5
- package/dist/umd/data-structure-typed.js +1344 -1614
- package/dist/umd/data-structure-typed.min.js +10 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/eslint.config.mjs +69 -0
- package/package.json +30 -28
- package/src/constants/index.ts +4 -0
- package/src/data-structures/base/iterable-element-base.ts +11 -1
- package/src/data-structures/base/iterable-entry-base.ts +11 -19
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
- package/src/data-structures/binary-tree/avl-tree.ts +69 -71
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +698 -726
- package/src/data-structures/binary-tree/bst.ts +123 -129
- package/src/data-structures/binary-tree/rb-tree.ts +44 -46
- package/src/data-structures/binary-tree/segment-tree.ts +2 -2
- package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +4 -4
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +3 -3
- package/src/data-structures/heap/heap.ts +3 -3
- package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/navigator.ts +4 -4
- package/src/data-structures/queue/deque.ts +31 -31
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/stack/stack.ts +2 -2
- package/src/data-structures/trie/trie.ts +3 -3
- package/src/index.ts +1 -0
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
- package/test/config.ts +1 -7
- package/test/integration/all-in-one.test.ts +2 -2
- package/test/integration/avl-tree.test.ts +3 -3
- package/test/integration/bst.test.ts +19 -18
- package/test/integration/heap.test.js +6 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +39 -39
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +140 -112
- package/test/unit/data-structures/binary-tree/bst.test.ts +41 -13
- package/test/unit/data-structures/binary-tree/overall.test.ts +0 -6
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +88 -34
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +42 -42
- package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/undirected-graph.test.ts +14 -2
- package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
- package/test/unit/data-structures/stack/stack.test.ts +6 -0
- package/test/unit/unrestricted-interconversion.test.ts +24 -24
- package/test/utils/big-o.ts +5 -4
- package/.eslintrc.js +0 -64
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
|
2
|
+
import _import from "eslint-plugin-import";
|
|
3
|
+
import { fixupPluginRules } from "@eslint/compat";
|
|
4
|
+
import tsParser from "@typescript-eslint/parser";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import js from "@eslint/js";
|
|
8
|
+
import { FlatCompat } from "@eslint/eslintrc";
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
const compat = new FlatCompat({
|
|
13
|
+
baseDirectory: __dirname,
|
|
14
|
+
recommendedConfig: js.configs.recommended,
|
|
15
|
+
allConfig: js.configs.all
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export default [{
|
|
19
|
+
ignores: ["**/lib/", "**/dist/", "**/umd/", "**/coverage/", "**/docs/"],
|
|
20
|
+
}, ...compat.extends("plugin:@typescript-eslint/recommended", "prettier"), {
|
|
21
|
+
plugins: {
|
|
22
|
+
"@typescript-eslint": typescriptEslint,
|
|
23
|
+
import: fixupPluginRules(_import),
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
languageOptions: {
|
|
27
|
+
parser: tsParser,
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
settings: {
|
|
31
|
+
"import/parsers": {
|
|
32
|
+
"@typescript-eslint/parser": [".ts"],
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
"import/resolver": {
|
|
36
|
+
typescript: {
|
|
37
|
+
alwaysTryTypes: true,
|
|
38
|
+
project: ["./tsconfig.json"],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
rules: {
|
|
44
|
+
"import/no-anonymous-default-export": "off",
|
|
45
|
+
"@typescript-eslint/no-unused-vars": "warn",
|
|
46
|
+
"@typescript-eslint/ban-ts-comment": "off",
|
|
47
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
48
|
+
"@typescript-eslint/no-var-requires": "off",
|
|
49
|
+
"@typescript-eslint/no-non-null-assertion": "off",
|
|
50
|
+
"@typescript-eslint/no-require-imports": "off",
|
|
51
|
+
"lines-around-comment": ["warn", {
|
|
52
|
+
beforeLineComment: false,
|
|
53
|
+
beforeBlockComment: true,
|
|
54
|
+
allowBlockStart: true,
|
|
55
|
+
allowClassStart: true,
|
|
56
|
+
allowObjectStart: true,
|
|
57
|
+
allowArrayStart: true,
|
|
58
|
+
}],
|
|
59
|
+
|
|
60
|
+
"newline-before-return": "off",
|
|
61
|
+
|
|
62
|
+
"import/newline-after-import": ["warn", {
|
|
63
|
+
count: 1,
|
|
64
|
+
}],
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
"object-curly-spacing": ["warn", "always"],
|
|
68
|
+
},
|
|
69
|
+
}];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.52.
|
|
3
|
+
"version": "1.52.7",
|
|
4
4
|
"description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/mjs/index.js",
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"import": "./dist/mjs/index.js",
|
|
12
|
-
"require": "./dist/cjs/index.js"
|
|
13
|
-
"types": "./dist/mjs/index.d.ts"
|
|
12
|
+
"require": "./dist/cjs/index.js"
|
|
14
13
|
}
|
|
15
14
|
},
|
|
16
15
|
"scripts": {
|
|
@@ -59,37 +58,40 @@
|
|
|
59
58
|
"@zrwusa:registry": "https://npm.pkg.github.com"
|
|
60
59
|
},
|
|
61
60
|
"devDependencies": {
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"@
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
67
|
-
"@
|
|
68
|
-
"
|
|
69
|
-
"
|
|
61
|
+
"@eslint/compat": "^1.2.2",
|
|
62
|
+
"@eslint/eslintrc": "^3.1.0",
|
|
63
|
+
"@eslint/js": "^9.13.0",
|
|
64
|
+
"@swc/core": "^1.7.40",
|
|
65
|
+
"@types/benchmark": "^2.1.5",
|
|
66
|
+
"@types/jest": "^29.5.14",
|
|
67
|
+
"@types/node": "^22.8.2",
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^8.12.1",
|
|
69
|
+
"@typescript-eslint/parser": "^8.12.1",
|
|
70
|
+
"auto-changelog": "^2.5.0",
|
|
71
|
+
"avl-tree-typed": "^1.52.6",
|
|
70
72
|
"benchmark": "^2.1.4",
|
|
71
|
-
"binary-tree-typed": "^1.52.
|
|
72
|
-
"bst-typed": "^1.52.
|
|
73
|
-
"data-structure-typed": "^1.52.
|
|
74
|
-
"dependency-cruiser": "^
|
|
73
|
+
"binary-tree-typed": "^1.52.6",
|
|
74
|
+
"bst-typed": "^1.52.6",
|
|
75
|
+
"data-structure-typed": "^1.52.6",
|
|
76
|
+
"dependency-cruiser": "^16.5.0",
|
|
75
77
|
"doctoc": "^2.2.1",
|
|
76
|
-
"eslint": "^
|
|
77
|
-
"eslint-config-prettier": "^9.
|
|
78
|
+
"eslint": "^9.13.0",
|
|
79
|
+
"eslint-config-prettier": "^9.1.0",
|
|
78
80
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
79
|
-
"eslint-import-resolver-typescript": "^3.6.
|
|
80
|
-
"eslint-plugin-import": "^2.
|
|
81
|
-
"fast-glob": "^3.3.
|
|
82
|
-
"heap-typed": "^1.52.
|
|
83
|
-
"istanbul-badges-readme": "^1.
|
|
81
|
+
"eslint-import-resolver-typescript": "^3.6.3",
|
|
82
|
+
"eslint-plugin-import": "^2.31.0",
|
|
83
|
+
"fast-glob": "^3.3.2",
|
|
84
|
+
"heap-typed": "^1.52.6",
|
|
85
|
+
"istanbul-badges-readme": "^1.9.0",
|
|
84
86
|
"jest": "^29.7.0",
|
|
85
87
|
"js-sdsl": "^4.4.2",
|
|
86
88
|
"prettier": "^3.3.3",
|
|
87
|
-
"ts-jest": "^29.
|
|
88
|
-
"ts-loader": "^9.
|
|
89
|
-
"ts-node": "^10.9.
|
|
90
|
-
"tsup": "^
|
|
91
|
-
"typedoc": "^0.26.
|
|
92
|
-
"typescript": "^5.3
|
|
89
|
+
"ts-jest": "^29.2.5",
|
|
90
|
+
"ts-loader": "^9.5.1",
|
|
91
|
+
"ts-node": "^10.9.2",
|
|
92
|
+
"tsup": "^8.3.5",
|
|
93
|
+
"typedoc": "^0.26.10",
|
|
94
|
+
"typescript": "^5.6.3"
|
|
93
95
|
},
|
|
94
96
|
"keywords": [
|
|
95
97
|
"data",
|
|
@@ -192,10 +192,20 @@ export abstract class IterableElementBase<E, R, C> {
|
|
|
192
192
|
*
|
|
193
193
|
* The print function logs the elements of an array to the console.
|
|
194
194
|
*/
|
|
195
|
-
|
|
195
|
+
toVisual(): E[] {
|
|
196
196
|
return [...this];
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
/**
|
|
200
|
+
* Time Complexity: O(n)
|
|
201
|
+
* Space Complexity: O(n)
|
|
202
|
+
*
|
|
203
|
+
* The print function logs the elements of an array to the console.
|
|
204
|
+
*/
|
|
205
|
+
print(): void {
|
|
206
|
+
console.log(this.toVisual());
|
|
207
|
+
}
|
|
208
|
+
|
|
199
209
|
abstract isEmpty(): boolean;
|
|
200
210
|
|
|
201
211
|
abstract clear(): void;
|
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
import { EntryCallback, ReduceEntryCallback } from '../../types';
|
|
2
2
|
|
|
3
3
|
export abstract class IterableEntryBase<K = any, V = any> {
|
|
4
|
-
// protected constructor(options?: IterableEntryBaseOptions<K, V, R>) {
|
|
5
|
-
// if (options) {
|
|
6
|
-
// const { toEntryFn } = options;
|
|
7
|
-
// if (typeof toEntryFn === 'function') this._toEntryFn = toEntryFn
|
|
8
|
-
// else throw new TypeError('toEntryFn must be a function type');
|
|
9
|
-
// }
|
|
10
|
-
// }
|
|
11
|
-
|
|
12
4
|
abstract get size(): number;
|
|
13
5
|
|
|
14
|
-
// protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
15
|
-
//
|
|
16
|
-
// /**
|
|
17
|
-
// * The function returns the value of the _toEntryFn property.
|
|
18
|
-
// * @returns The function being returned is `this._toEntryFn`.
|
|
19
|
-
// */
|
|
20
|
-
// get toEntryFn() {
|
|
21
|
-
// return this._toEntryFn;
|
|
22
|
-
// }
|
|
23
|
-
|
|
24
6
|
/**
|
|
25
7
|
* Time Complexity: O(n)
|
|
26
8
|
* Space Complexity: O(1)
|
|
@@ -251,10 +233,20 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
251
233
|
*
|
|
252
234
|
* The print function logs the elements of an array to the console.
|
|
253
235
|
*/
|
|
254
|
-
|
|
236
|
+
toVisual(): [K, V][] | string {
|
|
255
237
|
return [...this];
|
|
256
238
|
}
|
|
257
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Time Complexity: O(n)
|
|
242
|
+
* Space Complexity: O(n)
|
|
243
|
+
*
|
|
244
|
+
* The print function logs the elements of an array to the console.
|
|
245
|
+
*/
|
|
246
|
+
print(): void {
|
|
247
|
+
console.log(this.toVisual());
|
|
248
|
+
}
|
|
249
|
+
|
|
258
250
|
abstract isEmpty(): boolean;
|
|
259
251
|
|
|
260
252
|
abstract clear(): void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type {
|
|
@@ -11,11 +11,11 @@ import type {
|
|
|
11
11
|
AVLTreeMultiMapOptions,
|
|
12
12
|
BinaryTreeDeleteResult,
|
|
13
13
|
BSTNKeyOrNode,
|
|
14
|
-
BTNCallback,
|
|
15
14
|
BTNKeyOrNodeOrEntry,
|
|
16
|
-
|
|
15
|
+
BTNPredicate,
|
|
16
|
+
IterationType,
|
|
17
|
+
BTNEntry
|
|
17
18
|
} from '../../types';
|
|
18
|
-
import { BTNEntry } from '../../types';
|
|
19
19
|
import { IBinaryTree } from '../../interfaces';
|
|
20
20
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
21
21
|
|
|
@@ -80,18 +80,18 @@ export class AVLTreeMultiMap<
|
|
|
80
80
|
{
|
|
81
81
|
/**
|
|
82
82
|
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
83
|
-
* @param
|
|
83
|
+
* @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
|
|
84
84
|
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
85
85
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
86
86
|
* behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
|
|
87
87
|
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
88
88
|
*/
|
|
89
89
|
constructor(
|
|
90
|
-
|
|
90
|
+
keysOrNodesOrEntriesOrRaws: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
|
|
91
91
|
options?: AVLTreeMultiMapOptions<K, V, R>
|
|
92
92
|
) {
|
|
93
93
|
super([], options);
|
|
94
|
-
if (
|
|
94
|
+
if (keysOrNodesOrEntriesOrRaws) this.addMany(keysOrNodesOrEntriesOrRaws);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
protected _count = 0;
|
|
@@ -144,29 +144,28 @@ export class AVLTreeMultiMap<
|
|
|
144
144
|
override createTree(options?: AVLTreeMultiMapOptions<K, V, R>): TREE {
|
|
145
145
|
return new AVLTreeMultiMap<K, V, R, NODE, TREE>([], {
|
|
146
146
|
iterationType: this.iterationType,
|
|
147
|
-
comparator: this.
|
|
147
|
+
comparator: this._comparator,
|
|
148
|
+
toEntryFn: this._toEntryFn,
|
|
148
149
|
...options
|
|
149
150
|
}) as TREE;
|
|
150
151
|
}
|
|
151
152
|
|
|
152
153
|
/**
|
|
153
154
|
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
154
|
-
* @param {
|
|
155
|
-
* `
|
|
156
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
155
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
156
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
157
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
|
|
157
158
|
* an instance of the `AVLTreeMultiMapNode` class.
|
|
158
159
|
*/
|
|
159
|
-
override isNode(
|
|
160
|
-
|
|
161
|
-
): keyOrNodeOrEntryOrRawElement is NODE {
|
|
162
|
-
return keyOrNodeOrEntryOrRawElement instanceof AVLTreeMultiMapNode;
|
|
160
|
+
override isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE {
|
|
161
|
+
return keyOrNodeOrEntryOrRaw instanceof AVLTreeMultiMapNode;
|
|
163
162
|
}
|
|
164
163
|
|
|
165
164
|
/**
|
|
166
165
|
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
167
166
|
* a node object.
|
|
168
|
-
* @param {
|
|
169
|
-
* `
|
|
167
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
|
|
168
|
+
* `keyOrNodeOrEntryOrRaw` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
170
169
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
171
170
|
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
172
171
|
* value is provided, it will default to `undefined`.
|
|
@@ -175,25 +174,25 @@ export class AVLTreeMultiMap<
|
|
|
175
174
|
* @returns either a NODE object or undefined.
|
|
176
175
|
*/
|
|
177
176
|
override keyValueOrEntryOrRawElementToNode(
|
|
178
|
-
|
|
177
|
+
keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
|
|
179
178
|
value?: V,
|
|
180
179
|
count = 1
|
|
181
180
|
): NODE | undefined {
|
|
182
|
-
if (
|
|
183
|
-
if (this.isNode(
|
|
181
|
+
if (keyOrNodeOrEntryOrRaw === undefined || keyOrNodeOrEntryOrRaw === null) return;
|
|
182
|
+
if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
|
|
184
183
|
|
|
185
|
-
if (this.isEntry(
|
|
186
|
-
const [key, entryValue] =
|
|
184
|
+
if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
|
|
185
|
+
const [key, entryValue] = keyOrNodeOrEntryOrRaw;
|
|
187
186
|
if (key === undefined || key === null) return;
|
|
188
187
|
if (this.isKey(key)) return this.createNode(key, value ?? entryValue, count);
|
|
189
188
|
}
|
|
190
189
|
|
|
191
|
-
if (this.
|
|
192
|
-
const [key, entryValue] = this.
|
|
190
|
+
if (this._toEntryFn) {
|
|
191
|
+
const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw as R);
|
|
193
192
|
if (this.isKey(key)) return this.createNode(key, value ?? entryValue, count);
|
|
194
193
|
}
|
|
195
194
|
|
|
196
|
-
if (this.isKey(
|
|
195
|
+
if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, count);
|
|
197
196
|
|
|
198
197
|
return;
|
|
199
198
|
}
|
|
@@ -204,8 +203,8 @@ export class AVLTreeMultiMap<
|
|
|
204
203
|
*
|
|
205
204
|
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
206
205
|
* and update the count.
|
|
207
|
-
* @param {
|
|
208
|
-
* `
|
|
206
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
|
|
207
|
+
* `keyOrNodeOrEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
|
|
209
208
|
* can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
210
209
|
* entry, or raw element
|
|
211
210
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
@@ -215,8 +214,8 @@ export class AVLTreeMultiMap<
|
|
|
215
214
|
* be added once. However, you can specify a different value for `count` if you want to add
|
|
216
215
|
* @returns a boolean value.
|
|
217
216
|
*/
|
|
218
|
-
override add(
|
|
219
|
-
const newNode = this.keyValueOrEntryOrRawElementToNode(
|
|
217
|
+
override add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count = 1): boolean {
|
|
218
|
+
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
|
|
220
219
|
if (newNode === undefined) return false;
|
|
221
220
|
|
|
222
221
|
const orgNodeCount = newNode?.count || 0;
|
|
@@ -231,31 +230,29 @@ export class AVLTreeMultiMap<
|
|
|
231
230
|
* Time Complexity: O(log n)
|
|
232
231
|
* Space Complexity: O(1)
|
|
233
232
|
*
|
|
234
|
-
* The
|
|
235
|
-
*
|
|
236
|
-
* @param
|
|
237
|
-
*
|
|
238
|
-
* function
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
233
|
+
* The function overrides the delete method in a binary tree data structure, handling deletion of
|
|
234
|
+
* nodes and maintaining balance in the tree.
|
|
235
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
236
|
+
* parameter in the `delete` method is used to specify the condition for deleting a node from the
|
|
237
|
+
* binary tree. It can be a key, node, entry, or a custom predicate function that determines which
|
|
238
|
+
* node(s) should be deleted.
|
|
239
|
+
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
240
|
+
* boolean flag that determines whether to ignore the count of the node being deleted. If
|
|
241
|
+
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
242
|
+
* `ignoreCount` is set to
|
|
243
|
+
* @returns The `delete` method overrides the default delete behavior in a binary tree data
|
|
244
|
+
* structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
|
|
245
|
+
* method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
|
|
246
|
+
* deleted node and whether balancing is needed in the tree.
|
|
248
247
|
*/
|
|
249
|
-
override delete
|
|
250
|
-
|
|
251
|
-
callback: C = this._DEFAULT_CALLBACK as C,
|
|
248
|
+
override delete(
|
|
249
|
+
predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>,
|
|
252
250
|
ignoreCount = false
|
|
253
251
|
): BinaryTreeDeleteResult<NODE>[] {
|
|
254
252
|
const deletedResult: BinaryTreeDeleteResult<NODE>[] = [];
|
|
255
253
|
if (!this.root) return deletedResult;
|
|
256
|
-
callback = this._ensureCallback(identifier, callback);
|
|
257
254
|
|
|
258
|
-
const curr: NODE | undefined = this.getNode(
|
|
255
|
+
const curr: NODE | undefined = this.getNode(predicate) ?? undefined;
|
|
259
256
|
if (!curr) return deletedResult;
|
|
260
257
|
|
|
261
258
|
const parent: NODE | undefined = curr?.parent ? curr.parent : undefined;
|
|
@@ -293,7 +290,7 @@ export class AVLTreeMultiMap<
|
|
|
293
290
|
}
|
|
294
291
|
}
|
|
295
292
|
}
|
|
296
|
-
this._size = this.
|
|
293
|
+
this._size = this._size - 1;
|
|
297
294
|
// TODO How to handle when the count of target node is lesser than current node's count
|
|
298
295
|
if (orgCurrent) this._count -= orgCurrent.count;
|
|
299
296
|
}
|