max-priority-queue-typed 2.5.0 → 2.5.1
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/dist/cjs/index.cjs +294 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +294 -0
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +294 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +294 -0
- package/dist/esm-legacy/index.mjs.map +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 +252 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +294 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +527 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +505 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +399 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +126 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +2881 -382
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2867 -347
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2328 -312
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +2671 -277
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +210 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +189 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +241 -10
- package/dist/types/data-structures/heap/heap.d.ts +294 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +360 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +318 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +380 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -0
- package/dist/types/data-structures/queue/deque.d.ts +319 -4
- package/dist/types/data-structures/queue/queue.d.ts +252 -0
- package/dist/types/data-structures/stack/stack.d.ts +210 -0
- package/dist/types/data-structures/trie/trie.d.ts +256 -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/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/max-priority-queue-typed.js +294 -0
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- 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 +252 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +295 -1
- package/src/data-structures/binary-tree/binary-tree.ts +527 -2
- package/src/data-structures/binary-tree/bst.ts +505 -1
- package/src/data-structures/binary-tree/red-black-tree.ts +399 -0
- package/src/data-structures/binary-tree/segment-tree.ts +127 -2
- package/src/data-structures/binary-tree/tree-map.ts +2958 -459
- package/src/data-structures/binary-tree/tree-multi-map.ts +3069 -549
- package/src/data-structures/binary-tree/tree-multi-set.ts +2476 -460
- package/src/data-structures/binary-tree/tree-set.ts +2816 -422
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +210 -0
- package/src/data-structures/graph/undirected-graph.ts +189 -0
- package/src/data-structures/hash/hash-map.ts +246 -15
- package/src/data-structures/heap/heap.ts +294 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +360 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +318 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +380 -2
- package/src/data-structures/matrix/matrix.ts +169 -1
- package/src/data-structures/queue/deque.ts +320 -5
- package/src/data-structures/queue/queue.ts +252 -0
- package/src/data-structures/stack/stack.ts +210 -0
- package/src/data-structures/trie/trie.ts +257 -5
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- 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
|
@@ -180,6 +180,27 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
180
180
|
|
|
181
181
|
|
|
182
182
|
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
183
204
|
* @example
|
|
184
205
|
* // Check if empty
|
|
185
206
|
* const map = new HashMap();
|
|
@@ -202,6 +223,27 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
202
223
|
|
|
203
224
|
|
|
204
225
|
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
205
247
|
* @example
|
|
206
248
|
* // Remove all entries
|
|
207
249
|
* const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
|
|
@@ -219,7 +261,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
219
261
|
* @remarks Time O(1), Space O(1)
|
|
220
262
|
* @returns True if the value is a 2-tuple.
|
|
221
263
|
*/
|
|
222
|
-
isEntry(rawElement:
|
|
264
|
+
isEntry(rawElement: unknown): rawElement is [K, V] {
|
|
223
265
|
return Array.isArray(rawElement) && rawElement.length === 2;
|
|
224
266
|
}
|
|
225
267
|
|
|
@@ -249,6 +291,48 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
249
291
|
|
|
250
292
|
|
|
251
293
|
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
252
336
|
|
|
253
337
|
|
|
254
338
|
* @example
|
|
@@ -296,6 +380,27 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
296
380
|
|
|
297
381
|
|
|
298
382
|
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
299
404
|
* @example
|
|
300
405
|
* // Add multiple entries
|
|
301
406
|
* const map = new HashMap<string, number>();
|
|
@@ -329,6 +434,27 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
329
434
|
|
|
330
435
|
|
|
331
436
|
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
332
458
|
* @example
|
|
333
459
|
* // HashMap get and has operations
|
|
334
460
|
* const map = new HashMap<string, number>([
|
|
@@ -373,6 +499,27 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
373
499
|
|
|
374
500
|
|
|
375
501
|
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
376
523
|
* @example
|
|
377
524
|
* // Check key existence
|
|
378
525
|
* const map = new HashMap<string, number>([['a', 1], ['b', 2]]);
|
|
@@ -402,6 +549,27 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
402
549
|
|
|
403
550
|
|
|
404
551
|
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
405
573
|
* @example
|
|
406
574
|
* // Remove entries by key
|
|
407
575
|
* const map = new HashMap<string, number>([['x', 10], ['y', 20], ['z', 30]]);
|
|
@@ -450,6 +618,27 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
450
618
|
|
|
451
619
|
|
|
452
620
|
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
453
642
|
* @example
|
|
454
643
|
* // Create independent copy
|
|
455
644
|
* const map = new HashMap<string, number>([['a', 1]]);
|
|
@@ -480,6 +669,27 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
480
669
|
|
|
481
670
|
|
|
482
671
|
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
483
693
|
* @example
|
|
484
694
|
* // Transform all values
|
|
485
695
|
* const prices = new HashMap<string, number>([['apple', 1], ['banana', 2]]);
|
|
@@ -488,8 +698,8 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
488
698
|
* console.log(doubled.get('apple')); // 2;
|
|
489
699
|
* console.log(doubled.get('banana')); // 4;
|
|
490
700
|
*/
|
|
491
|
-
map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?:
|
|
492
|
-
const out = this._createLike<K, VM, [K, VM]>()
|
|
701
|
+
map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: unknown): HashMap<K, VM> {
|
|
702
|
+
const out = this._createLike<K, VM, [K, VM]>() as unknown as HashMap<K, VM>;
|
|
493
703
|
let index = 0;
|
|
494
704
|
for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, value, key, index++, this));
|
|
495
705
|
return out;
|
|
@@ -512,6 +722,27 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
512
722
|
|
|
513
723
|
|
|
514
724
|
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
515
746
|
* @example
|
|
516
747
|
* // HashMap iteration and filter operations
|
|
517
748
|
* const map = new HashMap<number, string>([
|
|
@@ -539,7 +770,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
539
770
|
* console.log(values); // contains 7;
|
|
540
771
|
*/
|
|
541
772
|
|
|
542
|
-
filter(predicate: EntryCallback<K, V, boolean>, thisArg?:
|
|
773
|
+
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): any {
|
|
543
774
|
const out = this._createLike<K, V, [K, V]>();
|
|
544
775
|
let index = 0;
|
|
545
776
|
for (const [key, value] of this) if (predicate.call(thisArg, value, key, index++, this)) out.set(key, value);
|
|
@@ -556,8 +787,8 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
556
787
|
* @param [options] - Options forwarded to the constructor.
|
|
557
788
|
* @returns A like-kind map instance.
|
|
558
789
|
*/
|
|
559
|
-
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries: Iterable<[TK, TV] | TR> = [], options?:
|
|
560
|
-
const Ctor = this.constructor as new (e?: Iterable<[TK, TV] | TR>, o?:
|
|
790
|
+
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries: Iterable<[TK, TV] | TR> = [], options?: Record<string, unknown>): this {
|
|
791
|
+
const Ctor = this.constructor as new (e?: Iterable<[TK, TV] | TR>, o?: Record<string, unknown>) => this;
|
|
561
792
|
return new Ctor(entries, options);
|
|
562
793
|
}
|
|
563
794
|
|
|
@@ -575,7 +806,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
575
806
|
for (const node of this.objMap) yield node as [K, V];
|
|
576
807
|
}
|
|
577
808
|
|
|
578
|
-
protected _isObjKey(key:
|
|
809
|
+
protected _isObjKey(key: unknown): key is object | ((...args: unknown[]) => unknown) {
|
|
579
810
|
const keyType = typeof key;
|
|
580
811
|
return (keyType === 'object' || keyType === 'function') && key !== null;
|
|
581
812
|
}
|
|
@@ -897,7 +1128,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
|
|
|
897
1128
|
return this._size === 0;
|
|
898
1129
|
}
|
|
899
1130
|
|
|
900
|
-
isEntry(rawElement:
|
|
1131
|
+
isEntry(rawElement: unknown): rawElement is [K, V] {
|
|
901
1132
|
return Array.isArray(rawElement) && rawElement.length === 2;
|
|
902
1133
|
}
|
|
903
1134
|
|
|
@@ -907,12 +1138,12 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
|
|
|
907
1138
|
this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
|
|
908
1139
|
}
|
|
909
1140
|
|
|
910
|
-
clone():
|
|
1141
|
+
clone(): this {
|
|
911
1142
|
const opts = { hashFn: this._hashFn, objHashFn: this._objHashFn };
|
|
912
|
-
return this._createLike<
|
|
1143
|
+
return this._createLike<K, V, [K, V]>(this, opts);
|
|
913
1144
|
}
|
|
914
1145
|
|
|
915
|
-
filter(predicate: EntryCallback<K, V, boolean>, thisArg?:
|
|
1146
|
+
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): this {
|
|
916
1147
|
const out = this._createLike<K, V, [K, V]>();
|
|
917
1148
|
let index = 0;
|
|
918
1149
|
for (const [key, value] of this) {
|
|
@@ -931,8 +1162,8 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
|
|
|
931
1162
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
932
1163
|
* @returns A new map of the same class with transformed entries.
|
|
933
1164
|
*/
|
|
934
|
-
map<MK, MV>(callback: EntryCallback<K, V, [MK, MV]>, thisArg?:
|
|
935
|
-
const out = this._createLike<MK, MV, [MK, MV]>()
|
|
1165
|
+
map<MK, MV>(callback: EntryCallback<K, V, [MK, MV]>, thisArg?: unknown): LinkedHashMap<MK, MV> {
|
|
1166
|
+
const out = this._createLike<MK, MV, [MK, MV]>() as unknown as LinkedHashMap<MK, MV>;
|
|
936
1167
|
let index = 0;
|
|
937
1168
|
for (const [key, value] of this) {
|
|
938
1169
|
const [newKey, newValue] = callback.call(thisArg, value, key, index, this);
|
|
@@ -972,8 +1203,8 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
|
|
|
972
1203
|
return true;
|
|
973
1204
|
}
|
|
974
1205
|
|
|
975
|
-
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries: Iterable<[TK, TV] | TR> = [], options?:
|
|
976
|
-
const Ctor = this.constructor as new (e?: Iterable<[TK, TV] | TR>, o?:
|
|
1206
|
+
protected _createLike<TK = K, TV = V, TR = [TK, TV]>(entries: Iterable<[TK, TV] | TR> = [], options?: Record<string, unknown>): this {
|
|
1207
|
+
const Ctor = this.constructor as new (e?: Iterable<[TK, TV] | TR>, o?: Record<string, unknown>) => this;
|
|
977
1208
|
return new Ctor(entries, options);
|
|
978
1209
|
}
|
|
979
1210
|
}
|