data-structure-typed 1.46.2 → 1.46.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/CHANGELOG.md +1 -1
- package/README.md +16 -16
- package/benchmark/report.html +1 -46
- package/benchmark/report.json +8 -389
- package/dist/cjs/data-structures/hash/hash-map.d.ts +31 -116
- package/dist/cjs/data-structures/hash/hash-map.js +127 -254
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/index.d.ts +0 -4
- package/dist/cjs/data-structures/hash/index.js +0 -4
- package/dist/cjs/data-structures/hash/index.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +6 -74
- package/dist/cjs/data-structures/queue/deque.js +20 -142
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +5 -0
- package/dist/cjs/types/data-structures/hash/index.d.ts +0 -4
- package/dist/cjs/types/data-structures/hash/index.js +0 -4
- package/dist/cjs/types/data-structures/hash/index.js.map +1 -1
- package/dist/cjs/utils/utils.d.ts +1 -1
- package/dist/cjs/utils/utils.js +3 -3
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +31 -116
- package/dist/mjs/data-structures/hash/hash-map.js +129 -257
- package/dist/mjs/data-structures/hash/index.d.ts +0 -4
- package/dist/mjs/data-structures/hash/index.js +0 -4
- package/dist/mjs/data-structures/queue/deque.d.ts +6 -74
- package/dist/mjs/data-structures/queue/deque.js +16 -140
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +5 -0
- package/dist/mjs/types/data-structures/hash/index.d.ts +0 -4
- package/dist/mjs/types/data-structures/hash/index.js +0 -4
- package/dist/mjs/utils/utils.d.ts +1 -1
- package/dist/mjs/utils/utils.js +1 -1
- package/dist/umd/data-structure-typed.js +169 -531
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +4 -3
- package/src/data-structures/hash/hash-map.ts +154 -275
- package/src/data-structures/hash/index.ts +0 -4
- package/src/data-structures/queue/deque.ts +22 -161
- package/src/types/data-structures/hash/hash-map.ts +6 -0
- package/src/types/data-structures/hash/index.ts +0 -4
- package/src/utils/utils.ts +1 -1
- package/test/performance/data-structures/hash/hash-map.test.ts +86 -11
- package/test/performance/reportor.ts +6 -3
- package/test/unit/data-structures/hash/hash-map.test.ts +36 -5
- package/test/unit/data-structures/queue/deque.test.ts +28 -0
- package/dist/cjs/data-structures/hash/coordinate-map.d.ts +0 -44
- package/dist/cjs/data-structures/hash/coordinate-map.js +0 -63
- package/dist/cjs/data-structures/hash/coordinate-map.js.map +0 -1
- package/dist/cjs/data-structures/hash/coordinate-set.d.ts +0 -36
- package/dist/cjs/data-structures/hash/coordinate-set.js +0 -53
- package/dist/cjs/data-structures/hash/coordinate-set.js.map +0 -1
- package/dist/cjs/data-structures/hash/tree-map.d.ts +0 -2
- package/dist/cjs/data-structures/hash/tree-map.js +0 -7
- package/dist/cjs/data-structures/hash/tree-map.js.map +0 -1
- package/dist/cjs/data-structures/hash/tree-set.d.ts +0 -2
- package/dist/cjs/data-structures/hash/tree-set.js +0 -7
- package/dist/cjs/data-structures/hash/tree-set.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/coordinate-map.d.ts +0 -1
- package/dist/cjs/types/data-structures/hash/coordinate-map.js +0 -3
- package/dist/cjs/types/data-structures/hash/coordinate-map.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/coordinate-set.d.ts +0 -1
- package/dist/cjs/types/data-structures/hash/coordinate-set.js +0 -3
- package/dist/cjs/types/data-structures/hash/coordinate-set.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/cjs/types/data-structures/hash/tree-map.js +0 -3
- package/dist/cjs/types/data-structures/hash/tree-map.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/cjs/types/data-structures/hash/tree-set.js +0 -3
- package/dist/cjs/types/data-structures/hash/tree-set.js.map +0 -1
- package/dist/mjs/data-structures/hash/coordinate-map.d.ts +0 -44
- package/dist/mjs/data-structures/hash/coordinate-map.js +0 -58
- package/dist/mjs/data-structures/hash/coordinate-set.d.ts +0 -36
- package/dist/mjs/data-structures/hash/coordinate-set.js +0 -48
- package/dist/mjs/data-structures/hash/tree-map.d.ts +0 -2
- package/dist/mjs/data-structures/hash/tree-map.js +0 -2
- package/dist/mjs/data-structures/hash/tree-set.d.ts +0 -2
- package/dist/mjs/data-structures/hash/tree-set.js +0 -2
- package/dist/mjs/types/data-structures/hash/coordinate-map.d.ts +0 -1
- package/dist/mjs/types/data-structures/hash/coordinate-map.js +0 -1
- package/dist/mjs/types/data-structures/hash/coordinate-set.d.ts +0 -1
- package/dist/mjs/types/data-structures/hash/coordinate-set.js +0 -1
- package/dist/mjs/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/mjs/types/data-structures/hash/tree-map.js +0 -1
- package/dist/mjs/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/mjs/types/data-structures/hash/tree-set.js +0 -1
- package/src/data-structures/hash/coordinate-map.ts +0 -63
- package/src/data-structures/hash/coordinate-set.ts +0 -52
- package/src/data-structures/hash/tree-map.ts +0 -2
- package/src/data-structures/hash/tree-set.ts +0 -2
- package/src/types/data-structures/hash/coordinate-map.ts +0 -1
- package/src/types/data-structures/hash/coordinate-set.ts +0 -1
- package/src/types/data-structures/hash/tree-map.ts +0 -1
- package/src/types/data-structures/hash/tree-set.ts +0 -1
- package/test/performance/data-structures/hash/coordinate-map.test.ts +0 -0
- package/test/performance/data-structures/hash/coordinate-set.test.ts +0 -0
- package/test/unit/data-structures/hash/coordinate-map.test.ts +0 -74
- package/test/unit/data-structures/hash/coordinate-set.test.ts +0 -66
|
@@ -100,10 +100,7 @@ var dataStructureTyped = (() => {
|
|
|
100
100
|
BinaryTreeNode: () => BinaryTreeNode,
|
|
101
101
|
CP: () => CP,
|
|
102
102
|
Character: () => Character,
|
|
103
|
-
CoordinateMap: () => CoordinateMap,
|
|
104
|
-
CoordinateSet: () => CoordinateSet,
|
|
105
103
|
Deque: () => Deque,
|
|
106
|
-
DequeIterator: () => DequeIterator,
|
|
107
104
|
DirectedEdge: () => DirectedEdge,
|
|
108
105
|
DirectedGraph: () => DirectedGraph,
|
|
109
106
|
DirectedVertex: () => DirectedVertex,
|
|
@@ -113,7 +110,6 @@ var dataStructureTyped = (() => {
|
|
|
113
110
|
FibonacciHeap: () => FibonacciHeap,
|
|
114
111
|
FibonacciHeapNode: () => FibonacciHeapNode,
|
|
115
112
|
HashMap: () => HashMap,
|
|
116
|
-
HashMapIterator: () => HashMapIterator,
|
|
117
113
|
HashTable: () => HashTable,
|
|
118
114
|
HashTableNode: () => HashTableNode,
|
|
119
115
|
Heap: () => Heap,
|
|
@@ -144,11 +140,9 @@ var dataStructureTyped = (() => {
|
|
|
144
140
|
SkipListNode: () => SkipListNode,
|
|
145
141
|
Stack: () => Stack,
|
|
146
142
|
THUNK_SYMBOL: () => THUNK_SYMBOL,
|
|
147
|
-
TreeMap: () => TreeMap,
|
|
148
143
|
TreeMultimap: () => TreeMultimap,
|
|
149
144
|
TreeMultimapNode: () => TreeMultimapNode,
|
|
150
145
|
TreeNode: () => TreeNode,
|
|
151
|
-
TreeSet: () => TreeSet,
|
|
152
146
|
Trie: () => Trie,
|
|
153
147
|
TrieNode: () => TrieNode,
|
|
154
148
|
UndirectedEdge: () => UndirectedEdge,
|
|
@@ -158,8 +152,8 @@ var dataStructureTyped = (() => {
|
|
|
158
152
|
arrayRemove: () => arrayRemove,
|
|
159
153
|
calcMinUnitsRequired: () => calcMinUnitsRequired,
|
|
160
154
|
getMSB: () => getMSB,
|
|
161
|
-
isObjOrFunc: () => isObjOrFunc,
|
|
162
155
|
isThunk: () => isThunk,
|
|
156
|
+
isWeakKey: () => isWeakKey,
|
|
163
157
|
rangeCheck: () => rangeCheck,
|
|
164
158
|
throwRangeError: () => throwRangeError,
|
|
165
159
|
toThunk: () => toThunk,
|
|
@@ -390,110 +384,6 @@ var dataStructureTyped = (() => {
|
|
|
390
384
|
__publicField(_HashTable, "LOAD_FACTOR", 0.75);
|
|
391
385
|
var HashTable = _HashTable;
|
|
392
386
|
|
|
393
|
-
// src/data-structures/hash/coordinate-map.ts
|
|
394
|
-
var CoordinateMap = class extends Map {
|
|
395
|
-
constructor(joint) {
|
|
396
|
-
super();
|
|
397
|
-
__publicField(this, "_joint", "_");
|
|
398
|
-
if (joint !== void 0)
|
|
399
|
-
this._joint = joint;
|
|
400
|
-
}
|
|
401
|
-
get joint() {
|
|
402
|
-
return this._joint;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
|
|
406
|
-
* key array with a specified delimiter.
|
|
407
|
-
* @param {number[]} key - The parameter "key" is an array of numbers.
|
|
408
|
-
* @returns The `has` method is being overridden to return the result of calling the `has` method of the superclass
|
|
409
|
-
* (`super.has`) with the `key` array joined together using the `_joint` property.
|
|
410
|
-
*/
|
|
411
|
-
has(key) {
|
|
412
|
-
return super.has(key.join(this._joint));
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* The function overrides the set method of a Map object to convert the key from an array to a string using a specified
|
|
416
|
-
* delimiter before calling the original set method.
|
|
417
|
-
* @param {number[]} key - The key parameter is an array of numbers.
|
|
418
|
-
* @param {V} value - The value parameter is the value that you want to associate with the specified key.
|
|
419
|
-
* @returns The `set` method is returning the result of calling the `set` method of the superclass
|
|
420
|
-
* (`super.set(key.join(this._joint), value)`).
|
|
421
|
-
*/
|
|
422
|
-
set(key, value) {
|
|
423
|
-
return super.set(key.join(this._joint), value);
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* The function overrides the get method to join the key array with a specified joint and then calls the super get
|
|
427
|
-
* method.
|
|
428
|
-
* @param {number[]} key - An array of numbers
|
|
429
|
-
* @returns The code is returning the value associated with the specified key in the map.
|
|
430
|
-
*/
|
|
431
|
-
get(key) {
|
|
432
|
-
return super.get(key.join(this._joint));
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* The function overrides the delete method and joins the key array using a specified joint character before calling
|
|
436
|
-
* the super delete method.
|
|
437
|
-
* @param {number[]} key - An array of numbers that represents the key to be deleted.
|
|
438
|
-
* @returns The `delete` method is returning the result of calling the `delete` method on the superclass, with the
|
|
439
|
-
* `key` array joined together using the `_joint` property.
|
|
440
|
-
*/
|
|
441
|
-
delete(key) {
|
|
442
|
-
return super.delete(key.join(this._joint));
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
// src/data-structures/hash/coordinate-set.ts
|
|
447
|
-
var CoordinateSet = class extends Set {
|
|
448
|
-
constructor(joint) {
|
|
449
|
-
super();
|
|
450
|
-
__publicField(this, "_joint", "_");
|
|
451
|
-
if (joint !== void 0)
|
|
452
|
-
this._joint = joint;
|
|
453
|
-
}
|
|
454
|
-
get joint() {
|
|
455
|
-
return this._joint;
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
|
|
459
|
-
* joining its elements with a specified separator.
|
|
460
|
-
* @param {number[]} value - The parameter "value" is an array of numbers.
|
|
461
|
-
* @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
|
|
462
|
-
* in the joined value as an argument.
|
|
463
|
-
*/
|
|
464
|
-
has(value) {
|
|
465
|
-
return super.has(value.join(this._joint));
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
|
|
469
|
-
* specified delimiter before calling the parent class's "add" function.
|
|
470
|
-
* @param {number[]} value - An array of numbers
|
|
471
|
-
* @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
|
|
472
|
-
* (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
|
|
473
|
-
*/
|
|
474
|
-
add(value) {
|
|
475
|
-
return super.add(value.join(this._joint));
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* The function overrides the delete method and deletes an element from a Set by joining the elements of the input
|
|
479
|
-
* array with a specified joint and then calling the delete method of the parent class.
|
|
480
|
-
* @param {number[]} value - An array of numbers
|
|
481
|
-
* @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
|
|
482
|
-
* `value` array joined together using the `_joint` property.
|
|
483
|
-
*/
|
|
484
|
-
delete(value) {
|
|
485
|
-
return super.delete(value.join(this._joint));
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
// src/data-structures/hash/tree-map.ts
|
|
490
|
-
var TreeMap = class {
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
// src/data-structures/hash/tree-set.ts
|
|
494
|
-
var TreeSet = class {
|
|
495
|
-
};
|
|
496
|
-
|
|
497
387
|
// src/utils/utils.ts
|
|
498
388
|
var uuidV4 = function() {
|
|
499
389
|
return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g, function(c) {
|
|
@@ -562,220 +452,46 @@ var dataStructureTyped = (() => {
|
|
|
562
452
|
var throwRangeError = (message = "The value is off-limits.") => {
|
|
563
453
|
throw new RangeError(message);
|
|
564
454
|
};
|
|
565
|
-
var
|
|
455
|
+
var isWeakKey = (input) => {
|
|
566
456
|
const inputType = typeof input;
|
|
567
457
|
return inputType === "object" && input !== null || inputType === "function";
|
|
568
458
|
};
|
|
569
459
|
var calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
|
|
570
460
|
|
|
571
|
-
// src/types/data-structures/binary-tree/binary-tree.ts
|
|
572
|
-
var IterationType = /* @__PURE__ */ ((IterationType3) => {
|
|
573
|
-
IterationType3["ITERATIVE"] = "ITERATIVE";
|
|
574
|
-
IterationType3["RECURSIVE"] = "RECURSIVE";
|
|
575
|
-
return IterationType3;
|
|
576
|
-
})(IterationType || {});
|
|
577
|
-
var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
|
|
578
|
-
FamilyPosition2["ROOT"] = "ROOT";
|
|
579
|
-
FamilyPosition2["LEFT"] = "LEFT";
|
|
580
|
-
FamilyPosition2["RIGHT"] = "RIGHT";
|
|
581
|
-
FamilyPosition2["ROOT_LEFT"] = "ROOT_LEFT";
|
|
582
|
-
FamilyPosition2["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
583
|
-
FamilyPosition2["ISOLATED"] = "ISOLATED";
|
|
584
|
-
FamilyPosition2["MAL_NODE"] = "MAL_NODE";
|
|
585
|
-
return FamilyPosition2;
|
|
586
|
-
})(FamilyPosition || {});
|
|
587
|
-
|
|
588
|
-
// src/types/data-structures/binary-tree/rb-tree.ts
|
|
589
|
-
var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
|
|
590
|
-
RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
|
|
591
|
-
RBTNColor2[RBTNColor2["BLACK"] = 0] = "BLACK";
|
|
592
|
-
return RBTNColor2;
|
|
593
|
-
})(RBTNColor || {});
|
|
594
|
-
|
|
595
|
-
// src/types/helpers.ts
|
|
596
|
-
var CP = /* @__PURE__ */ ((CP2) => {
|
|
597
|
-
CP2["lt"] = "lt";
|
|
598
|
-
CP2["eq"] = "eq";
|
|
599
|
-
CP2["gt"] = "gt";
|
|
600
|
-
return CP2;
|
|
601
|
-
})(CP || {});
|
|
602
|
-
var IterateDirection = /* @__PURE__ */ ((IterateDirection2) => {
|
|
603
|
-
IterateDirection2[IterateDirection2["DEFAULT"] = 0] = "DEFAULT";
|
|
604
|
-
IterateDirection2[IterateDirection2["REVERSE"] = 1] = "REVERSE";
|
|
605
|
-
return IterateDirection2;
|
|
606
|
-
})(IterateDirection || {});
|
|
607
|
-
|
|
608
461
|
// src/data-structures/hash/hash-map.ts
|
|
609
|
-
var
|
|
610
|
-
/**
|
|
611
|
-
* This is a constructor function for a linked list iterator in a HashMap data structure.
|
|
612
|
-
* @param node - The `node` parameter is a reference to a `HashMapLinkedNode` object. This object
|
|
613
|
-
* represents a node in a linked list used in a hash map data structure. It contains a key-value pair
|
|
614
|
-
* and references to the previous and next nodes in the linked list.
|
|
615
|
-
* @param sentinel - The `sentinel` parameter is a reference to a special node in a linked list. It
|
|
616
|
-
* is used to mark the beginning or end of the list and is typically used in data structures like
|
|
617
|
-
* hash maps or linked lists to simplify operations and boundary checks.
|
|
618
|
-
* @param hashMap - A HashMap object that stores key-value pairs.
|
|
619
|
-
* @param {IterateDirection} iterateDirection - The `iterateDirection` parameter is an optional
|
|
620
|
-
* parameter that specifies the direction in which the iterator should iterate over the elements of
|
|
621
|
-
* the HashMap. It can take one of the following values:
|
|
622
|
-
* @returns The constructor does not return anything. It is used to initialize the properties and
|
|
623
|
-
* methods of the object being created.
|
|
624
|
-
*/
|
|
625
|
-
constructor(node, sentinel, hashMap, iterateDirection = 0 /* DEFAULT */) {
|
|
626
|
-
__publicField(this, "hashMap");
|
|
627
|
-
__publicField(this, "iterateDirection");
|
|
628
|
-
__publicField(this, "_node");
|
|
629
|
-
__publicField(this, "_sentinel");
|
|
630
|
-
this._node = node;
|
|
631
|
-
this._sentinel = sentinel;
|
|
632
|
-
this.iterateDirection = iterateDirection;
|
|
633
|
-
if (this.iterateDirection === 0 /* DEFAULT */) {
|
|
634
|
-
this.prev = function() {
|
|
635
|
-
if (this._node.prev === this._sentinel) {
|
|
636
|
-
throwRangeError();
|
|
637
|
-
}
|
|
638
|
-
this._node = this._node.prev;
|
|
639
|
-
return this;
|
|
640
|
-
};
|
|
641
|
-
this.next = function() {
|
|
642
|
-
if (this._node === this._sentinel) {
|
|
643
|
-
throwRangeError();
|
|
644
|
-
}
|
|
645
|
-
this._node = this._node.next;
|
|
646
|
-
return this;
|
|
647
|
-
};
|
|
648
|
-
} else {
|
|
649
|
-
this.prev = function() {
|
|
650
|
-
if (this._node.next === this._sentinel) {
|
|
651
|
-
throwRangeError();
|
|
652
|
-
}
|
|
653
|
-
this._node = this._node.next;
|
|
654
|
-
return this;
|
|
655
|
-
};
|
|
656
|
-
this.next = function() {
|
|
657
|
-
if (this._node === this._sentinel) {
|
|
658
|
-
throwRangeError();
|
|
659
|
-
}
|
|
660
|
-
this._node = this._node.prev;
|
|
661
|
-
return this;
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
this.hashMap = hashMap;
|
|
665
|
-
}
|
|
462
|
+
var HashMap = class _HashMap {
|
|
666
463
|
/**
|
|
667
|
-
* The
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*/
|
|
671
|
-
get current() {
|
|
672
|
-
if (this._node === this._sentinel) {
|
|
673
|
-
throwRangeError();
|
|
674
|
-
}
|
|
675
|
-
return new Proxy([], {
|
|
676
|
-
get: (target, prop) => {
|
|
677
|
-
if (prop === "0")
|
|
678
|
-
return this._node.key;
|
|
679
|
-
else if (prop === "1")
|
|
680
|
-
return this._node.value;
|
|
681
|
-
target[0] = this._node.key;
|
|
682
|
-
target[1] = this._node.value;
|
|
683
|
-
return target[prop];
|
|
684
|
-
},
|
|
685
|
-
set: (_, prop, newValue) => {
|
|
686
|
-
if (prop !== "1") {
|
|
687
|
-
throw new TypeError(`prop should be string '1'`);
|
|
688
|
-
}
|
|
689
|
-
this._node.value = newValue;
|
|
690
|
-
return true;
|
|
691
|
-
}
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
/**
|
|
695
|
-
* The function checks if a node is accessible.
|
|
696
|
-
* @returns a boolean value indicating whether the `_node` is not equal to the `_sentinel`.
|
|
464
|
+
* The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs.
|
|
465
|
+
* @param options - The `options` parameter is an object that contains the `elements` property. The
|
|
466
|
+
* `elements` property is an iterable that contains key-value pairs represented as arrays `[K, V]`.
|
|
697
467
|
*/
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
return this;
|
|
706
|
-
}
|
|
707
|
-
clone() {
|
|
708
|
-
return new _HashMapIterator(this._node, this._sentinel, this.hashMap, this.iterateDirection);
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
var HashMap = class {
|
|
712
|
-
/**
|
|
713
|
-
* The constructor initializes a HashMap object with an optional initial set of key-value pairs.
|
|
714
|
-
* @param {Iterable<[K, V]>} elements - The `hashMap` parameter is an optional parameter of type `HashMapOptions<[K,
|
|
715
|
-
* V]>`. It is an array of key-value pairs, where each pair is represented as an array `[K, V]`. The
|
|
716
|
-
* `K` represents the type of the key and `V` represents the
|
|
717
|
-
*/
|
|
718
|
-
constructor(elements = []) {
|
|
719
|
-
__publicField(this, "OBJ_KEY_INDEX", Symbol("OBJ_KEY_INDEX"));
|
|
720
|
-
__publicField(this, "_nodes", []);
|
|
721
|
-
__publicField(this, "_orgMap", {});
|
|
468
|
+
constructor(options = {
|
|
469
|
+
elements: [],
|
|
470
|
+
hashFn: (key) => String(key),
|
|
471
|
+
objHashFn: (key) => key
|
|
472
|
+
}) {
|
|
473
|
+
__publicField(this, "_noObjMap", {});
|
|
474
|
+
__publicField(this, "_objMap", /* @__PURE__ */ new WeakMap());
|
|
722
475
|
__publicField(this, "_head");
|
|
723
476
|
__publicField(this, "_tail");
|
|
724
477
|
__publicField(this, "_sentinel");
|
|
478
|
+
__publicField(this, "_hashFn");
|
|
479
|
+
__publicField(this, "_objHashFn");
|
|
725
480
|
__publicField(this, "_size", 0);
|
|
726
|
-
Object.setPrototypeOf(this._orgMap, null);
|
|
727
481
|
this._sentinel = {};
|
|
728
482
|
this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
|
|
729
|
-
|
|
730
|
-
|
|
483
|
+
const { elements, hashFn, objHashFn } = options;
|
|
484
|
+
this._hashFn = hashFn;
|
|
485
|
+
this._objHashFn = objHashFn;
|
|
486
|
+
if (elements) {
|
|
487
|
+
for (const el of elements) {
|
|
488
|
+
this.set(el[0], el[1]);
|
|
489
|
+
}
|
|
731
490
|
}
|
|
732
491
|
}
|
|
733
492
|
get size() {
|
|
734
493
|
return this._size;
|
|
735
494
|
}
|
|
736
|
-
/**
|
|
737
|
-
* Time Complexity: O(1)
|
|
738
|
-
* Space Complexity: O(1)
|
|
739
|
-
*
|
|
740
|
-
* The function returns a new iterator object for a HashMap.
|
|
741
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
742
|
-
*/
|
|
743
|
-
get begin() {
|
|
744
|
-
return new HashMapIterator(this._head, this._sentinel, this);
|
|
745
|
-
}
|
|
746
|
-
/**
|
|
747
|
-
* Time Complexity: O(1)
|
|
748
|
-
* Space Complexity: O(1)
|
|
749
|
-
*
|
|
750
|
-
* The function returns a new HashMapIterator object with the _sentinel value as both the start and
|
|
751
|
-
* end values.
|
|
752
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
753
|
-
*/
|
|
754
|
-
get end() {
|
|
755
|
-
return new HashMapIterator(this._sentinel, this._sentinel, this);
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
* Time Complexity: O(1)
|
|
759
|
-
* Space Complexity: O(1)
|
|
760
|
-
*
|
|
761
|
-
* The reverseBegin function returns a new HashMapIterator object that iterates over the elements of
|
|
762
|
-
* a HashMap in reverse order.
|
|
763
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
764
|
-
*/
|
|
765
|
-
get reverseBegin() {
|
|
766
|
-
return new HashMapIterator(this._tail, this._sentinel, this, 1 /* REVERSE */);
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Time Complexity: O(1)
|
|
770
|
-
* Space Complexity: O(1)
|
|
771
|
-
*
|
|
772
|
-
* The reverseEnd function returns a new HashMapIterator object that iterates over the elements of a
|
|
773
|
-
* HashMap in reverse order.
|
|
774
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
775
|
-
*/
|
|
776
|
-
get reverseEnd() {
|
|
777
|
-
return new HashMapIterator(this._sentinel, this._sentinel, this, 1 /* REVERSE */);
|
|
778
|
-
}
|
|
779
495
|
/**
|
|
780
496
|
* Time Complexity: O(1)
|
|
781
497
|
* Space Complexity: O(1)
|
|
@@ -802,6 +518,27 @@ var dataStructureTyped = (() => {
|
|
|
802
518
|
return;
|
|
803
519
|
return [this._tail.key, this._tail.value];
|
|
804
520
|
}
|
|
521
|
+
/**
|
|
522
|
+
* The `begin()` function in TypeScript iterates over a linked list and yields key-value pairs.
|
|
523
|
+
*/
|
|
524
|
+
*begin() {
|
|
525
|
+
let node = this._head;
|
|
526
|
+
while (node !== this._sentinel) {
|
|
527
|
+
yield [node.key, node.value];
|
|
528
|
+
node = node.next;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* The function `reverseBegin()` iterates over a linked list in reverse order, yielding each node's
|
|
533
|
+
* key and value.
|
|
534
|
+
*/
|
|
535
|
+
*reverseBegin() {
|
|
536
|
+
let node = this._tail;
|
|
537
|
+
while (node !== this._sentinel) {
|
|
538
|
+
yield [node.key, node.value];
|
|
539
|
+
node = node.prev;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
805
542
|
/**
|
|
806
543
|
* Time Complexity: O(1)
|
|
807
544
|
* Space Complexity: O(1)
|
|
@@ -812,50 +549,43 @@ var dataStructureTyped = (() => {
|
|
|
812
549
|
* type, but typically it is a string or symbol.
|
|
813
550
|
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
|
|
814
551
|
* value associated with the key being set in the data structure.
|
|
815
|
-
* @param {boolean} isObjectKey - A boolean flag indicating whether the key is an object key or not.
|
|
816
552
|
* @returns the size of the data structure after the key-value pair has been set.
|
|
817
553
|
*/
|
|
818
|
-
set(key, value
|
|
819
|
-
let
|
|
820
|
-
if (
|
|
821
|
-
const
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
});
|
|
830
|
-
newTail = {
|
|
831
|
-
key,
|
|
832
|
-
value,
|
|
833
|
-
prev: this._tail,
|
|
834
|
-
next: this._sentinel
|
|
835
|
-
};
|
|
836
|
-
this._nodes.push(newTail);
|
|
554
|
+
set(key, value) {
|
|
555
|
+
let node;
|
|
556
|
+
if (isWeakKey(key)) {
|
|
557
|
+
const hash = key;
|
|
558
|
+
node = this._objMap.get(hash);
|
|
559
|
+
if (node) {
|
|
560
|
+
node.value = value;
|
|
561
|
+
} else {
|
|
562
|
+
node = { key: hash, value, prev: this._tail, next: this._sentinel };
|
|
563
|
+
this._objMap.set(hash, node);
|
|
564
|
+
}
|
|
837
565
|
} else {
|
|
838
|
-
const
|
|
566
|
+
const hash = this._hashFn(key);
|
|
567
|
+
node = this._noObjMap[hash];
|
|
839
568
|
if (node) {
|
|
840
569
|
node.value = value;
|
|
841
|
-
|
|
570
|
+
} else {
|
|
571
|
+
this._noObjMap[hash] = node = {
|
|
572
|
+
key,
|
|
573
|
+
value,
|
|
574
|
+
prev: this._tail,
|
|
575
|
+
next: this._sentinel
|
|
576
|
+
};
|
|
842
577
|
}
|
|
843
|
-
this._orgMap[key] = newTail = {
|
|
844
|
-
key,
|
|
845
|
-
value,
|
|
846
|
-
prev: this._tail,
|
|
847
|
-
next: this._sentinel
|
|
848
|
-
};
|
|
849
578
|
}
|
|
850
579
|
if (this._size === 0) {
|
|
851
|
-
this._head =
|
|
852
|
-
this._sentinel.next =
|
|
580
|
+
this._head = node;
|
|
581
|
+
this._sentinel.next = node;
|
|
853
582
|
} else {
|
|
854
|
-
this._tail.next =
|
|
583
|
+
this._tail.next = node;
|
|
855
584
|
}
|
|
856
|
-
this._tail =
|
|
857
|
-
this._sentinel.prev =
|
|
858
|
-
|
|
585
|
+
this._tail = node;
|
|
586
|
+
this._sentinel.prev = node;
|
|
587
|
+
this._size++;
|
|
588
|
+
return this._size;
|
|
859
589
|
}
|
|
860
590
|
/**
|
|
861
591
|
* Time Complexity: O(1)
|
|
@@ -865,21 +595,21 @@ var dataStructureTyped = (() => {
|
|
|
865
595
|
* key directly or by using an index stored in the key object.
|
|
866
596
|
* @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
|
|
867
597
|
* of any type, but typically it is a string or symbol.
|
|
868
|
-
* @param {boolean} isObjectKey - The `isObjectKey` parameter is a boolean flag that indicates
|
|
869
|
-
* whether the `key` parameter is an object key or not. If `isObjectKey` is `true`, it means that
|
|
870
|
-
* `key` is an object key. If `isObjectKey` is `false`, it means that `key`
|
|
871
598
|
* @returns The value associated with the given key is being returned. If the key is an object key,
|
|
872
599
|
* the value is retrieved from the `_nodes` array using the index stored in the `OBJ_KEY_INDEX`
|
|
873
|
-
* property of the key. If the key is a string key, the value is retrieved from the `
|
|
600
|
+
* property of the key. If the key is a string key, the value is retrieved from the `_noObjMap` object
|
|
874
601
|
* using the key itself. If the key is not found, `undefined` is
|
|
875
602
|
*/
|
|
876
|
-
get(key
|
|
877
|
-
if (
|
|
878
|
-
const
|
|
879
|
-
|
|
603
|
+
get(key) {
|
|
604
|
+
if (isWeakKey(key)) {
|
|
605
|
+
const hash = this._objHashFn(key);
|
|
606
|
+
const node = this._objMap.get(hash);
|
|
607
|
+
return node ? node.value : void 0;
|
|
608
|
+
} else {
|
|
609
|
+
const hash = this._hashFn(key);
|
|
610
|
+
const node = this._noObjMap[hash];
|
|
611
|
+
return node ? node.value : void 0;
|
|
880
612
|
}
|
|
881
|
-
const node = this._orgMap[key];
|
|
882
|
-
return node ? node.value : void 0;
|
|
883
613
|
}
|
|
884
614
|
/**
|
|
885
615
|
* Time Complexity: O(n), where n is the index.
|
|
@@ -900,33 +630,6 @@ var dataStructureTyped = (() => {
|
|
|
900
630
|
}
|
|
901
631
|
return [node.key, node.value];
|
|
902
632
|
}
|
|
903
|
-
/**
|
|
904
|
-
* Time Complexity: O(1)
|
|
905
|
-
* Space Complexity: O(1)
|
|
906
|
-
*
|
|
907
|
-
* The function `getIterator` returns a new instance of `HashMapIterator` based on the provided key
|
|
908
|
-
* and whether it is an object key or not.
|
|
909
|
-
* @param {K} key - The `key` parameter is the key used to retrieve the iterator from the HashMap. It
|
|
910
|
-
* can be of any type, depending on how the HashMap is implemented.
|
|
911
|
-
* @param {boolean} [isObjectKey] - The `isObjectKey` parameter is an optional boolean parameter that
|
|
912
|
-
* indicates whether the `key` parameter is an object key. If `isObjectKey` is `true`, it means that
|
|
913
|
-
* the `key` parameter is an object and needs to be handled differently. If `isObjectKey` is `false`
|
|
914
|
-
* @returns a new instance of the `HashMapIterator` class.
|
|
915
|
-
*/
|
|
916
|
-
getIterator(key, isObjectKey) {
|
|
917
|
-
let node;
|
|
918
|
-
if (isObjectKey) {
|
|
919
|
-
const index = key[this.OBJ_KEY_INDEX];
|
|
920
|
-
if (index === void 0) {
|
|
921
|
-
node = this._sentinel;
|
|
922
|
-
} else {
|
|
923
|
-
node = this._nodes[index];
|
|
924
|
-
}
|
|
925
|
-
} else {
|
|
926
|
-
node = this._orgMap[key] || this._sentinel;
|
|
927
|
-
}
|
|
928
|
-
return new HashMapIterator(node, this._sentinel, this);
|
|
929
|
-
}
|
|
930
633
|
/**
|
|
931
634
|
* Time Complexity: O(1)
|
|
932
635
|
* Space Complexity: O(1)
|
|
@@ -934,26 +637,25 @@ var dataStructureTyped = (() => {
|
|
|
934
637
|
* The `delete` function removes a key-value pair from a map-like data structure.
|
|
935
638
|
* @param {K} key - The `key` parameter is the key that you want to delete from the data structure.
|
|
936
639
|
* It can be of any type, but typically it is a string or an object.
|
|
937
|
-
* @param {boolean} isObjectKey - The `isObjectKey` parameter is a boolean flag that indicates
|
|
938
|
-
* whether the `key` parameter is an object key or not. If `isObjectKey` is `true`, it means that the
|
|
939
|
-
* `key` parameter is an object key. If `isObjectKey` is `false`, it means that the
|
|
940
640
|
* @returns a boolean value. It returns `true` if the deletion was successful, and `false` if the key
|
|
941
641
|
* was not found.
|
|
942
642
|
*/
|
|
943
|
-
delete(key
|
|
643
|
+
delete(key) {
|
|
944
644
|
let node;
|
|
945
|
-
if (
|
|
946
|
-
const
|
|
947
|
-
|
|
645
|
+
if (isWeakKey(key)) {
|
|
646
|
+
const hash = this._objHashFn(key);
|
|
647
|
+
node = this._objMap.get(hash);
|
|
648
|
+
if (!node) {
|
|
948
649
|
return false;
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
delete this._nodes[index];
|
|
650
|
+
}
|
|
651
|
+
this._objMap.delete(hash);
|
|
952
652
|
} else {
|
|
953
|
-
|
|
954
|
-
|
|
653
|
+
const hash = this._hashFn(key);
|
|
654
|
+
node = this._noObjMap[hash];
|
|
655
|
+
if (!node) {
|
|
955
656
|
return false;
|
|
956
|
-
|
|
657
|
+
}
|
|
658
|
+
delete this._noObjMap[hash];
|
|
957
659
|
}
|
|
958
660
|
this._deleteNode(node);
|
|
959
661
|
return true;
|
|
@@ -994,9 +696,7 @@ var dataStructureTyped = (() => {
|
|
|
994
696
|
* The `clear` function clears all the elements in a data structure and resets its properties.
|
|
995
697
|
*/
|
|
996
698
|
clear() {
|
|
997
|
-
this.
|
|
998
|
-
this._orgMap = {};
|
|
999
|
-
Object.setPrototypeOf(this._orgMap, null);
|
|
699
|
+
this._noObjMap = {};
|
|
1000
700
|
this._size = 0;
|
|
1001
701
|
this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
|
|
1002
702
|
}
|
|
@@ -1017,6 +717,30 @@ var dataStructureTyped = (() => {
|
|
|
1017
717
|
node = node.next;
|
|
1018
718
|
}
|
|
1019
719
|
}
|
|
720
|
+
filter(predicate) {
|
|
721
|
+
const filteredMap = new _HashMap();
|
|
722
|
+
for (const [key, value] of this) {
|
|
723
|
+
if (predicate([key, value], this)) {
|
|
724
|
+
filteredMap.set(key, value);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return filteredMap;
|
|
728
|
+
}
|
|
729
|
+
map(callback) {
|
|
730
|
+
const mappedMap = new _HashMap();
|
|
731
|
+
for (const [key, value] of this) {
|
|
732
|
+
const newValue = callback([key, value], this);
|
|
733
|
+
mappedMap.set(key, newValue);
|
|
734
|
+
}
|
|
735
|
+
return mappedMap;
|
|
736
|
+
}
|
|
737
|
+
reduce(callback, initialValue) {
|
|
738
|
+
let accumulator = initialValue;
|
|
739
|
+
for (const element of this) {
|
|
740
|
+
accumulator = callback(accumulator, element, this);
|
|
741
|
+
}
|
|
742
|
+
return accumulator;
|
|
743
|
+
}
|
|
1020
744
|
/**
|
|
1021
745
|
* Time Complexity: O(n), where n is the number of elements in the HashMap.
|
|
1022
746
|
* Space Complexity: O(1)
|
|
@@ -3161,79 +2885,6 @@ var dataStructureTyped = (() => {
|
|
|
3161
2885
|
};
|
|
3162
2886
|
|
|
3163
2887
|
// src/data-structures/queue/deque.ts
|
|
3164
|
-
var DequeIterator = class _DequeIterator {
|
|
3165
|
-
/**
|
|
3166
|
-
* The constructor initializes the index, iterate direction, and prev/next functions for a
|
|
3167
|
-
* DequeIterator object.
|
|
3168
|
-
* @param {number} index - The index parameter represents the current index position of the iterator
|
|
3169
|
-
* within the deque. It is a number that indicates the position of the element that the iterator is
|
|
3170
|
-
* currently pointing to.
|
|
3171
|
-
* @param deque - The `deque` parameter is an instance of the `Deque` class. It represents a
|
|
3172
|
-
* double-ended queue data structure, which allows elements to be added or removed from both ends.
|
|
3173
|
-
* @param iterateDirection - The `iterateDirection` parameter is an optional parameter that specifies
|
|
3174
|
-
* the direction in which the iterator should iterate over the elements of the `deque`. It has a
|
|
3175
|
-
* default value of `IterateDirection.DEFAULT`.
|
|
3176
|
-
* @returns The constructor is not returning anything. It is used to initialize the properties of the
|
|
3177
|
-
* object being created.
|
|
3178
|
-
*/
|
|
3179
|
-
constructor(index, deque, iterateDirection = 0 /* DEFAULT */) {
|
|
3180
|
-
__publicField(this, "iterateDirection");
|
|
3181
|
-
__publicField(this, "index");
|
|
3182
|
-
__publicField(this, "deque");
|
|
3183
|
-
this.index = index;
|
|
3184
|
-
this.iterateDirection = iterateDirection;
|
|
3185
|
-
if (this.iterateDirection === 0 /* DEFAULT */) {
|
|
3186
|
-
this.prev = function() {
|
|
3187
|
-
if (this.index === 0) {
|
|
3188
|
-
throwRangeError();
|
|
3189
|
-
}
|
|
3190
|
-
this.index -= 1;
|
|
3191
|
-
return this;
|
|
3192
|
-
};
|
|
3193
|
-
this.next = function() {
|
|
3194
|
-
if (this.index === this.deque.size) {
|
|
3195
|
-
throwRangeError();
|
|
3196
|
-
}
|
|
3197
|
-
this.index += 1;
|
|
3198
|
-
return this;
|
|
3199
|
-
};
|
|
3200
|
-
} else {
|
|
3201
|
-
this.prev = function() {
|
|
3202
|
-
if (this.index === this.deque.size - 1) {
|
|
3203
|
-
throwRangeError();
|
|
3204
|
-
}
|
|
3205
|
-
this.index += 1;
|
|
3206
|
-
return this;
|
|
3207
|
-
};
|
|
3208
|
-
this.next = function() {
|
|
3209
|
-
if (this.index === -1) {
|
|
3210
|
-
throwRangeError();
|
|
3211
|
-
}
|
|
3212
|
-
this.index -= 1;
|
|
3213
|
-
return this;
|
|
3214
|
-
};
|
|
3215
|
-
}
|
|
3216
|
-
this.deque = deque;
|
|
3217
|
-
}
|
|
3218
|
-
get current() {
|
|
3219
|
-
return this.deque.getAt(this.index);
|
|
3220
|
-
}
|
|
3221
|
-
set current(newElement) {
|
|
3222
|
-
this.deque.setAt(this.index, newElement);
|
|
3223
|
-
}
|
|
3224
|
-
isAccessible() {
|
|
3225
|
-
return this.index !== this.deque.size;
|
|
3226
|
-
}
|
|
3227
|
-
prev() {
|
|
3228
|
-
return this;
|
|
3229
|
-
}
|
|
3230
|
-
next() {
|
|
3231
|
-
return this;
|
|
3232
|
-
}
|
|
3233
|
-
clone() {
|
|
3234
|
-
return new _DequeIterator(this.index, this.deque, this.iterateDirection);
|
|
3235
|
-
}
|
|
3236
|
-
};
|
|
3237
2888
|
var Deque = class _Deque {
|
|
3238
2889
|
/**
|
|
3239
2890
|
* The constructor initializes a data structure with a specified bucket size and populates it with
|
|
@@ -3367,35 +3018,25 @@ var dataStructureTyped = (() => {
|
|
|
3367
3018
|
this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
|
|
3368
3019
|
}
|
|
3369
3020
|
/**
|
|
3370
|
-
* The
|
|
3371
|
-
* @returns A new instance of the DequeIterator class is being returned.
|
|
3372
|
-
*/
|
|
3373
|
-
begin() {
|
|
3374
|
-
return new DequeIterator(0, this);
|
|
3375
|
-
}
|
|
3376
|
-
/**
|
|
3377
|
-
* The `end()` function returns a new `DequeIterator` object with the size and reference to the
|
|
3378
|
-
* current deque.
|
|
3379
|
-
* @returns A new instance of the DequeIterator class is being returned.
|
|
3380
|
-
*/
|
|
3381
|
-
end() {
|
|
3382
|
-
return new DequeIterator(this.size, this);
|
|
3383
|
-
}
|
|
3384
|
-
/**
|
|
3385
|
-
* The reverseBegin function returns a new DequeIterator object that starts at the last element of
|
|
3386
|
-
* the deque and iterates in reverse direction.
|
|
3387
|
-
* @returns A new instance of the DequeIterator class is being returned.
|
|
3021
|
+
* The below function is a generator that yields elements from a collection one by one.
|
|
3388
3022
|
*/
|
|
3389
|
-
|
|
3390
|
-
|
|
3023
|
+
*begin() {
|
|
3024
|
+
let index = 0;
|
|
3025
|
+
while (index < this.size) {
|
|
3026
|
+
yield this.getAt(index);
|
|
3027
|
+
index++;
|
|
3028
|
+
}
|
|
3391
3029
|
}
|
|
3392
3030
|
/**
|
|
3393
|
-
* The
|
|
3394
|
-
*
|
|
3395
|
-
* @returns A new instance of the DequeIterator class is being returned.
|
|
3031
|
+
* The function `reverseBegin()` is a generator that yields elements in reverse order starting from
|
|
3032
|
+
* the last element.
|
|
3396
3033
|
*/
|
|
3397
|
-
|
|
3398
|
-
|
|
3034
|
+
*reverseBegin() {
|
|
3035
|
+
let index = this.size - 1;
|
|
3036
|
+
while (index >= 0) {
|
|
3037
|
+
yield this.getAt(index);
|
|
3038
|
+
index--;
|
|
3039
|
+
}
|
|
3399
3040
|
}
|
|
3400
3041
|
/**
|
|
3401
3042
|
* Time Complexity - Amortized O(1) (possible reallocation)
|
|
@@ -3705,46 +3346,6 @@ var dataStructureTyped = (() => {
|
|
|
3705
3346
|
this.cut(index - 1);
|
|
3706
3347
|
return this.size;
|
|
3707
3348
|
}
|
|
3708
|
-
/**
|
|
3709
|
-
* Time Complexity: O(n)
|
|
3710
|
-
* Space Complexity: O(1)
|
|
3711
|
-
*/
|
|
3712
|
-
/**
|
|
3713
|
-
* Time Complexity: O(n)
|
|
3714
|
-
* Space Complexity: O(1)
|
|
3715
|
-
*
|
|
3716
|
-
* The function deletes an element from a deque using an iterator and returns the next iterator.
|
|
3717
|
-
* @param iter - The parameter `iter` is of type `DequeIterator<E>`. It represents an iterator object
|
|
3718
|
-
* that is used to iterate over elements in a deque (double-ended queue).
|
|
3719
|
-
* @returns the updated iterator after deleting an element from the deque.
|
|
3720
|
-
*/
|
|
3721
|
-
deleteByIterator(iter) {
|
|
3722
|
-
const index = iter.index;
|
|
3723
|
-
this.deleteAt(index);
|
|
3724
|
-
iter = iter.next();
|
|
3725
|
-
return iter;
|
|
3726
|
-
}
|
|
3727
|
-
/**
|
|
3728
|
-
* Time Complexity: O(n)
|
|
3729
|
-
* Space Complexity: O(1)
|
|
3730
|
-
*/
|
|
3731
|
-
/**
|
|
3732
|
-
* Time Complexity: O(n)
|
|
3733
|
-
* Space Complexity: O(1)
|
|
3734
|
-
*
|
|
3735
|
-
* The function `findIterator` searches for an element in a deque and returns an iterator pointing to
|
|
3736
|
-
* the element if found, otherwise it returns an iterator pointing to the end of the deque.
|
|
3737
|
-
* @param {E} element - The `element` parameter is the element that you want to find in the deque.
|
|
3738
|
-
* @returns The method `findIterator(element: E)` returns a `DequeIterator<E>` object.
|
|
3739
|
-
*/
|
|
3740
|
-
findIterator(element) {
|
|
3741
|
-
for (let i = 0; i < this.size; ++i) {
|
|
3742
|
-
if (this.getAt(i) === element) {
|
|
3743
|
-
return new DequeIterator(i, this);
|
|
3744
|
-
}
|
|
3745
|
-
}
|
|
3746
|
-
return this.end();
|
|
3747
|
-
}
|
|
3748
3349
|
/**
|
|
3749
3350
|
* Time Complexity: O(n)
|
|
3750
3351
|
* Space Complexity: O(1)
|
|
@@ -6909,6 +6510,43 @@ var dataStructureTyped = (() => {
|
|
|
6909
6510
|
}
|
|
6910
6511
|
};
|
|
6911
6512
|
|
|
6513
|
+
// src/types/data-structures/binary-tree/binary-tree.ts
|
|
6514
|
+
var IterationType = /* @__PURE__ */ ((IterationType3) => {
|
|
6515
|
+
IterationType3["ITERATIVE"] = "ITERATIVE";
|
|
6516
|
+
IterationType3["RECURSIVE"] = "RECURSIVE";
|
|
6517
|
+
return IterationType3;
|
|
6518
|
+
})(IterationType || {});
|
|
6519
|
+
var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
|
|
6520
|
+
FamilyPosition2["ROOT"] = "ROOT";
|
|
6521
|
+
FamilyPosition2["LEFT"] = "LEFT";
|
|
6522
|
+
FamilyPosition2["RIGHT"] = "RIGHT";
|
|
6523
|
+
FamilyPosition2["ROOT_LEFT"] = "ROOT_LEFT";
|
|
6524
|
+
FamilyPosition2["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
6525
|
+
FamilyPosition2["ISOLATED"] = "ISOLATED";
|
|
6526
|
+
FamilyPosition2["MAL_NODE"] = "MAL_NODE";
|
|
6527
|
+
return FamilyPosition2;
|
|
6528
|
+
})(FamilyPosition || {});
|
|
6529
|
+
|
|
6530
|
+
// src/types/data-structures/binary-tree/rb-tree.ts
|
|
6531
|
+
var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
|
|
6532
|
+
RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
|
|
6533
|
+
RBTNColor2[RBTNColor2["BLACK"] = 0] = "BLACK";
|
|
6534
|
+
return RBTNColor2;
|
|
6535
|
+
})(RBTNColor || {});
|
|
6536
|
+
|
|
6537
|
+
// src/types/helpers.ts
|
|
6538
|
+
var CP = /* @__PURE__ */ ((CP2) => {
|
|
6539
|
+
CP2["lt"] = "lt";
|
|
6540
|
+
CP2["eq"] = "eq";
|
|
6541
|
+
CP2["gt"] = "gt";
|
|
6542
|
+
return CP2;
|
|
6543
|
+
})(CP || {});
|
|
6544
|
+
var IterateDirection = /* @__PURE__ */ ((IterateDirection2) => {
|
|
6545
|
+
IterateDirection2[IterateDirection2["DEFAULT"] = 0] = "DEFAULT";
|
|
6546
|
+
IterateDirection2[IterateDirection2["REVERSE"] = 1] = "REVERSE";
|
|
6547
|
+
return IterateDirection2;
|
|
6548
|
+
})(IterateDirection || {});
|
|
6549
|
+
|
|
6912
6550
|
// src/data-structures/binary-tree/binary-tree.ts
|
|
6913
6551
|
var BinaryTreeNode = class {
|
|
6914
6552
|
/**
|