priority-queue-typed 2.4.2 → 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.
Files changed (51) hide show
  1. package/dist/cjs/index.cjs +1 -7
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +1 -7
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +1 -7
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +1 -7
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  10. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  11. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  12. package/dist/types/data-structures/binary-tree/tree-map.d.ts +10 -0
  13. package/dist/types/data-structures/binary-tree/tree-set.d.ts +10 -0
  14. package/dist/types/data-structures/graph/directed-graph.d.ts +2 -2
  15. package/dist/types/data-structures/graph/undirected-graph.d.ts +2 -2
  16. package/dist/types/data-structures/hash/hash-map.d.ts +2 -2
  17. package/dist/types/data-structures/heap/heap.d.ts +3 -7
  18. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +1 -1
  19. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
  20. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  21. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  22. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  23. package/dist/types/types/data-structures/stack/stack.d.ts +1 -1
  24. package/dist/umd/priority-queue-typed.js +1 -7
  25. package/dist/umd/priority-queue-typed.js.map +1 -1
  26. package/dist/umd/priority-queue-typed.min.js +1 -1
  27. package/dist/umd/priority-queue-typed.min.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/data-structures/base/iterable-element-base.ts +2 -2
  30. package/src/data-structures/binary-tree/binary-tree.ts +8 -7
  31. package/src/data-structures/binary-tree/bst.ts +1 -1
  32. package/src/data-structures/binary-tree/tree-map.ts +16 -0
  33. package/src/data-structures/binary-tree/tree-multi-set.ts +5 -5
  34. package/src/data-structures/binary-tree/tree-set.ts +16 -0
  35. package/src/data-structures/graph/abstract-graph.ts +18 -18
  36. package/src/data-structures/graph/directed-graph.ts +4 -4
  37. package/src/data-structures/graph/map-graph.ts +1 -1
  38. package/src/data-structures/graph/undirected-graph.ts +4 -4
  39. package/src/data-structures/hash/hash-map.ts +6 -4
  40. package/src/data-structures/heap/heap.ts +17 -14
  41. package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
  42. package/src/data-structures/linked-list/singly-linked-list.ts +15 -9
  43. package/src/data-structures/queue/deque.ts +1 -1
  44. package/src/data-structures/stack/stack.ts +1 -1
  45. package/src/data-structures/trie/trie.ts +10 -5
  46. package/src/types/data-structures/binary-tree/avl-tree.ts +1 -1
  47. package/src/types/data-structures/binary-tree/red-black-tree.ts +1 -1
  48. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -1
  49. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -1
  50. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  51. package/src/types/data-structures/stack/stack.ts +1 -1
@@ -111,7 +111,7 @@ export class MapGraph<
111
111
  * @remarks Time O(1), Space O(1)
112
112
  */
113
113
  protected override _snapshotOptions(): Record<string, unknown> {
114
- return { ...(super._snapshotOptions() as any), originCoord: this.originCoord, bottomRight: this.bottomRight };
114
+ return { ...super._snapshotOptions(), originCoord: this.originCoord, bottomRight: this.bottomRight };
115
115
  }
116
116
 
117
117
  /**
@@ -232,8 +232,8 @@ export class UndirectedGraph<
232
232
  */
