data-structure-typed 2.5.0 → 2.5.2
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/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
- package/CHANGELOG.md +5 -1
- package/README.md +124 -29
- package/dist/cjs/binary-tree.cjs +26282 -0
- package/dist/cjs/graph.cjs +5422 -0
- package/dist/cjs/hash.cjs +1310 -0
- package/dist/cjs/heap.cjs +1602 -0
- package/dist/cjs/index.cjs +31257 -14673
- package/dist/cjs/linked-list.cjs +4576 -0
- package/dist/cjs/matrix.cjs +1080 -0
- package/dist/cjs/priority-queue.cjs +1376 -0
- package/dist/cjs/queue.cjs +4264 -0
- package/dist/cjs/stack.cjs +907 -0
- package/dist/cjs/trie.cjs +1223 -0
- package/dist/cjs-legacy/binary-tree.cjs +26319 -0
- package/dist/cjs-legacy/graph.cjs +5420 -0
- package/dist/cjs-legacy/hash.cjs +1310 -0
- package/dist/cjs-legacy/heap.cjs +1599 -0
- package/dist/cjs-legacy/index.cjs +31268 -14679
- package/dist/cjs-legacy/linked-list.cjs +4582 -0
- package/dist/cjs-legacy/matrix.cjs +1083 -0
- package/dist/cjs-legacy/priority-queue.cjs +1374 -0
- package/dist/cjs-legacy/queue.cjs +4262 -0
- package/dist/cjs-legacy/stack.cjs +907 -0
- package/dist/cjs-legacy/trie.cjs +1222 -0
- package/dist/esm/binary-tree.mjs +26267 -0
- package/dist/esm/graph.mjs +5409 -0
- package/dist/esm/hash.mjs +1307 -0
- package/dist/esm/heap.mjs +1596 -0
- package/dist/esm/index.mjs +31254 -14674
- package/dist/esm/linked-list.mjs +4569 -0
- package/dist/esm/matrix.mjs +1076 -0
- package/dist/esm/priority-queue.mjs +1372 -0
- package/dist/esm/queue.mjs +4260 -0
- package/dist/esm/stack.mjs +905 -0
- package/dist/esm/trie.mjs +1220 -0
- package/dist/esm-legacy/binary-tree.mjs +26304 -0
- package/dist/esm-legacy/graph.mjs +5407 -0
- package/dist/esm-legacy/hash.mjs +1307 -0
- package/dist/esm-legacy/heap.mjs +1593 -0
- package/dist/esm-legacy/index.mjs +31265 -14680
- package/dist/esm-legacy/linked-list.mjs +4575 -0
- package/dist/esm-legacy/matrix.mjs +1079 -0
- package/dist/esm-legacy/priority-queue.mjs +1370 -0
- package/dist/esm-legacy/queue.mjs +4258 -0
- package/dist/esm-legacy/stack.mjs +905 -0
- package/dist/esm-legacy/trie.mjs +1219 -0
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/data-structure-typed.js +31196 -14608
- package/dist/umd/data-structure-typed.min.js +11 -5
- package/docs-site-docusaurus/README.md +41 -0
- package/docs-site-docusaurus/docs/api/README.md +52 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6644 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
- package/docs-site-docusaurus/docs/api/classes/BST.md +6293 -0
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
- package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
- package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
- package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6888 -0
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
- package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1389 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1591 -0
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1246 -0
- package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
- package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/architecture.md +615 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +451 -0
- package/docs-site-docusaurus/docs/guide/faq.md +180 -0
- package/docs-site-docusaurus/docs/guide/guides.md +597 -0
- package/docs-site-docusaurus/docs/guide/installation.md +62 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +825 -0
- package/docs-site-docusaurus/docs/guide/overview.md +645 -0
- package/docs-site-docusaurus/docs/guide/performance.md +835 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +104 -0
- package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
- package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
- package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
- package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
- package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -0
- package/docs-site-docusaurus/docusaurus.config.ts +159 -0
- package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
- package/docs-site-docusaurus/package-lock.json +18667 -0
- package/docs-site-docusaurus/package.json +50 -0
- package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
- package/docs-site-docusaurus/sidebars.ts +23 -0
- package/docs-site-docusaurus/sort-protected.mjs +87 -0
- package/docs-site-docusaurus/src/css/custom.css +96 -0
- package/docs-site-docusaurus/src/pages/index.module.css +13 -0
- package/docs-site-docusaurus/src/pages/index.tsx +120 -0
- package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
- package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
- package/docs-site-docusaurus/static/.nojekyll +0 -0
- package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
- package/docs-site-docusaurus/static/img/favicon.ico +0 -0
- package/docs-site-docusaurus/static/img/favicon.png +0 -0
- package/docs-site-docusaurus/static/img/logo-180.png +0 -0
- package/docs-site-docusaurus/static/img/logo.jpg +0 -0
- package/docs-site-docusaurus/static/img/logo.png +0 -0
- package/docs-site-docusaurus/static/img/logo.svg +1 -0
- package/docs-site-docusaurus/static/img/og-image.png +0 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
- package/docs-site-docusaurus/static/llms.txt +37 -0
- package/docs-site-docusaurus/static/robots.txt +4 -0
- package/docs-site-docusaurus/typedoc.json +23 -0
- package/llms.txt +37 -0
- package/package.json +159 -55
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +287 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +327 -5
- package/src/data-structures/binary-tree/binary-tree.ts +581 -6
- package/src/data-structures/binary-tree/bst.ts +922 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +453 -0
- package/src/data-structures/binary-tree/segment-tree.ts +139 -2
- package/src/data-structures/binary-tree/tree-map.ts +3300 -495
- package/src/data-structures/binary-tree/tree-multi-map.ts +3384 -563
- package/src/data-structures/binary-tree/tree-multi-set.ts +2757 -493
- package/src/data-structures/binary-tree/tree-set.ts +3122 -440
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +230 -0
- package/src/data-structures/graph/undirected-graph.ts +207 -0
- package/src/data-structures/hash/hash-map.ts +270 -19
- package/src/data-structures/heap/heap.ts +326 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +394 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +348 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +421 -7
- package/src/data-structures/matrix/matrix.ts +194 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +350 -5
- package/src/data-structures/queue/queue.ts +276 -0
- package/src/data-structures/stack/stack.ts +230 -0
- package/src/data-structures/trie/trie.ts +283 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
- package/vercel.json +6 -0
- package/dist/leetcode/avl-tree-counter.mjs +0 -2957
- package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
- package/dist/leetcode/avl-tree.mjs +0 -2720
- package/dist/leetcode/binary-tree.mjs +0 -1594
- package/dist/leetcode/bst.mjs +0 -2398
- package/dist/leetcode/deque.mjs +0 -683
- package/dist/leetcode/directed-graph.mjs +0 -1733
- package/dist/leetcode/doubly-linked-list.mjs +0 -709
- package/dist/leetcode/hash-map.mjs +0 -493
- package/dist/leetcode/heap.mjs +0 -542
- package/dist/leetcode/max-heap.mjs +0 -375
- package/dist/leetcode/max-priority-queue.mjs +0 -383
- package/dist/leetcode/min-heap.mjs +0 -363
- package/dist/leetcode/min-priority-queue.mjs +0 -371
- package/dist/leetcode/priority-queue.mjs +0 -363
- package/dist/leetcode/queue.mjs +0 -943
- package/dist/leetcode/red-black-tree.mjs +0 -2765
- package/dist/leetcode/singly-linked-list.mjs +0 -754
- package/dist/leetcode/stack.mjs +0 -217
- package/dist/leetcode/tree-counter.mjs +0 -3039
- package/dist/leetcode/tree-multi-map.mjs +0 -2913
- package/dist/leetcode/trie.mjs +0 -413
- package/dist/leetcode/undirected-graph.mjs +0 -1650
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
var IterableEntryBase = class {
|
|
4
|
-
static {
|
|
5
|
-
__name(this, "IterableEntryBase");
|
|
6
|
-
}
|
|
7
|
-
*[Symbol.iterator](...args) {
|
|
8
|
-
yield* this._getIterator(...args);
|
|
9
|
-
}
|
|
10
|
-
*entries() {
|
|
11
|
-
for (const item of this) {
|
|
12
|
-
yield item;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
*keys() {
|
|
16
|
-
for (const item of this) {
|
|
17
|
-
yield item[0];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
*values() {
|
|
21
|
-
for (const item of this) {
|
|
22
|
-
yield item[1];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
every(predicate, thisArg) {
|
|
26
|
-
let index = 0;
|
|
27
|
-
for (const item of this) {
|
|
28
|
-
if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
some(predicate, thisArg) {
|
|
35
|
-
let index = 0;
|
|
36
|
-
for (const item of this) {
|
|
37
|
-
if (predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
forEach(callbackfn, thisArg) {
|
|
44
|
-
let index = 0;
|
|
45
|
-
for (const item of this) {
|
|
46
|
-
const [key, value] = item;
|
|
47
|
-
callbackfn.call(thisArg, value, key, index++, this);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
find(callbackfn, thisArg) {
|
|
51
|
-
let index = 0;
|
|
52
|
-
for (const item of this) {
|
|
53
|
-
const [key, value] = item;
|
|
54
|
-
if (callbackfn.call(thisArg, value, key, index++, this)) return item;
|
|
55
|
-
}
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
has(key) {
|
|
59
|
-
for (const item of this) {
|
|
60
|
-
const [itemKey] = item;
|
|
61
|
-
if (itemKey === key) return true;
|
|
62
|
-
}
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
hasValue(value) {
|
|
66
|
-
for (const [, elementValue] of this) {
|
|
67
|
-
if (elementValue === value) return true;
|
|
68
|
-
}
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
get(key) {
|
|
72
|
-
for (const item of this) {
|
|
73
|
-
const [itemKey, value] = item;
|
|
74
|
-
if (itemKey === key) return value;
|
|
75
|
-
}
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
reduce(callbackfn, initialValue) {
|
|
79
|
-
let accumulator = initialValue;
|
|
80
|
-
let index = 0;
|
|
81
|
-
for (const item of this) {
|
|
82
|
-
const [key, value] = item;
|
|
83
|
-
accumulator = callbackfn(accumulator, value, key, index++, this);
|
|
84
|
-
}
|
|
85
|
-
return accumulator;
|
|
86
|
-
}
|
|
87
|
-
toArray() {
|
|
88
|
-
return [...this];
|
|
89
|
-
}
|
|
90
|
-
toVisual() {
|
|
91
|
-
return [...this];
|
|
92
|
-
}
|
|
93
|
-
print() {
|
|
94
|
-
console.log(this.toVisual());
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
var rangeCheck = __name((index, min, max, message = "Index out of bounds.") => {
|
|
98
|
-
if (index < min || index > max) throw new RangeError(message);
|
|
99
|
-
}, "rangeCheck");
|
|
100
|
-
var isWeakKey = __name((input) => {
|
|
101
|
-
const inputType = typeof input;
|
|
102
|
-
return inputType === "object" && input !== null || inputType === "function";
|
|
103
|
-
}, "isWeakKey");
|
|
104
|
-
var HashMap = class extends IterableEntryBase {
|
|
105
|
-
static {
|
|
106
|
-
__name(this, "HashMap");
|
|
107
|
-
}
|
|
108
|
-
constructor(entryOrRawElements = [], options) {
|
|
109
|
-
super();
|
|
110
|
-
if (options) {
|
|
111
|
-
const { hashFn, toEntryFn } = options;
|
|
112
|
-
if (hashFn) this._hashFn = hashFn;
|
|
113
|
-
if (toEntryFn) this._toEntryFn = toEntryFn;
|
|
114
|
-
}
|
|
115
|
-
if (entryOrRawElements) this.setMany(entryOrRawElements);
|
|
116
|
-
}
|
|
117
|
-
_store = {};
|
|
118
|
-
get store() {
|
|
119
|
-
return this._store;
|
|
120
|
-
}
|
|
121
|
-
_objMap = new Map();
|
|
122
|
-
get objMap() {
|
|
123
|
-
return this._objMap;
|
|
124
|
-
}
|
|
125
|
-
_toEntryFn;
|
|
126
|
-
get toEntryFn() {
|
|
127
|
-
return this._toEntryFn;
|
|
128
|
-
}
|
|
129
|
-
_size = 0;
|
|
130
|
-
get size() {
|
|
131
|
-
return this._size;
|
|
132
|
-
}
|
|
133
|
-
_hashFn = __name((key) => String(key), "_hashFn");
|
|
134
|
-
get hashFn() {
|
|
135
|
-
return this._hashFn;
|
|
136
|
-
}
|
|
137
|
-
isEmpty() {
|
|
138
|
-
return this._size === 0;
|
|
139
|
-
}
|
|
140
|
-
clear() {
|
|
141
|
-
this._store = {};
|
|
142
|
-
this._objMap.clear();
|
|
143
|
-
this._size = 0;
|
|
144
|
-
}
|
|
145
|
-
isEntry(rawElement) {
|
|
146
|
-
return Array.isArray(rawElement) && rawElement.length === 2;
|
|
147
|
-
}
|
|
148
|
-
set(key, value) {
|
|
149
|
-
if (this._isObjKey(key)) {
|
|
150
|
-
if (!this.objMap.has(key)) this._size++;
|
|
151
|
-
this.objMap.set(key, value);
|
|
152
|
-
} else {
|
|
153
|
-
const strKey = this._getNoObjKey(key);
|
|
154
|
-
if (this.store[strKey] === void 0) this._size++;
|
|
155
|
-
this._store[strKey] = { key, value };
|
|
156
|
-
}
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
setMany(entryOrRawElements) {
|
|
160
|
-
const results = [];
|
|
161
|
-
for (const rawEle of entryOrRawElements) {
|
|
162
|
-
let key, value;
|
|
163
|
-
if (this.isEntry(rawEle)) [key, value] = rawEle;
|
|
164
|
-
else if (this._toEntryFn) [key, value] = this._toEntryFn(rawEle);
|
|
165
|
-
if (key !== void 0 && value !== void 0) results.push(this.set(key, value));
|
|
166
|
-
}
|
|
167
|
-
return results;
|
|
168
|
-
}
|
|
169
|
-
get(key) {
|
|
170
|
-
if (this._isObjKey(key)) return this.objMap.get(key);
|
|
171
|
-
const strKey = this._getNoObjKey(key);
|
|
172
|
-
return this._store[strKey]?.value;
|
|
173
|
-
}
|
|
174
|
-
has(key) {
|
|
175
|
-
if (this._isObjKey(key)) return this.objMap.has(key);
|
|
176
|
-
const strKey = this._getNoObjKey(key);
|
|
177
|
-
return strKey in this.store;
|
|
178
|
-
}
|
|
179
|
-
delete(key) {
|
|
180
|
-
if (this._isObjKey(key)) {
|
|
181
|
-
if (this.objMap.has(key)) this._size--;
|
|
182
|
-
return this.objMap.delete(key);
|
|
183
|
-
}
|
|
184
|
-
const strKey = this._getNoObjKey(key);
|
|
185
|
-
if (strKey in this.store) {
|
|
186
|
-
delete this.store[strKey];
|
|
187
|
-
this._size--;
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
setHashFn(fn) {
|
|
193
|
-
if (this._hashFn === fn) return this;
|
|
194
|
-
this._hashFn = fn;
|
|
195
|
-
this._rehashNoObj();
|
|
196
|
-
return this;
|
|
197
|
-
}
|
|
198
|
-
clone() {
|
|
199
|
-
const opts = { hashFn: this._hashFn, toEntryFn: this._toEntryFn };
|
|
200
|
-
return this._createLike(this, opts);
|
|
201
|
-
}
|
|
202
|
-
map(callbackfn, thisArg) {
|
|
203
|
-
const out = this._createLike();
|
|
204
|
-
let index = 0;
|
|
205
|
-
for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, value, key, index++, this));
|
|
206
|
-
return out;
|
|
207
|
-
}
|
|
208
|
-
filter(predicate, thisArg) {
|
|
209
|
-
const out = this._createLike();
|
|
210
|
-
let index = 0;
|
|
211
|
-
for (const [key, value] of this) if (predicate.call(thisArg, value, key, index++, this)) out.set(key, value);
|
|
212
|
-
return out;
|
|
213
|
-
}
|
|
214
|
-
_createLike(entries = [], options) {
|
|
215
|
-
const Ctor = this.constructor;
|
|
216
|
-
return new Ctor(entries, options);
|
|
217
|
-
}
|
|
218
|
-
_rehashNoObj() {
|
|
219
|
-
const fresh = {};
|
|
220
|
-
for (const { key, value } of Object.values(this._store)) {
|
|
221
|
-
const sk = this._getNoObjKey(key);
|
|
222
|
-
fresh[sk] = { key, value };
|
|
223
|
-
}
|
|
224
|
-
this._store = fresh;
|
|
225
|
-
}
|
|
226
|
-
*_getIterator() {
|
|
227
|
-
for (const node of Object.values(this.store)) yield [node.key, node.value];
|
|
228
|
-
for (const node of this.objMap) yield node;
|
|
229
|
-
}
|
|
230
|
-
_isObjKey(key) {
|
|
231
|
-
const keyType = typeof key;
|
|
232
|
-
return (keyType === "object" || keyType === "function") && key !== null;
|
|
233
|
-
}
|
|
234
|
-
_getNoObjKey(key) {
|
|
235
|
-
const keyType = typeof key;
|
|
236
|
-
let strKey;
|
|
237
|
-
if (keyType !== "string" && keyType !== "number" && keyType !== "symbol") {
|
|
238
|
-
strKey = this._hashFn(key);
|
|
239
|
-
} else {
|
|
240
|
-
if (keyType === "number") {
|
|
241
|
-
strKey = key;
|
|
242
|
-
} else {
|
|
243
|
-
strKey = key;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
return strKey;
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
var LinkedHashMap = class extends IterableEntryBase {
|
|
250
|
-
static {
|
|
251
|
-
__name(this, "LinkedHashMap");
|
|
252
|
-
}
|
|
253
|
-
_sentinel;
|
|
254
|
-
constructor(entryOrRawElements = [], options) {
|
|
255
|
-
super();
|
|
256
|
-
this._sentinel = {};
|
|
257
|
-
this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
|
|
258
|
-
if (options) {
|
|
259
|
-
const { hashFn, objHashFn, toEntryFn } = options;
|
|
260
|
-
if (hashFn) this._hashFn = hashFn;
|
|
261
|
-
if (objHashFn) this._objHashFn = objHashFn;
|
|
262
|
-
if (toEntryFn) this._toEntryFn = toEntryFn;
|
|
263
|
-
}
|
|
264
|
-
if (entryOrRawElements) this.setMany(entryOrRawElements);
|
|
265
|
-
}
|
|
266
|
-
_hashFn = __name((key) => String(key), "_hashFn");
|
|
267
|
-
get hashFn() {
|
|
268
|
-
return this._hashFn;
|
|
269
|
-
}
|
|
270
|
-
_objHashFn = __name((key) => key, "_objHashFn");
|
|
271
|
-
get objHashFn() {
|
|
272
|
-
return this._objHashFn;
|
|
273
|
-
}
|
|
274
|
-
_noObjMap = {};
|
|
275
|
-
get noObjMap() {
|
|
276
|
-
return this._noObjMap;
|
|
277
|
-
}
|
|
278
|
-
_objMap = new WeakMap();
|
|
279
|
-
get objMap() {
|
|
280
|
-
return this._objMap;
|
|
281
|
-
}
|
|
282
|
-
_head;
|
|
283
|
-
get head() {
|
|
284
|
-
return this._head;
|
|
285
|
-
}
|
|
286
|
-
_tail;
|
|
287
|
-
get tail() {
|
|
288
|
-
return this._tail;
|
|
289
|
-
}
|
|
290
|
-
_toEntryFn = __name((rawElement) => {
|
|
291
|
-
if (this.isEntry(rawElement)) {
|
|
292
|
-
return rawElement;
|
|
293
|
-
}
|
|
294
|
-
throw new Error(
|
|
295
|
-
"If `entryOrRawElements` does not adhere to [key,value], provide `options.toEntryFn` to transform raw records."
|
|
296
|
-
);
|
|
297
|
-
}, "_toEntryFn");
|
|
298
|
-
get toEntryFn() {
|
|
299
|
-
return this._toEntryFn;
|
|
300
|
-
}
|
|
301
|
-
_size = 0;
|
|
302
|
-
get size() {
|
|
303
|
-
return this._size;
|
|
304
|
-
}
|
|
305
|
-
get first() {
|
|
306
|
-
if (this._size === 0) return;
|
|
307
|
-
return [this.head.key, this.head.value];
|
|
308
|
-
}
|
|
309
|
-
get last() {
|
|
310
|
-
if (this._size === 0) return;
|
|
311
|
-
return [this.tail.key, this.tail.value];
|
|
312
|
-
}
|
|
313
|
-
*begin() {
|
|
314
|
-
let node = this.head;
|
|
315
|
-
while (node !== this._sentinel) {
|
|
316
|
-
yield [node.key, node.value];
|
|
317
|
-
node = node.next;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
*reverseBegin() {
|
|
321
|
-
let node = this.tail;
|
|
322
|
-
while (node !== this._sentinel) {
|
|
323
|
-
yield [node.key, node.value];
|
|
324
|
-
node = node.prev;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
set(key, value) {
|
|
328
|
-
let node;
|
|
329
|
-
const isNewKey = !this.has(key);
|
|
330
|
-
if (isWeakKey(key)) {
|
|
331
|
-
const hash = this._objHashFn(key);
|
|
332
|
-
node = this.objMap.get(hash);
|
|
333
|
-
if (!node && isNewKey) {
|
|
334
|
-
node = { key: hash, value, prev: this.tail, next: this._sentinel };
|
|
335
|
-
this.objMap.set(hash, node);
|
|
336
|
-
} else if (node) {
|
|
337
|
-
node.value = value;
|
|
338
|
-
}
|
|
339
|
-
} else {
|
|
340
|
-
const hash = this._hashFn(key);
|
|
341
|
-
node = this.noObjMap[hash];
|
|
342
|
-
if (!node && isNewKey) {
|
|
343
|
-
this.noObjMap[hash] = node = { key, value, prev: this.tail, next: this._sentinel };
|
|
344
|
-
} else if (node) {
|
|
345
|
-
node.value = value;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
if (node && isNewKey) {
|
|
349
|
-
if (this._size === 0) {
|
|
350
|
-
this._head = node;
|
|
351
|
-
this._sentinel.next = node;
|
|
352
|
-
} else {
|
|
353
|
-
this.tail.next = node;
|
|
354
|
-
node.prev = this.tail;
|
|
355
|
-
}
|
|
356
|
-
this._tail = node;
|
|
357
|
-
this._sentinel.prev = node;
|
|
358
|
-
this._size++;
|
|
359
|
-
}
|
|
360
|
-
return true;
|
|
361
|
-
}
|
|
362
|
-
setMany(entryOrRawElements) {
|
|
363
|
-
const results = [];
|
|
364
|
-
for (const rawEle of entryOrRawElements) {
|
|
365
|
-
let key, value;
|
|
366
|
-
if (this.isEntry(rawEle)) [key, value] = rawEle;
|
|
367
|
-
else if (this._toEntryFn) [key, value] = this._toEntryFn(rawEle);
|
|
368
|
-
if (key !== void 0 && value !== void 0) results.push(this.set(key, value));
|
|
369
|
-
}
|
|
370
|
-
return results;
|
|
371
|
-
}
|
|
372
|
-
has(key) {
|
|
373
|
-
if (isWeakKey(key)) {
|
|
374
|
-
const hash2 = this._objHashFn(key);
|
|
375
|
-
return this.objMap.has(hash2);
|
|
376
|
-
}
|
|
377
|
-
const hash = this._hashFn(key);
|
|
378
|
-
return hash in this.noObjMap;
|
|
379
|
-
}
|
|
380
|
-
get(key) {
|
|
381
|
-
if (isWeakKey(key)) {
|
|
382
|
-
const hash2 = this._objHashFn(key);
|
|
383
|
-
const node2 = this.objMap.get(hash2);
|
|
384
|
-
return node2 ? node2.value : void 0;
|
|
385
|
-
}
|
|
386
|
-
const hash = this._hashFn(key);
|
|
387
|
-
const node = this.noObjMap[hash];
|
|
388
|
-
return node ? node.value : void 0;
|
|
389
|
-
}
|
|
390
|
-
at(index) {
|
|
391
|
-
rangeCheck(index, 0, this._size - 1);
|
|
392
|
-
let node = this.head;
|
|
393
|
-
while (index--) node = node.next;
|
|
394
|
-
return node.value;
|
|
395
|
-
}
|
|
396
|
-
delete(key) {
|
|
397
|
-
let node;
|
|
398
|
-
if (isWeakKey(key)) {
|
|
399
|
-
const hash = this._objHashFn(key);
|
|
400
|
-
node = this.objMap.get(hash);
|
|
401
|
-
if (!node) return false;
|
|
402
|
-
this.objMap.delete(hash);
|
|
403
|
-
} else {
|
|
404
|
-
const hash = this._hashFn(key);
|
|
405
|
-
node = this.noObjMap[hash];
|
|
406
|
-
if (!node) return false;
|
|
407
|
-
delete this.noObjMap[hash];
|
|
408
|
-
}
|
|
409
|
-
return this._deleteNode(node);
|
|
410
|
-
}
|
|
411
|
-
deleteWhere(predicate) {
|
|
412
|
-
let node = this._head;
|
|
413
|
-
let i = 0;
|
|
414
|
-
while (node !== this._sentinel) {
|
|
415
|
-
const cur = node;
|
|
416
|
-
node = node.next;
|
|
417
|
-
if (predicate(cur.key, cur.value, i++, this)) {
|
|
418
|
-
if (isWeakKey(cur.key)) {
|
|
419
|
-
this._objMap.delete(cur.key);
|
|
420
|
-
} else {
|
|
421
|
-
const hash = this._hashFn(cur.key);
|
|
422
|
-
delete this._noObjMap[hash];
|
|
423
|
-
}
|
|
424
|
-
return this._deleteNode(cur);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
return false;
|
|
428
|
-
}
|
|
429
|
-
deleteAt(index) {
|
|
430
|
-
rangeCheck(index, 0, this._size - 1);
|
|
431
|
-
let node = this.head;
|
|
432
|
-
while (index--) node = node.next;
|
|
433
|
-
return this._deleteNode(node);
|
|
434
|
-
}
|
|
435
|
-
isEmpty() {
|
|
436
|
-
return this._size === 0;
|
|
437
|
-
}
|
|
438
|
-
isEntry(rawElement) {
|
|
439
|
-
return Array.isArray(rawElement) && rawElement.length === 2;
|
|
440
|
-
}
|
|
441
|
-
clear() {
|
|
442
|
-
this._noObjMap = {};
|
|
443
|
-
this._size = 0;
|
|
444
|
-
this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
|
|
445
|
-
}
|
|
446
|
-
clone() {
|
|
447
|
-
const opts = { hashFn: this._hashFn, objHashFn: this._objHashFn };
|
|
448
|
-
return this._createLike(this, opts);
|
|
449
|
-
}
|
|
450
|
-
filter(predicate, thisArg) {
|
|
451
|
-
const out = this._createLike();
|
|
452
|
-
let index = 0;
|
|
453
|
-
for (const [key, value] of this) {
|
|
454
|
-
if (predicate.call(thisArg, value, key, index, this)) out.set(key, value);
|
|
455
|
-
index++;
|
|
456
|
-
}
|
|
457
|
-
return out;
|
|
458
|
-
}
|
|
459
|
-
map(callback, thisArg) {
|
|
460
|
-
const out = this._createLike();
|
|
461
|
-
let index = 0;
|
|
462
|
-
for (const [key, value] of this) {
|
|
463
|
-
const [newKey, newValue] = callback.call(thisArg, value, key, index, this);
|
|
464
|
-
out.set(newKey, newValue);
|
|
465
|
-
index++;
|
|
466
|
-
}
|
|
467
|
-
return out;
|
|
468
|
-
}
|
|
469
|
-
*_getIterator() {
|
|
470
|
-
let node = this.head;
|
|
471
|
-
while (node !== this._sentinel) {
|
|
472
|
-
yield [node.key, node.value];
|
|
473
|
-
node = node.next;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
_deleteNode(node) {
|
|
477
|
-
const { prev, next } = node;
|
|
478
|
-
prev.next = next;
|
|
479
|
-
next.prev = prev;
|
|
480
|
-
if (node === this.head) this._head = next;
|
|
481
|
-
if (node === this.tail) this._tail = prev;
|
|
482
|
-
this._size -= 1;
|
|
483
|
-
return true;
|
|
484
|
-
}
|
|
485
|
-
_createLike(entries = [], options) {
|
|
486
|
-
const Ctor = this.constructor;
|
|
487
|
-
return new Ctor(entries, options);
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
export {
|
|
491
|
-
HashMap,
|
|
492
|
-
LinkedHashMap
|
|
493
|
-
};
|