data-structure-typed 1.50.2 → 1.50.4
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/.github/ISSUE_TEMPLATE/bug_report.md +0 -13
- package/CHANGELOG.md +1 -1
- package/README.md +23 -21
- package/README_zh-CN.md +7 -7
- package/SPECIFICATION.md +56 -0
- package/SPONSOR-zh-CN.md +90 -0
- package/SPONSOR.md +54 -0
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +149 -155
- package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/cjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +50 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/cjs/data-structures/binary-tree/bst.js +51 -20
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/cjs/data-structures/binary-tree/index.js +2 -1
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +90 -24
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +400 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -189
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/cjs/data-structures/graph/undirected-graph.js +126 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/cjs/data-structures/hash/hash-map.js +196 -62
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/cjs/data-structures/heap/heap.js +29 -20
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +83 -25
- 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 +26 -3
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +34 -3
- 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/linked-list/skip-linked-list.js +2 -2
- package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/cjs/data-structures/queue/deque.js +100 -16
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/cjs/data-structures/queue/queue.js +65 -45
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/cjs/data-structures/stack/stack.js +36 -22
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/cjs/data-structures/tree/tree.js +77 -11
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/cjs/data-structures/trie/trie.js +115 -36
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js +2 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/cjs/types/data-structures/binary-tree/{tree-multimap.js → tree-multi-map.js} +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/mjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/mjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +46 -9
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +34 -2
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/mjs/data-structures/binary-tree/bst.js +51 -20
- package/dist/mjs/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/mjs/data-structures/binary-tree/index.js +2 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +91 -25
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +397 -0
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/mjs/data-structures/graph/abstract-graph.js +0 -188
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/mjs/data-structures/graph/undirected-graph.js +127 -19
- package/dist/mjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/mjs/data-structures/hash/hash-map.js +204 -70
- package/dist/mjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/mjs/data-structures/heap/heap.js +29 -20
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +86 -28
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +36 -5
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/mjs/data-structures/matrix/matrix.js +1 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/mjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/mjs/data-structures/queue/deque.js +105 -21
- package/dist/mjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/mjs/data-structures/queue/queue.js +65 -45
- package/dist/mjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/mjs/data-structures/stack/stack.js +36 -22
- package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/mjs/data-structures/tree/tree.js +80 -14
- package/dist/mjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/mjs/data-structures/trie/trie.js +118 -39
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/mjs/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/mjs/types/data-structures/binary-tree/index.js +2 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.js +1 -0
- package/dist/umd/data-structure-typed.js +1876 -656
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +59 -58
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +51 -19
- package/src/data-structures/binary-tree/index.ts +2 -1
- package/src/data-structures/binary-tree/rb-tree.ts +99 -28
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
- package/src/types/data-structures/binary-tree/index.ts +2 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
- package/test/integration/index.html +2 -2
- package/test/performance/data-structures/graph/directed-graph.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/{tree-multimap.test.ts → avl-tree-multi-map.test.ts} +55 -55
- package/test/unit/data-structures/binary-tree/overall.test.ts +24 -25
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +706 -0
- package/test/unit/data-structures/graph/abstract-graph.test.ts +3 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +189 -253
- package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
- package/test/unit/data-structures/queue/queue.test.ts +2 -0
- package/test/unit/unrestricted-interconversion.test.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.js.map +0 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
- /package/dist/mjs/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.50.
|
|
3
|
+
"version": "1.50.4",
|
|
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",
|
|
@@ -94,17 +94,52 @@
|
|
|
94
94
|
"keywords": [
|
|
95
95
|
"data structure",
|
|
96
96
|
"data structures",
|
|
97
|
-
"javascript data structure",
|
|
98
|
-
"javascript data structures",
|
|
99
|
-
"typescript data structure",
|
|
100
|
-
"typescript data structures",
|
|
101
|
-
"js data structure",
|
|
102
|
-
"js data structures",
|
|
103
|
-
"data-structure",
|
|
104
97
|
"datastructure",
|
|
98
|
+
"datastructures",
|
|
105
99
|
"data",
|
|
106
100
|
"structure",
|
|
107
101
|
"structures",
|
|
102
|
+
"min",
|
|
103
|
+
"max",
|
|
104
|
+
"heap",
|
|
105
|
+
"priority",
|
|
106
|
+
"queue",
|
|
107
|
+
"min heap",
|
|
108
|
+
"min-heap",
|
|
109
|
+
"max heap",
|
|
110
|
+
"max-heap",
|
|
111
|
+
"priority queue",
|
|
112
|
+
"priority-queue",
|
|
113
|
+
"max priority queue",
|
|
114
|
+
"max-priority-queue",
|
|
115
|
+
"min priority queue",
|
|
116
|
+
"min-priority-queue",
|
|
117
|
+
"binary search tree",
|
|
118
|
+
"binary-search-tree",
|
|
119
|
+
"BST",
|
|
120
|
+
"binary tree",
|
|
121
|
+
"binary-tree",
|
|
122
|
+
"red black tree",
|
|
123
|
+
"red black tree",
|
|
124
|
+
"red-black-tree",
|
|
125
|
+
"rb tree",
|
|
126
|
+
"trie",
|
|
127
|
+
"prefix tree",
|
|
128
|
+
"prefix-tree",
|
|
129
|
+
"avl tree",
|
|
130
|
+
"avl-tree",
|
|
131
|
+
"tree set",
|
|
132
|
+
"tree-set",
|
|
133
|
+
"tree multiset",
|
|
134
|
+
"tree-multiset",
|
|
135
|
+
"tree map",
|
|
136
|
+
"tree-map",
|
|
137
|
+
"tree multimap",
|
|
138
|
+
"tree-multimap",
|
|
139
|
+
"binary indexed tree",
|
|
140
|
+
"binary-indexed-tree",
|
|
141
|
+
"segment tree",
|
|
142
|
+
"segment-tree",
|
|
108
143
|
"binary",
|
|
109
144
|
"depth",
|
|
110
145
|
"breadth",
|
|
@@ -124,18 +159,26 @@
|
|
|
124
159
|
"set",
|
|
125
160
|
"multiset",
|
|
126
161
|
"multimap",
|
|
127
|
-
"directed",
|
|
128
|
-
"undirected",
|
|
129
|
-
"graph",
|
|
130
|
-
"min",
|
|
131
|
-
"max",
|
|
132
|
-
"heap",
|
|
133
|
-
"priority",
|
|
134
|
-
"queue",
|
|
135
162
|
"singly",
|
|
136
163
|
"doubly",
|
|
137
164
|
"linked",
|
|
138
165
|
"list",
|
|
166
|
+
"linked list",
|
|
167
|
+
"linked-list",
|
|
168
|
+
"singly linked list",
|
|
169
|
+
"singly-linked-list",
|
|
170
|
+
"doubly linked list",
|
|
171
|
+
"doubly-linked-list",
|
|
172
|
+
"javascript data structure",
|
|
173
|
+
"javascript data structures",
|
|
174
|
+
"typescript data structures",
|
|
175
|
+
"js data structure",
|
|
176
|
+
"js data structures",
|
|
177
|
+
"data-structure",
|
|
178
|
+
"data-structures",
|
|
179
|
+
"directed",
|
|
180
|
+
"undirected",
|
|
181
|
+
"graph",
|
|
139
182
|
"js",
|
|
140
183
|
"ts",
|
|
141
184
|
"javascript",
|
|
@@ -159,32 +202,6 @@
|
|
|
159
202
|
"java.util",
|
|
160
203
|
"Java",
|
|
161
204
|
"util",
|
|
162
|
-
"binary search tree",
|
|
163
|
-
"binary-search-tree",
|
|
164
|
-
"BST",
|
|
165
|
-
"binary tree",
|
|
166
|
-
"binary-tree",
|
|
167
|
-
"red black tree",
|
|
168
|
-
"red black tree",
|
|
169
|
-
"red-black-tree",
|
|
170
|
-
"rb tree",
|
|
171
|
-
"trie",
|
|
172
|
-
"prefix tree",
|
|
173
|
-
"prefix-tree",
|
|
174
|
-
"avl tree",
|
|
175
|
-
"avl-tree",
|
|
176
|
-
"tree set",
|
|
177
|
-
"tree-set",
|
|
178
|
-
"tree multiset",
|
|
179
|
-
"tree-multiset",
|
|
180
|
-
"tree map",
|
|
181
|
-
"tree-map",
|
|
182
|
-
"tree multimap",
|
|
183
|
-
"tree-multimap",
|
|
184
|
-
"binary indexed tree",
|
|
185
|
-
"binary-indexed-tree",
|
|
186
|
-
"segment tree",
|
|
187
|
-
"segment-tree",
|
|
188
205
|
"sort",
|
|
189
206
|
"sorted",
|
|
190
207
|
"order",
|
|
@@ -212,28 +229,12 @@
|
|
|
212
229
|
"directed-graph",
|
|
213
230
|
"undirected graph",
|
|
214
231
|
"undirected-graph",
|
|
215
|
-
"min heap",
|
|
216
|
-
"min-heap",
|
|
217
|
-
"max heap",
|
|
218
|
-
"max-heap",
|
|
219
|
-
"priority queue",
|
|
220
|
-
"priority-queue",
|
|
221
|
-
"max priority queue",
|
|
222
|
-
"max-priority-queue",
|
|
223
|
-
"min priority queue",
|
|
224
|
-
"min-priority-queue",
|
|
225
232
|
"hash",
|
|
226
233
|
"map",
|
|
227
234
|
"hashmap",
|
|
228
235
|
"hash map",
|
|
229
236
|
"hash-map",
|
|
230
237
|
"deque",
|
|
231
|
-
"linked list",
|
|
232
|
-
"linked-list",
|
|
233
|
-
"singly linked list",
|
|
234
|
-
"singly-linked-list",
|
|
235
|
-
"doubly linked list",
|
|
236
|
-
"doubly-linked-list",
|
|
237
238
|
"stack",
|
|
238
239
|
"CommonJS",
|
|
239
240
|
"ES6",
|
|
@@ -289,8 +289,14 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
289
289
|
|
|
290
290
|
abstract isEmpty(): boolean;
|
|
291
291
|
|
|
292
|
+
abstract clear(): void;
|
|
293
|
+
|
|
292
294
|
abstract clone(): any;
|
|
293
295
|
|
|
296
|
+
abstract map(...args: any[]): any;
|
|
297
|
+
|
|
298
|
+
abstract filter(...args: any[]): any;
|
|
299
|
+
|
|
294
300
|
protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
|
|
295
301
|
}
|
|
296
302
|
|
|
@@ -497,7 +503,13 @@ export abstract class IterableElementBase<E = any, C = any> {
|
|
|
497
503
|
|
|
498
504
|
abstract isEmpty(): boolean;
|
|
499
505
|
|
|
506
|
+
abstract clear(): void;
|
|
507
|
+
|
|
500
508
|
abstract clone(): C;
|
|
501
509
|
|
|
510
|
+
abstract map(...args: any[]): any;
|
|
511
|
+
|
|
512
|
+
abstract filter(...args: any[]): any;
|
|
513
|
+
|
|
502
514
|
protected abstract _getIterator(...args: any[]): IterableIterator<E>;
|
|
503
515
|
}
|
|
@@ -6,25 +6,23 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type {
|
|
9
|
+
AVLTreeMultiMapNested,
|
|
10
|
+
AVLTreeMultiMapNodeNested,
|
|
11
|
+
AVLTreeMultiMapOptions,
|
|
9
12
|
BinaryTreeDeleteResult,
|
|
10
13
|
BSTNKeyOrNode,
|
|
11
14
|
BTNCallback,
|
|
12
|
-
KeyOrNodeOrEntry
|
|
13
|
-
TreeMultimapNested,
|
|
14
|
-
TreeMultimapNodeNested,
|
|
15
|
-
TreeMultimapOptions
|
|
15
|
+
KeyOrNodeOrEntry
|
|
16
16
|
} from '../../types';
|
|
17
17
|
import { FamilyPosition, IterationType } from '../../types';
|
|
18
18
|
import { IBinaryTree } from '../../interfaces';
|
|
19
19
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
20
20
|
|
|
21
|
-
export class
|
|
21
|
+
export class AVLTreeMultiMapNode<
|
|
22
22
|
K = any,
|
|
23
23
|
V = any,
|
|
24
|
-
NODE extends
|
|
24
|
+
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>
|
|
25
25
|
> extends AVLTreeNode<K, V, NODE> {
|
|
26
|
-
count: number;
|
|
27
|
-
|
|
28
26
|
/**
|
|
29
27
|
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
30
28
|
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
@@ -39,27 +37,51 @@ export class TreeMultimapNode<
|
|
|
39
37
|
super(key, value);
|
|
40
38
|
this.count = count;
|
|
41
39
|
}
|
|
40
|
+
|
|
41
|
+
protected _count: number = 1;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The function returns the value of the protected variable _count.
|
|
45
|
+
* @returns The count property of the object, which is of type number.
|
|
46
|
+
*/
|
|
47
|
+
get count(): number {
|
|
48
|
+
return this._count;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The above function sets the value of the count property.
|
|
53
|
+
* @param {number} value - The value parameter is of type number, which means it can accept any
|
|
54
|
+
* numeric value.
|
|
55
|
+
*/
|
|
56
|
+
set count(value: number) {
|
|
57
|
+
this._count = value;
|
|
58
|
+
}
|
|
42
59
|
}
|
|
43
60
|
|
|
44
61
|
/**
|
|
45
|
-
* The only distinction between a
|
|
62
|
+
* 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.
|
|
46
63
|
*/
|
|
47
|
-
export class
|
|
64
|
+
export class AVLTreeMultiMap<
|
|
48
65
|
K = any,
|
|
49
66
|
V = any,
|
|
50
|
-
NODE extends
|
|
51
|
-
TREE extends
|
|
67
|
+
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
|
|
68
|
+
TREE extends AVLTreeMultiMap<K, V, NODE, TREE> = AVLTreeMultiMap<K, V, NODE, AVLTreeMultiMapNested<K, V, NODE>>
|
|
52
69
|
>
|
|
53
70
|
extends AVLTree<K, V, NODE, TREE>
|
|
54
71
|
implements IBinaryTree<K, V, NODE, TREE> {
|
|
55
|
-
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?:
|
|
72
|
+
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: AVLTreeMultiMapOptions<K>) {
|
|
56
73
|
super([], options);
|
|
57
74
|
if (keysOrNodesOrEntries) this.addMany(keysOrNodesOrEntries);
|
|
58
75
|
}
|
|
59
76
|
|
|
60
|
-
|
|
77
|
+
protected _count = 0;
|
|
61
78
|
|
|
62
79
|
// TODO the _count is not accurate after nodes count modified
|
|
80
|
+
/**
|
|
81
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
82
|
+
* search.
|
|
83
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
84
|
+
*/
|
|
63
85
|
get count(): number {
|
|
64
86
|
let sum = 0;
|
|
65
87
|
this.dfs(node => (sum += node.count));
|
|
@@ -76,11 +98,20 @@ export class TreeMultimap<
|
|
|
76
98
|
* @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
|
|
77
99
|
*/
|
|
78
100
|
override createNode(key: K, value?: V, count?: number): NODE {
|
|
79
|
-
return new
|
|
101
|
+
return new AVLTreeMultiMapNode(key, value, count) as NODE;
|
|
80
102
|
}
|
|
81
103
|
|
|
82
|
-
|
|
83
|
-
|
|
104
|
+
/**
|
|
105
|
+
* The function creates a new AVLTreeMultiMap object with the specified options and returns it.
|
|
106
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
107
|
+
* configuration options for creating the `AVLTreeMultiMap` object. It can include properties such as
|
|
108
|
+
* `iterationType` and `variant`, which are used to specify the type of iteration and the variant of
|
|
109
|
+
* the tree, respectively. These properties can be
|
|
110
|
+
* @returns a new instance of the `AVLTreeMultiMap` class, with the provided options merged with the
|
|
111
|
+
* default options. The returned value is casted as `TREE`.
|
|
112
|
+
*/
|
|
113
|
+
override createTree(options?: AVLTreeMultiMapOptions<K>): TREE {
|
|
114
|
+
return new AVLTreeMultiMap<K, V, NODE, TREE>([], {
|
|
84
115
|
iterationType: this.iterationType,
|
|
85
116
|
variant: this.variant,
|
|
86
117
|
...options
|
|
@@ -124,13 +155,13 @@ export class TreeMultimap<
|
|
|
124
155
|
}
|
|
125
156
|
|
|
126
157
|
/**
|
|
127
|
-
* The function checks if an keyOrNodeOrEntry is an instance of the
|
|
158
|
+
* The function checks if an keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode class.
|
|
128
159
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
129
|
-
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the
|
|
160
|
+
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode
|
|
130
161
|
* class.
|
|
131
162
|
*/
|
|
132
163
|
override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE {
|
|
133
|
-
return keyOrNodeOrEntry instanceof
|
|
164
|
+
return keyOrNodeOrEntry instanceof AVLTreeMultiMapNode;
|
|
134
165
|
}
|
|
135
166
|
|
|
136
167
|
/**
|
|
@@ -375,6 +406,14 @@ export class TreeMultimap<
|
|
|
375
406
|
return undefined;
|
|
376
407
|
}
|
|
377
408
|
|
|
409
|
+
/**
|
|
410
|
+
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
411
|
+
* @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
|
|
412
|
+
* needs to be replaced in a data structure.
|
|
413
|
+
* @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
|
|
414
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
415
|
+
* superclass, after updating the `count` property of the `newNode` object.
|
|
416
|
+
*/
|
|
378
417
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE {
|
|
379
418
|
newNode.count = oldNode.count + newNode.count;
|
|
380
419
|
return super._replaceNode(oldNode, newNode);
|
|
@@ -22,11 +22,36 @@ export class AVLTreeNode<
|
|
|
22
22
|
V = any,
|
|
23
23
|
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>
|
|
24
24
|
> extends BSTNode<K, V, NODE> {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The constructor function initializes a new instance of a class with a key and an optional value,
|
|
27
|
+
* and sets the height property to 0.
|
|
28
|
+
* @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
|
|
29
|
+
* constructor. It is used to initialize the key property of the object being created.
|
|
30
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
31
|
+
* value associated with the key in the constructor.
|
|
32
|
+
*/
|
|
27
33
|
constructor(key: K, value?: V) {
|
|
28
34
|
super(key, value);
|
|
29
|
-
this.
|
|
35
|
+
this._height = 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected _height: number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The function returns the value of the height property.
|
|
42
|
+
* @returns The height of the object.
|
|
43
|
+
*/
|
|
44
|
+
get height(): number {
|
|
45
|
+
return this._height;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The above function sets the value of the height property.
|
|
50
|
+
* @param {number} value - The value parameter is a number that represents the new height value to be
|
|
51
|
+
* set.
|
|
52
|
+
*/
|
|
53
|
+
set height(value: number) {
|
|
54
|
+
this._height = value;
|
|
30
55
|
}
|
|
31
56
|
}
|
|
32
57
|
|
|
@@ -488,6 +513,15 @@ export class AVLTree<
|
|
|
488
513
|
}
|
|
489
514
|
}
|
|
490
515
|
|
|
516
|
+
/**
|
|
517
|
+
* The function replaces an old node with a new node while preserving the height of the old node.
|
|
518
|
+
* @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace with the
|
|
519
|
+
* `newNode`.
|
|
520
|
+
* @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
|
|
521
|
+
* the data structure.
|
|
522
|
+
* @returns the result of calling the `_replaceNode` method on the superclass, passing in the
|
|
523
|
+
* `oldNode` and `newNode` as arguments.
|
|
524
|
+
*/
|
|
491
525
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE {
|
|
492
526
|
newNode.height = oldNode.height;
|
|
493
527
|
|
|
@@ -27,26 +27,48 @@ export class BinaryIndexedTree {
|
|
|
27
27
|
|
|
28
28
|
protected _freqMap: Record<number, number>;
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* The function returns the frequency map of numbers.
|
|
32
|
+
* @returns The `_freqMap` property, which is a record with number keys and number values, is being
|
|
33
|
+
* returned.
|
|
34
|
+
*/
|
|
30
35
|
get freqMap(): Record<number, number> {
|
|
31
36
|
return this._freqMap;
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
protected _msb: number;
|
|
35
40
|
|
|
41
|
+
/**
|
|
42
|
+
* The function returns the value of the _msb property.
|
|
43
|
+
* @returns The `_msb` property of the object.
|
|
44
|
+
*/
|
|
36
45
|
get msb(): number {
|
|
37
46
|
return this._msb;
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
protected _negativeCount: number;
|
|
41
50
|
|
|
51
|
+
/**
|
|
52
|
+
* The function returns the value of the _negativeCount property.
|
|
53
|
+
* @returns The method is returning the value of the variable `_negativeCount`, which is of type
|
|
54
|
+
* `number`.
|
|
55
|
+
*/
|
|
42
56
|
get negativeCount(): number {
|
|
43
57
|
return this._negativeCount;
|
|
44
58
|
}
|
|
45
59
|
|
|
60
|
+
/**
|
|
61
|
+
* The above function returns the value of the protected variable `_freq`.
|
|
62
|
+
* @returns The frequency value stored in the protected variable `_freq`.
|
|
63
|
+
*/
|
|
46
64
|
get freq(): number {
|
|
47
65
|
return this._freq;
|
|
48
66
|
}
|
|
49
67
|
|
|
68
|
+
/**
|
|
69
|
+
* The above function returns the maximum value.
|
|
70
|
+
* @returns The maximum value stored in the variable `_max`.
|
|
71
|
+
*/
|
|
50
72
|
get max(): number {
|
|
51
73
|
return this._max;
|
|
52
74
|
}
|
|
@@ -44,7 +44,7 @@ export class BinaryTreeNode<
|
|
|
44
44
|
/**
|
|
45
45
|
* The constructor function initializes an object with a key and an optional value.
|
|
46
46
|
* @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
|
|
47
|
-
* constructor. It is used to set the
|
|
47
|
+
* constructor. It is used to set the key property of the object being created.
|
|
48
48
|
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
49
49
|
* value associated with the key in the constructor.
|
|
50
50
|
*/
|
|
@@ -34,10 +34,19 @@ export class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNod
|
|
|
34
34
|
|
|
35
35
|
protected override _left?: NODE;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* The function returns the value of the `_left` property.
|
|
39
|
+
* @returns The `_left` property of the current object is being returned.
|
|
40
|
+
*/
|
|
37
41
|
override get left(): NODE | undefined {
|
|
38
42
|
return this._left;
|
|
39
43
|
}
|
|
40
44
|
|
|
45
|
+
/**
|
|
46
|
+
* The function sets the left child of a node and updates the parent reference of the child.
|
|
47
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be an
|
|
48
|
+
* instance of the `NODE` class or `undefined`.
|
|
49
|
+
*/
|
|
41
50
|
override set left(v: NODE | undefined) {
|
|
42
51
|
if (v) {
|
|
43
52
|
v.parent = this as unknown as NODE;
|
|
@@ -47,10 +56,20 @@ export class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNod
|
|
|
47
56
|
|
|
48
57
|
protected override _right?: NODE;
|
|
49
58
|
|
|
59
|
+
/**
|
|
60
|
+
* The function returns the right node of a binary tree or undefined if there is no right node.
|
|
61
|
+
* @returns The method is returning the value of the `_right` property, which is of type `NODE` or
|
|
62
|
+
* `undefined`.
|
|
63
|
+
*/
|
|
50
64
|
override get right(): NODE | undefined {
|
|
51
65
|
return this._right;
|
|
52
66
|
}
|
|
53
67
|
|
|
68
|
+
/**
|
|
69
|
+
* The function sets the right child of a node and updates the parent reference of the child.
|
|
70
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be a
|
|
71
|
+
* `NODE` object or `undefined`.
|
|
72
|
+
*/
|
|
54
73
|
override set right(v: NODE | undefined) {
|
|
55
74
|
if (v) {
|
|
56
75
|
v.parent = this as unknown as NODE;
|
|
@@ -77,10 +96,10 @@ export class BST<
|
|
|
77
96
|
extends BinaryTree<K, V, NODE, TREE>
|
|
78
97
|
implements IBinaryTree<K, V, NODE, TREE> {
|
|
79
98
|
/**
|
|
80
|
-
* This is the constructor function for a
|
|
81
|
-
*
|
|
82
|
-
* @param
|
|
83
|
-
* binary search tree.
|
|
99
|
+
* This is the constructor function for a TypeScript class that initializes a binary search tree with
|
|
100
|
+
* optional keys or nodes or entries and options.
|
|
101
|
+
* @param keysOrNodesOrEntries - An iterable object that contains keys, nodes, or entries. It is used
|
|
102
|
+
* to initialize the binary search tree with the provided keys, nodes, or entries.
|
|
84
103
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
85
104
|
* configuration options for the binary search tree. It can have the following properties:
|
|
86
105
|
*/
|
|
@@ -99,23 +118,31 @@ export class BST<
|
|
|
99
118
|
|
|
100
119
|
protected override _root?: NODE;
|
|
101
120
|
|
|
121
|
+
/**
|
|
122
|
+
* The function returns the root node of a tree structure.
|
|
123
|
+
* @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
|
|
124
|
+
*/
|
|
102
125
|
override get root(): NODE | undefined {
|
|
103
126
|
return this._root;
|
|
104
127
|
}
|
|
105
128
|
|
|
106
129
|
protected _variant = BSTVariant.STANDARD;
|
|
107
130
|
|
|
131
|
+
/**
|
|
132
|
+
* The function returns the value of the _variant property.
|
|
133
|
+
* @returns The value of the `_variant` property.
|
|
134
|
+
*/
|
|
108
135
|
get variant() {
|
|
109
136
|
return this._variant;
|
|
110
137
|
}
|
|
111
138
|
|
|
112
139
|
/**
|
|
113
|
-
* The function creates a new
|
|
114
|
-
* @param {K} key - The key parameter is the
|
|
115
|
-
*
|
|
116
|
-
* @param [value] - The parameter
|
|
117
|
-
*
|
|
118
|
-
* @returns a new instance of the BSTNode class
|
|
140
|
+
* The function creates a new BSTNode with the given key and value and returns it.
|
|
141
|
+
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
142
|
+
* being created.
|
|
143
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
144
|
+
* value associated with the key in the node being created.
|
|
145
|
+
* @returns The method is returning a new instance of the BSTNode class, casted as the NODE type.
|
|
119
146
|
*/
|
|
120
147
|
override createNode(key: K, value?: V): NODE {
|
|
121
148
|
return new BSTNode<K, V, NODE>(key, value) as NODE;
|
|
@@ -124,9 +151,10 @@ export class BST<
|
|
|
124
151
|
/**
|
|
125
152
|
* The function creates a new binary search tree with the specified options.
|
|
126
153
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
127
|
-
* behavior of the `createTree` method. It
|
|
128
|
-
*
|
|
129
|
-
* @returns a new instance of the BST class with the
|
|
154
|
+
* behavior of the `createTree` method. It is of type `Partial<BSTOptions<K>>`, which means it is a
|
|
155
|
+
* partial object of type `BSTOptions<K>`.
|
|
156
|
+
* @returns a new instance of the BST class, with the provided options merged with the default
|
|
157
|
+
* options. The returned value is casted as TREE.
|
|
130
158
|
*/
|
|
131
159
|
override createTree(options?: Partial<BSTOptions<K>>): TREE {
|
|
132
160
|
return new BST<K, V, NODE, TREE>([], {
|
|
@@ -680,9 +708,8 @@ export class BST<
|
|
|
680
708
|
const compared = this._compare(cur.key, targetKey);
|
|
681
709
|
if (compared === lesserOrGreater) ans.push(callback(cur));
|
|
682
710
|
|
|
683
|
-
if (
|
|
684
|
-
if (
|
|
685
|
-
if (cur.right && this._compare(cur.right.key, targetKey) === lesserOrGreater) _traverse(cur.right);
|
|
711
|
+
if (this.isRealNode(cur.left)) _traverse(cur.left);
|
|
712
|
+
if (this.isRealNode(cur.right)) _traverse(cur.right);
|
|
686
713
|
};
|
|
687
714
|
|
|
688
715
|
_traverse(this.root);
|
|
@@ -691,12 +718,12 @@ export class BST<
|
|
|
691
718
|
const queue = new Queue<NODE>([this.root]);
|
|
692
719
|
while (queue.size > 0) {
|
|
693
720
|
const cur = queue.shift();
|
|
694
|
-
if (cur) {
|
|
721
|
+
if (this.isRealNode(cur)) {
|
|
695
722
|
const compared = this._compare(cur.key, targetKey);
|
|
696
723
|
if (compared === lesserOrGreater) ans.push(callback(cur));
|
|
697
724
|
|
|
698
|
-
if (
|
|
699
|
-
if (
|
|
725
|
+
if (this.isRealNode(cur.left)) queue.push(cur.left);
|
|
726
|
+
if (this.isRealNode(cur.right)) queue.push(cur.right);
|
|
700
727
|
}
|
|
701
728
|
}
|
|
702
729
|
return ans;
|
|
@@ -824,6 +851,11 @@ export class BST<
|
|
|
824
851
|
return balanced;
|
|
825
852
|
}
|
|
826
853
|
|
|
854
|
+
/**
|
|
855
|
+
* The function sets the root property of an object and updates the parent property of the new root.
|
|
856
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. This means that it
|
|
857
|
+
* can either be an object of type `NODE` or it can be `undefined`.
|
|
858
|
+
*/
|
|
827
859
|
protected _setRoot(v: NODE | undefined) {
|
|
828
860
|
if (v) {
|
|
829
861
|
v.parent = undefined;
|