233
233
  static fromKeys<K extends VertexKey>(
234
234
  keys: Iterable<K>
235
- ): UndirectedGraph<K, any, UndirectedVertex<K>, UndirectedEdge<any>> {
236
- const g: UndirectedGraph<K, any, UndirectedVertex<K>, UndirectedEdge<any>> = new UndirectedGraph<K, any>({
235
+ ): UndirectedGraph<K, undefined, UndirectedVertex<K>, UndirectedEdge<undefined>> {
236
+ const g: UndirectedGraph<K, undefined, UndirectedVertex<K>, UndirectedEdge<undefined>> = new UndirectedGraph<K, undefined>({
237
237
  vertexValueInitializer: (k: VertexKey) => k as K
238
238
  });
239
239
  for (const k of keys) g.addVertex(k);
@@ -249,8 +249,8 @@ export class UndirectedGraph<
249
249
  */
250
250
  static fromEntries<V>(
251
251
  entries: Iterable<[VertexKey, V]>
252
- ): UndirectedGraph<V, any, UndirectedVertex<V>, UndirectedEdge<any>> {
253
- const g: UndirectedGraph<V, any, UndirectedVertex<V>, UndirectedEdge<any>> = new UndirectedGraph<V, any>();
252
+ ): UndirectedGraph<V, undefined, UndirectedVertex<V>, UndirectedEdge<undefined>> {
253
+ const g: UndirectedGraph<V, undefined, UndirectedVertex<V>, UndirectedEdge<undefined>> = new UndirectedGraph<V, undefined>();
254
254
  for (const [k, v] of entries) g.addVertex(k, v);
255
255
  return g;
256
256
  }
@@ -197,7 +197,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
197
197
  return this._objMap;
198
198
  }
199
199
 
200
- protected _toEntryFn?: (rawElement: R) => [K, V];
200
+ protected readonly _toEntryFn?: (rawElement: R) => [K, V];
201
201
 
202
202
  /**
203
203
  * Get the raw→entry converter function if present.
@@ -530,7 +530,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
530
530
  return this._tail;
531
531
  }
532
532
 
533
- protected _toEntryFn?: (rawElement: R) => [K, V] = (rawElement: R) => {
533
+ protected readonly _toEntryFn?: (rawElement: R) => [K, V] = (rawElement: R) => {
534
534
  if (this.isEntry(rawElement)) {
535
535
  return rawElement;
536
536
  }
@@ -538,6 +538,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
538
538
  'If `entryOrRawElements` does not adhere to [key,value], provide `options.toEntryFn` to transform raw records.'
539
539
  );
540
540
  };
541
+
541
542
  get toEntryFn() {
542
543
  return this._toEntryFn;
543
544
  }
@@ -712,8 +713,9 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
712
713
  const cur = node;
713
714
  node = node.next;
714
715
  if (predicate(cur.key as K, cur.value as V | undefined, i++, this)) {
715
- if (isWeakKey(cur.key as unknown as object)) {
716
- this._objMap.delete(cur.key as unknown as object);
716
+ const keyToCheck: unknown = cur.key;
717
+ if (isWeakKey(keyToCheck)) {
718
+ this._objMap.delete(keyToCheck);
717
719
  } else {
718
720
  const hash = this._hashFn(cur.key as K);
719
721
  delete this._noObjMap[hash];
@@ -639,20 +639,17 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
639
639
  return out;
640
640
  }
641
641
 
642
- protected _DEFAULT_COMPARATOR = (a: E, b: E): number => {
642
+ protected readonly _DEFAULT_COMPARATOR: Comparator<E> = (a: E, b: E): number => {
643
643
  if (typeof a === 'object' || typeof b === 'object') {
644
644
  throw TypeError('When comparing object types, define a custom comparator in options.');
645
645
  }
646
- if ((a as unknown as number) > (b as unknown as number)) return 1;
647
- if ((a as unknown as number) < (b as unknown as number)) return -1;
646
+ if (a > b) return 1;
647
+ if (a < b) return -1;
648
648
  return 0;
649
649
  };
650
650
 
651
- protected _comparator: Comparator<E> = this._DEFAULT_COMPARATOR; /**
652
- * Get the comparator used to order elements.
653
- * @remarks Time O(1), Space O(1)
654
- * @returns Comparator function.
655
- */
651
+ protected readonly _comparator: Comparator<E> = this._DEFAULT_COMPARATOR;
652
+
656
653
  /**
657
654
  * Get the comparator used to order elements.
658
655
  * @remarks Time O(1), Space O(1)
@@ -706,9 +703,11 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
706
703
  */
707
704
 
708
705
  protected _createInstance(options?: HeapOptions<E, R>): this {
709
- const Ctor: any = this.constructor;
710
- const next: any = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...(options ?? {}) });
711
- return next as this;
706
+ const Ctor = this.constructor as new (
707
+ elements?: Iterable<E> | Iterable<R>,
708
+ options?: HeapOptions<E, R>
709
+ ) => this;
710
+ return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...(options ?? {}) });
712
711
  }
713
712
 
