data-structure-typed 2.4.3 → 2.4.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/workflows/release.yml +27 -0
- package/CHANGELOG.md +3 -1
- package/README.md +46 -50
- package/dist/cjs/index.cjs +27 -35
- package/dist/cjs-legacy/index.cjs +28 -35
- package/dist/esm/index.mjs +27 -35
- package/dist/esm-legacy/index.mjs +28 -35
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/types/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/types/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/types/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/types/data-structures/heap/heap.d.ts +3 -7
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +1 -1
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/types/data-structures/stack/stack.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +28 -35
- package/dist/umd/data-structure-typed.min.js +4 -4
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +8 -7
- package/src/data-structures/binary-tree/bst.ts +1 -1
- package/src/data-structures/binary-tree/tree-multi-set.ts +5 -5
- package/src/data-structures/graph/abstract-graph.ts +18 -18
- package/src/data-structures/graph/directed-graph.ts +4 -4
- package/src/data-structures/graph/map-graph.ts +1 -1
- package/src/data-structures/graph/undirected-graph.ts +4 -4
- package/src/data-structures/hash/hash-map.ts +6 -4
- package/src/data-structures/heap/heap.ts +17 -14
- package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
- package/src/data-structures/linked-list/singly-linked-list.ts +15 -9
- package/src/data-structures/queue/deque.ts +1 -1
- package/src/data-structures/stack/stack.ts +1 -1
- package/src/data-structures/trie/trie.ts +10 -5
- package/src/types/data-structures/binary-tree/avl-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/red-black-tree.ts +1 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/types/data-structures/stack/stack.ts +1 -1
|
@@ -1105,8 +1105,9 @@ var dataStructureTyped = (() => {
|
|
|
1105
1105
|
const cur = node;
|
|
1106
1106
|
node = node.next;
|
|
1107
1107
|
if (predicate(cur.key, cur.value, i++, this)) {
|
|
1108
|
-
|
|
1109
|
-
|
|
1108
|
+
const keyToCheck = cur.key;
|
|
1109
|
+
if (isWeakKey(keyToCheck)) {
|
|
1110
|
+
this._objMap.delete(keyToCheck);
|
|
1110
1111
|
} else {
|
|
1111
1112
|
const hash = this._hashFn(cur.key);
|
|
1112
1113
|
delete this._noObjMap[hash];
|
|
@@ -1614,7 +1615,7 @@ var dataStructureTyped = (() => {
|
|
|
1614
1615
|
*/
|
|
1615
1616
|
constructor(elements = [], options) {
|
|
1616
1617
|
super(options);
|
|
1617
|
-
__publicField(this, "_equals", Object.is);
|
|
1618
|
+
__publicField(this, "_equals", (a, b) => Object.is(a, b));
|
|
1618
1619
|
__publicField(this, "_head");
|
|
1619
1620
|
__publicField(this, "_tail");
|
|
1620
1621
|
__publicField(this, "_length", 0);
|
|
@@ -1702,6 +1703,7 @@ var dataStructureTyped = (() => {
|
|
|
1702
1703
|
* @returns Removed element or undefined.
|
|
1703
1704
|
*/
|
|
1704
1705
|
pop() {
|
|
1706
|
+
var _a;
|
|
1705
1707
|
if (!this.head) return void 0;
|
|
1706
1708
|
if (this.head === this.tail) {
|
|
1707
1709
|
const value2 = this.head.value;
|
|
@@ -1711,8 +1713,8 @@ var dataStructureTyped = (() => {
|
|
|
1711
1713
|
return value2;
|
|
1712
1714
|
}
|
|
1713
1715
|
let current = this.head;
|
|
1714
|
-
while (current.next !== this.tail) current = current.next;
|
|
1715
|
-
const value = this.tail.value;
|
|
1716
|
+
while (current.next && current.next !== this.tail) current = current.next;
|
|
1717
|
+
const value = (_a = this.tail) == null ? void 0 : _a.value;
|
|
1716
1718
|
current.next = void 0;
|
|
1717
1719
|
this._tail = current;
|
|
1718
1720
|
this._length--;
|
|
@@ -1800,8 +1802,8 @@ var dataStructureTyped = (() => {
|
|
|
1800
1802
|
at(index) {
|
|
1801
1803
|
if (index < 0 || index >= this._length) return void 0;
|
|
1802
1804
|
let current = this.head;
|
|
1803
|
-
for (let i = 0; i < index; i++) current = current.next;
|
|
1804
|
-
return current.value;
|
|
1805
|
+
for (let i = 0; i < index && current; i++) current = current.next;
|
|
1806
|
+
return current == null ? void 0 : current.value;
|
|
1805
1807
|
}
|
|
1806
1808
|
/**
|
|
1807
1809
|
* Type guard: check whether the input is a SinglyLinkedListNode.
|
|
@@ -1821,7 +1823,7 @@ var dataStructureTyped = (() => {
|
|
|
1821
1823
|
getNodeAt(index) {
|
|
1822
1824
|
if (index < 0 || index >= this._length) return void 0;
|
|
1823
1825
|
let current = this.head;
|
|
1824
|
-
for (let i = 0; i < index; i++) current = current.next;
|
|
1826
|
+
for (let i = 0; i < index && current; i++) current = current.next;
|
|
1825
1827
|
return current;
|
|
1826
1828
|
}
|
|
1827
1829
|
/**
|
|
@@ -2332,7 +2334,7 @@ var dataStructureTyped = (() => {
|
|
|
2332
2334
|
*/
|
|
2333
2335
|
constructor(elements = [], options) {
|
|
2334
2336
|
super(options);
|
|
2335
|
-
__publicField(this, "_equals", Object.is);
|
|
2337
|
+
__publicField(this, "_equals", (a, b) => Object.is(a, b));
|
|
2336
2338
|
__publicField(this, "_head");
|
|
2337
2339
|
__publicField(this, "_tail");
|
|
2338
2340
|
__publicField(this, "_length", 0);
|
|
@@ -2520,8 +2522,8 @@ var dataStructureTyped = (() => {
|
|
|
2520
2522
|
at(index) {
|
|
2521
2523
|
if (index < 0 || index >= this._length) return void 0;
|
|
2522
2524
|
let current = this.head;
|
|
2523
|
-
for (let i = 0; i < index; i++) current = current.next;
|
|
2524
|
-
return current.value;
|
|
2525
|
+
for (let i = 0; i < index && current; i++) current = current.next;
|
|
2526
|
+
return current == null ? void 0 : current.value;
|
|
2525
2527
|
}
|
|
2526
2528
|
/**
|
|
2527
2529
|
* Get the node reference at a given index.
|
|
@@ -2532,7 +2534,7 @@ var dataStructureTyped = (() => {
|
|
|
2532
2534
|
getNodeAt(index) {
|
|
2533
2535
|
if (index < 0 || index >= this._length) return void 0;
|
|
2534
2536
|
let current = this.head;
|
|
2535
|
-
for (let i = 0; i < index; i++) current = current.next;
|
|
2537
|
+
for (let i = 0; i < index && current; i++) current = current.next;
|
|
2536
2538
|
return current;
|
|
2537
2539
|
}
|
|
2538
2540
|
/**
|
|
@@ -3038,7 +3040,7 @@ var dataStructureTyped = (() => {
|
|
|
3038
3040
|
*/
|
|
3039
3041
|
constructor(elements = [], options) {
|
|
3040
3042
|
super(options);
|
|
3041
|
-
__publicField(this, "_equals", Object.is);
|
|
3043
|
+
__publicField(this, "_equals", (a, b) => Object.is(a, b));
|
|
3042
3044
|
__publicField(this, "_elements", []);
|
|
3043
3045
|
this.pushMany(elements);
|
|
3044
3046
|
}
|
|
@@ -3667,7 +3669,7 @@ var dataStructureTyped = (() => {
|
|
|
3667
3669
|
*/
|
|
3668
3670
|
constructor(elements = [], options) {
|
|
3669
3671
|
super(options);
|
|
3670
|
-
__publicField(this, "_equals", Object.is);
|
|
3672
|
+
__publicField(this, "_equals", (a, b) => Object.is(a, b));
|
|
3671
3673
|
__publicField(this, "_bucketSize", 1 << 12);
|
|
3672
3674
|
__publicField(this, "_bucketFirst", 0);
|
|
3673
3675
|
__publicField(this, "_firstInBucket", 0);
|
|
@@ -4737,11 +4739,6 @@ var dataStructureTyped = (() => {
|
|
|
4737
4739
|
}
|
|
4738
4740
|
return out;
|
|
4739
4741
|
}
|
|
4740
|
-
/**
|
|
4741
|
-
* Get the comparator used to order elements.
|
|
4742
|
-
* @remarks Time O(1), Space O(1)
|
|
4743
|
-
* @returns Comparator function.
|
|
4744
|
-
*/
|
|
4745
4742
|
/**
|
|
4746
4743
|
* Get the comparator used to order elements.
|
|
4747
4744
|
* @remarks Time O(1), Space O(1)
|
|
@@ -4790,8 +4787,7 @@ var dataStructureTyped = (() => {
|
|
|
4790
4787
|
*/
|
|
4791
4788
|
_createInstance(options) {
|
|
4792
4789
|
const Ctor = this.constructor;
|
|
4793
|
-
|
|
4794
|
-
return next;
|
|
4790
|
+
return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
|
|
4795
4791
|
}
|
|
4796
4792
|
/**
|
|
4797
4793
|
* (Protected) Create a like-kind instance seeded by elements.
|
|
@@ -5823,8 +5819,8 @@ var dataStructureTyped = (() => {
|
|
|
5823
5819
|
const Ctor = this.constructor;
|
|
5824
5820
|
const instance = new Ctor();
|
|
5825
5821
|
const graph = _options == null ? void 0 : _options.graph;
|
|
5826
|
-
if (graph) instance
|
|
5827
|
-
else instance
|
|
5822
|
+
if (graph) instance["_options"] = { ...instance["_options"], ...graph };
|
|
5823
|
+
else instance["_options"] = { ...instance["_options"], ...this._options };
|
|
5828
5824
|
return instance;
|
|
5829
5825
|
}
|
|
5830
5826
|
/**
|
|
@@ -5857,12 +5853,10 @@ var dataStructureTyped = (() => {
|
|
|
5857
5853
|
const [va, vb] = ends;
|
|
5858
5854
|
const ka = va.key;
|
|
5859
5855
|
const kb = vb.key;
|
|
5860
|
-
const hasA = g.hasVertex ? g.hasVertex(ka) : false;
|
|
5861
|
-
const hasB = g.hasVertex ? g.hasVertex(kb) : false;
|
|
5856
|
+
const hasA = typeof g.hasVertex === "function" ? g.hasVertex(ka) : false;
|
|
5857
|
+
const hasB = typeof g.hasVertex === "function" ? g.hasVertex(kb) : false;
|
|
5862
5858
|
if (hasA && hasB) {
|
|
5863
|
-
const
|
|
5864
|
-
const val = e.value;
|
|
5865
|
-
const newEdge = g.createEdge(ka, kb, w, val);
|
|
5859
|
+
const newEdge = g.createEdge(ka, kb, e.weight, e.value);
|
|
5866
5860
|
g._addEdge(newEdge);
|
|
5867
5861
|
}
|
|
5868
5862
|
}
|
|
@@ -7030,7 +7024,7 @@ var dataStructureTyped = (() => {
|
|
|
7030
7024
|
* @param node - The node.
|
|
7031
7025
|
* @returns The node's key or undefined.
|
|
7032
7026
|
*/
|
|
7033
|
-
__publicField(this, "_DEFAULT_NODE_CALLBACK", (node) => node
|
|
7027
|
+
__publicField(this, "_DEFAULT_NODE_CALLBACK", (node) => node == null ? void 0 : node.key);
|
|
7034
7028
|
if (options) {
|
|
7035
7029
|
const { iterationType, toEntryFn, isMapMode, isDuplicate } = options;
|
|
7036
7030
|
if (iterationType) this.iterationType = iterationType;
|
|
@@ -13225,7 +13219,7 @@ var dataStructureTyped = (() => {
|
|
|
13225
13219
|
* @remarks Time O(1), Space O(1)
|
|
13226
13220
|
*/
|
|
13227
13221
|
get comparator() {
|
|
13228
|
-
return __privateGet(this, _core4).
|
|
13222
|
+
return __privateGet(this, _core4).comparator;
|
|
13229
13223
|
}
|
|
13230
13224
|
// ━━━ clear ━━━
|
|
13231
13225
|
/**
|
|
@@ -13362,7 +13356,7 @@ var dataStructureTyped = (() => {
|
|
|
13362
13356
|
filter(predicate) {
|
|
13363
13357
|
const result = new _TreeMultiSet([], {
|
|
13364
13358
|
comparator: __privateGet(this, _isDefaultComparator4) ? void 0 : this.comparator,
|
|
13365
|
-
isMapMode: __privateGet(this, _core4).
|
|
13359
|
+
isMapMode: __privateGet(this, _core4).isMapMode
|
|
13366
13360
|
});
|
|
13367
13361
|
for (const [k, c] of this.entries()) {
|
|
13368
13362
|
if (predicate(k, c)) {
|
|
@@ -13402,7 +13396,7 @@ var dataStructureTyped = (() => {
|
|
|
13402
13396
|
map(mapper, options) {
|
|
13403
13397
|
const result = new _TreeMultiSet([], {
|
|
13404
13398
|
comparator: options == null ? void 0 : options.comparator,
|
|
13405
|
-
isMapMode: __privateGet(this, _core4).
|
|
13399
|
+
isMapMode: __privateGet(this, _core4).isMapMode
|
|
13406
13400
|
});
|
|
13407
13401
|
for (const [k, c] of this.entries()) {
|
|
13408
13402
|
const [newKey, newCount] = mapper(k, c);
|
|
@@ -13422,7 +13416,7 @@ var dataStructureTyped = (() => {
|
|
|
13422
13416
|
clone() {
|
|
13423
13417
|
const result = new _TreeMultiSet([], {
|
|
13424
13418
|
comparator: __privateGet(this, _isDefaultComparator4) ? void 0 : this.comparator,
|
|
13425
|
-
isMapMode: __privateGet(this, _core4).
|
|
13419
|
+
isMapMode: __privateGet(this, _core4).isMapMode
|
|
13426
13420
|
});
|
|
13427
13421
|
for (const [k, c] of this.entries()) {
|
|
13428
13422
|
result.add(k, c);
|
|
@@ -14455,12 +14449,11 @@ var dataStructureTyped = (() => {
|
|
|
14455
14449
|
*/
|
|
14456
14450
|
_createInstance(options) {
|
|
14457
14451
|
const Ctor = this.constructor;
|
|
14458
|
-
|
|
14452
|
+
return new Ctor([], {
|
|
14459
14453
|
toElementFn: this.toElementFn,
|
|
14460
14454
|
caseSensitive: this.caseSensitive,
|
|
14461
14455
|
...options != null ? options : {}
|
|
14462
14456
|
});
|
|
14463
|
-
return next;
|
|
14464
14457
|
}
|
|
14465
14458
|
/**
|
|
14466
14459
|
* (Protected) Create a like-kind trie and seed it from an iterable.
|