714
713
  /**
@@ -725,8 +724,11 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
725
724
  elements: Iterable<EM> | Iterable<RM> = [],
726
725
  options?: HeapOptions<EM, RM>
727
726
  ): Heap<EM, RM> {
728
- const Ctor: any = this.constructor;
729
- return new Ctor(elements, options) as Heap<EM, RM>;
727
+ const Ctor = this.constructor as new (
728
+ elements?: Iterable<EM> | Iterable<RM>,
729
+ options?: HeapOptions<EM, RM>
730
+ ) => Heap<EM, RM>;
731
+ return new Ctor(elements, options);
730
732
  }
731
733
 
732
734
  /**
@@ -813,7 +815,8 @@ export class FibonacciHeap<E> {
813
815
  return this._min;
814
816
  }
815
817
 
816
- protected _comparator: Comparator<E>;
818
+ protected readonly _comparator: Comparator<E>;
819
+
817
820
  get comparator(): Comparator<E> {
818
821
  return this._comparator;
819
822
  }
@@ -182,7 +182,7 @@ export class DoublyLinkedListNode<E = any> extends LinkedListNode<E> {
182
182
  * console.log(foundEntry?.value); // 'Bob';
183
183
  */
184
184
  export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, DoublyLinkedListNode<E>> {
185
- protected _equals: (a: E, b: E) => boolean = Object.is as unknown as (a: E, b: E) => boolean;
185
+ protected _equals: (a: E, b: E) => boolean = (a, b) => Object.is(a, b);
186
186
 
187
187
  /**
188
188
  * Create a DoublyLinkedList and optionally bulk-insert elements.
@@ -423,8 +423,8 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
423
423
  at(index: number): E | undefined {
424
424
  if (index < 0 || index >= this._length) return undefined;
425
425
  let current = this.head;
426
- for (let i = 0; i < index; i++) current = current!.next;
427
- return current!.value;
426
+ for (let i = 0; i < index && current; i++) current = current.next;
427
+ return current?.value;
428
428
  }
429
429
 
430
430
  /**
@@ -437,7 +437,7 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
437
437
  getNodeAt(index: number): DoublyLinkedListNode<E> | undefined {
438
438
  if (index < 0 || index >= this._length) return undefined;
439
439
  let current = this.head;
440
- for (let i = 0; i < index; i++) current = current!.next;
440
+ for (let i = 0; i < index && current; i++) current = current.next;
441
441
  return current;
442
442
  }
443
443
 
@@ -246,7 +246,7 @@ export class SinglyLinkedListNode<E = any> extends LinkedListNode<E> {
246
246
  * console.log(editor.getText()); // 'Haello';
247
247
  */
248
248
  export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, SinglyLinkedListNode<E>> {
249
- protected _equals: (a: E, b: E) => boolean = Object.is as unknown as (a: E, b: E) => boolean;
249
+ protected _equals: (a: E, b: E) => boolean = (a, b) => Object.is(a, b);
250
250
 
251
251
  /**
252
252
  * Create a SinglyLinkedList and optionally bulk-insert elements.
@@ -381,8 +381,8 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
381
381
  return value;
382
382
  }
383
383
  let current = this.head;
384
- while (current.next !== this.tail) current = current.next!;
385
- const value = this.tail!.value;
384
+ while (current.next && current.next !== this.tail) current = current.next;
385
+ const value = this.tail?.value;
386
386
  current.next = undefined;
387
387
  this._tail = current;
388
388
  this._length--;
@@ -484,8 +484,8 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
484
484
  at(index: number): E | undefined {
485
485
  if (index < 0 || index >= this._length) return undefined;
486
486
  let current = this.head;
487
- for (let i = 0; i < index; i++) current = current!.next;
488
- return current!.value;
487
+ for (let i = 0; i < index && current; i++) current = current.next;
488
+ return current?.value;
489
489
  }
490
490
 
491
491
  /**
@@ -511,7 +511,7 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
511
511
  getNodeAt(index: number): SinglyLinkedListNode<E> | undefined {
512
512
  if (index < 0 || index >= this._length) return undefined;
513
513
  let current = this.head;
514
- for (let i = 0; i < index; i++) current = current!.next;
514
+ for (let i = 0; i < index && current; i++) current = current.next;
515
515
  return current;
516
516
  }
517
517
 
@@ -1003,7 +1003,10 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1003
1003
  */
1004
1004
 
1005
1005
  protected _createInstance(options?: SinglyLinkedListOptions<E, R>): this {
1006
- const Ctor: any = this.constructor;
1006
+ const Ctor = this.constructor as new (
1007
+ elements?: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>,
1008
+ options?: SinglyLinkedListOptions<E, R>
1009
+ ) => this;
1007
1010
  return new Ctor([], options);
1008
1011
  }
1009
1012
 
@@ -1021,8 +1024,11 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1021
1024
  elements: Iterable<EM> | Iterable<RM> | Iterable<SinglyLinkedListNode<EM>> = [],
1022
1025
  options?: SinglyLinkedListOptions<EM, RM>
1023
1026
  ): SinglyLinkedList<EM, RM> {
1024
- const Ctor: any = this.constructor;
1025
- return new Ctor(elements, options) as SinglyLinkedList<EM, RM>;
1027
+ const Ctor = this.constructor as new (
1028
+ elements?: Iterable<EM> | Iterable<RM> | Iterable<SinglyLinkedListNode<EM>>,
1029
+ options?: SinglyLinkedListOptions<EM, RM>
1030
+ ) => SinglyLinkedList<EM, RM>;
1031
+ return new Ctor(elements, options);
1026
1032
  }
1027
1033
 
1028
1034
  /**
@@ -144,7 +144,7 @@ import { LinearBase } from '../base/linear-base';
144
144
  * console.log(dataWindow.length); // 3;
145
145
  */
146
146
  export class Deque<E = any, R = any> extends LinearBase<E, R> {
147
- protected _equals: (a: E, b: E) => boolean = Object.is as unknown as (a: E, b: E) => boolean;
147
+ protected _equals: (a: E, b: E) => boolean = (a, b) => Object.is(a, b);
148
148
 
149
149
  /**
150
150
  * Create a Deque and optionally bulk-insert elements.
@@ -161,7 +161,7 @@ import { IterableElementBase } from '../base';
161
161
  * console.log(stack.elements.join('/')); // 'c';
162
162
  */
163
163
  export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
164
- protected _equals: (a: E, b: E) => boolean = Object.is as unknown as (a: E, b: E) => boolean;
164
+ protected _equals: (a: E, b: E) => boolean = (a, b) => Object.is(a, b);
165
165
 
166
166
  /**
167
167
  * Create a Stack and optionally bulk-push elements.
@@ -684,13 +684,15 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
684
684
  */
685
685
 
686
686
  protected _createInstance(options?: TrieOptions<R>): this {
687
- const Ctor: any = this.constructor;
688
- const next: any = new Ctor([], {
687
+ const Ctor = this.constructor as new (
688
+ elements?: Iterable<string> | Iterable<R>,
689
+ options?: TrieOptions<R>
690
+ ) => this;
691
+ return new Ctor([], {
689
692
  toElementFn: this.toElementFn,
690
693
  caseSensitive: this.caseSensitive,
691
694
  ...(options ?? {})
692
695
  });
693
- return next as this;
694
696
  }
695
697
 
696
698
  /**
@@ -703,8 +705,11 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
703
705
  */
704
706
 
705
707
  protected _createLike<RM>(elements: Iterable<string> | Iterable<RM> = [], options?: TrieOptions<RM>): Trie<RM> {
706
- const Ctor: any = this.constructor;
707
- return new Ctor(elements, options) as Trie<RM>;
708
+ const Ctor = this.constructor as new (
709
+ elements?: Iterable<string> | Iterable<RM>,
710
+ options?: TrieOptions<RM>
711
+ ) => Trie<RM>;
712
+ return new Ctor(elements, options);
708
713
  }
709
714
 
710
715
  /**
@@ -1,3 +1,3 @@
1
1
  import { BSTOptions } from './bst';
2
2
 
3
- export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
3
+ export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R>;
@@ -2,4 +2,4 @@ import type { BSTOptions } from './bst';
2
2
 
3
3
  export type RBTNColor = 'RED' | 'BLACK';
4
4
 
5
- export type RedBlackTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
5
+ export type RedBlackTreeOptions<K, V, R> = BSTOptions<K, V, R>;
@@ -1,3 +1,3 @@
1
1
  import { LinearBaseOptions } from '../base';
2
2
 
3
- export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
3
+ export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R>;
@@ -1,3 +1,3 @@
1
1
  import { LinearBaseOptions } from '../base';
2
2
 
3
- export type SinglyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
3
+ export type SinglyLinkedListOptions<E, R> = LinearBaseOptions<E, R>;
@@ -1,3 +1,3 @@
1
1
  import { HeapOptions } from '../heap';
2
2
 
3
- export type PriorityQueueOptions<E, R> = HeapOptions<E, R> & {};
3
+ export type PriorityQueueOptions<E, R> = HeapOptions<E, R>;
@@ -1,3 +1,3 @@
1
1
  import { IterableElementBaseOptions } from '../base';
2
2
 
3
- export type StackOptions<E, R> = IterableElementBaseOptions<E, R> & {};
3
+ export type StackOptions<E, R> = IterableElementBaseOptions<E, R>;