queue-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.
Files changed (47) hide show
  1. package/dist/cjs/index.cjs +7 -7
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +8 -7
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +7 -7
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +8 -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/graph/directed-graph.d.ts +2 -2
  13. package/dist/types/data-structures/graph/undirected-graph.d.ts +2 -2
  14. package/dist/types/data-structures/hash/hash-map.d.ts +2 -2
  15. package/dist/types/data-structures/heap/heap.d.ts +3 -7
  16. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +1 -1
  17. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
  18. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  19. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  20. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  21. package/dist/types/types/data-structures/stack/stack.d.ts +1 -1
  22. package/dist/umd/queue-typed.js +8 -7
  23. package/dist/umd/queue-typed.js.map +1 -1
  24. package/dist/umd/queue-typed.min.js +1 -1
  25. package/dist/umd/queue-typed.min.js.map +1 -1
  26. package/package.json +2 -2
  27. package/src/data-structures/base/iterable-element-base.ts +2 -2
  28. package/src/data-structures/binary-tree/binary-tree.ts +8 -7
  29. package/src/data-structures/binary-tree/bst.ts +1 -1
  30. package/src/data-structures/binary-tree/tree-multi-set.ts +5 -5
  31. package/src/data-structures/graph/abstract-graph.ts +18 -18
  32. package/src/data-structures/graph/directed-graph.ts +4 -4
  33. package/src/data-structures/graph/map-graph.ts +1 -1
  34. package/src/data-structures/graph/undirected-graph.ts +4 -4
  35. package/src/data-structures/hash/hash-map.ts +6 -4
  36. package/src/data-structures/heap/heap.ts +17 -14
  37. package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
  38. package/src/data-structures/linked-list/singly-linked-list.ts +15 -9
  39. package/src/data-structures/queue/deque.ts +1 -1
  40. package/src/data-structures/stack/stack.ts +1 -1
  41. package/src/data-structures/trie/trie.ts +10 -5
  42. package/src/types/data-structures/binary-tree/avl-tree.ts +1 -1
  43. package/src/types/data-structures/binary-tree/red-black-tree.ts +1 -1
  44. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -1
  45. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -1
  46. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  47. package/src/types/data-structures/stack/stack.ts +1 -1
@@ -27,7 +27,7 @@ export declare abstract class IterableElementBase<E, R> implements Iterable<E> {
27
27
  * @remarks
28
28
  * Time O(1), Space O(1).
29
29
  */
30
- protected _toElementFn?: (rawElement: R) => E;
30
+ protected readonly _toElementFn?: (rawElement: R) => E;
31
31
  /**
32
32
  * Exposes the current `toElementFn`, if configured.
33
33
  *
@@ -275,7 +275,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
275
275
  * @param [options] - Configuration options for the tree.
276
276
  */
277
277
  constructor(keysNodesEntriesOrRaws?: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BinaryTreeOptions<K, V, R>);
278
- protected _isMapMode: boolean;
278
+ protected readonly _isMapMode: boolean;
279
279
  /**
280
280
  * Gets whether the tree is in Map mode.
281
281
  * @remarks In Map mode (default), values are stored in an external Map, and nodes only hold keys. If false, values are stored directly on the nodes. Time O(1)
@@ -283,7 +283,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
283
283
  * @returns True if in Map mode, false otherwise.
284
284
  */
285
285
  get isMapMode(): boolean;
286
- protected _isDuplicate: boolean;
286
+ protected readonly _isDuplicate: boolean;
287
287
  /**
288
288
  * Gets whether the tree allows duplicate keys.
289
289
  * @remarks Time O(1)
@@ -315,7 +315,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
315
315
  * @returns The size of the tree.
316
316
  */
317
317
  get size(): number;
318
- protected _NIL: BinaryTreeNode<K, V>;
318
+ protected readonly _NIL: BinaryTreeNode<K, V>;
319
319
  /**
320
320
  * Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
321
321
  * @remarks Time O(1)
@@ -323,7 +323,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
323
323
  * @returns The NIL node.
324
324
  */
325
325
  get NIL(): BinaryTreeNode<K, V>;
326
- protected _toEntryFn?: ToEntryFn<K, V, R>;
326
+ protected readonly _toEntryFn?: ToEntryFn<K, V, R>;
327
327
  /**
328
328
  * Gets the function used to convert raw data objects (R) into [key, value] entries.
329
329
  * @remarks Time O(1)
@@ -682,7 +682,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
682
682
  * @param node - The node.
683
683
  * @returns The node's key or undefined.
684
684
  */
685
- protected _DEFAULT_NODE_CALLBACK: (node: BinaryTreeNode<K, V> | null | undefined) => K | undefined;
685
+ protected readonly _DEFAULT_NODE_CALLBACK: NodeCallback<BinaryTreeNode<K, V> | null | undefined, K | undefined>;
686
686
  /**
687
687
  * (Protected) Snapshots the current tree's configuration options.
688
688
  * @remarks Time O(1)
@@ -294,7 +294,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
294
294
 
295
295
  * @remarks Time O(1) Space O(1)
296
296
  */
297
- protected _comparator: Comparator<K>;
297
+ protected readonly _comparator: Comparator<K>;
298
298
  /**
299
299
  * Gets the comparator function used by the tree.
300
300
  * @remarks Time O(1)
@@ -170,7 +170,7 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
170
170
  * @returns DirectedGraph with all keys added.
171
171
  * @remarks Time O(V), Space O(V)
172
172
  */
173
- static fromKeys<K extends VertexKey>(keys: Iterable<K>): DirectedGraph<K, any, DirectedVertex<K>, DirectedEdge<any>>;
173
+ static fromKeys<K extends VertexKey>(keys: Iterable<K>): DirectedGraph<K, undefined, DirectedVertex<K>, DirectedEdge<undefined>>;
174
174
  /**
175
175
  * Construct a directed graph from `[key, value]` entries.
176
176
  * @template V - Vertex value type.
@@ -178,7 +178,7 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
178
178
  * @returns DirectedGraph with all vertices added.
179
179
  * @remarks Time O(V), Space O(V)
180
180
  */
181
- static fromEntries<V>(entries: Iterable<[VertexKey, V]>): DirectedGraph<V, any, DirectedVertex<V>, DirectedEdge<any>>;
181
+ static fromEntries<V>(entries: Iterable<[VertexKey, V]>): DirectedGraph<V, undefined, DirectedVertex<V>, DirectedEdge<undefined>>;
182
182
  /**
183
183
  * Create a directed vertex instance. Does not insert into the graph.
184
184
  * @param key - Vertex identifier.
@@ -200,7 +200,7 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
200
200
  * @returns UndirectedGraph with all keys added.
201
201
  * @remarks Time O(V), Space O(V)
202
202
  */
203
- static fromKeys<K extends VertexKey>(keys: Iterable<K>): UndirectedGraph<K, any, UndirectedVertex<K>, UndirectedEdge<any>>;
203
+ static fromKeys<K extends VertexKey>(keys: Iterable<K>): UndirectedGraph<K, undefined, UndirectedVertex<K>, UndirectedEdge<undefined>>;
204
204
  /**
205
205
  * Construct an undirected graph from `[key, value]` entries.
206
206
  * @template V - Vertex value type.
@@ -208,7 +208,7 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
208
208
  * @returns UndirectedGraph with all vertices added.
209
209
  * @remarks Time O(V), Space O(V)
210
210
  */
211
- static fromEntries<V>(entries: Iterable<[VertexKey, V]>): UndirectedGraph<V, any, UndirectedVertex<V>, UndirectedEdge<any>>;
211
+ static fromEntries<V>(entries: Iterable<[VertexKey, V]>): UndirectedGraph<V, undefined, UndirectedVertex<V>, UndirectedEdge<undefined>>;
212
212
  /**
213
213
  * Create an undirected vertex instance. Does not insert into the graph.
214
214
  * @param key - Vertex identifier.
@@ -175,7 +175,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
175
175
  * @returns Map of object→value.
176
176
  */
177
177
  get objMap(): Map<object, V>;
178
- protected _toEntryFn?: (rawElement: R) => [K, V];
178
+ protected readonly _toEntryFn?: (rawElement: R) => [K, V];
179
179
  /**
180
180
  * Get the raw→entry converter function if present.
181
181
  * @remarks Time O(1), Space O(1)
@@ -346,7 +346,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
346
346
  * @returns Tail node or sentinel.
347
347
  */
348
348
  get tail(): HashMapLinkedNode<K, V | undefined>;
349
- protected _toEntryFn?: (rawElement: R) => [K, V];
349
+ protected readonly _toEntryFn?: (rawElement: R) => [K, V];
350
350
  get toEntryFn(): ((rawElement: R) => [K, V]) | undefined;
351
351
  protected _size: number;
352
352
  get size(): number;
@@ -414,12 +414,8 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
414
414
  * @returns A new heap with mapped elements.
415
415
  */
416
416
  mapSame(callback: ElementCallback<E, R, E>, thisArg?: unknown): this;
417
- protected _DEFAULT_COMPARATOR: (a: E, b: E) => number;
418
- protected _comparator: Comparator<E>; /**
419
- * Get the comparator used to order elements.
420
- * @remarks Time O(1), Space O(1)
421
- * @returns Comparator function.
422
- */
417
+ protected readonly _DEFAULT_COMPARATOR: Comparator<E>;
418
+ protected readonly _comparator: Comparator<E>;
423
419
  /**
424
420
  * Get the comparator used to order elements.
425
421
  * @remarks Time O(1), Space O(1)
@@ -501,7 +497,7 @@ export declare class FibonacciHeap<E> {
501
497
  * @returns Min node or undefined.
502
498
  */
503
499
  get min(): FibonacciHeapNode<E> | undefined;
504
- protected _comparator: Comparator<E>;
500
+ protected readonly _comparator: Comparator<E>;
505
501
  get comparator(): Comparator<E>;
506
502
  clear(): void;
507
503
  add(element: E): boolean;
@@ -1,2 +1,2 @@
1
1
  import { BSTOptions } from './bst';
2
- export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
2
+ export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R>;
@@ -1,3 +1,3 @@
1
1
  import type { BSTOptions } from './bst';
2
2
  export type RBTNColor = 'RED' | 'BLACK';
3
- export type RedBlackTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
3
+ export type RedBlackTreeOptions<K, V, R> = BSTOptions<K, V, R>;
@@ -1,2 +1,2 @@
1
1
  import { LinearBaseOptions } from '../base';
2
- export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
2
+ export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R>;
@@ -1,2 +1,2 @@
1
1
  import { LinearBaseOptions } from '../base';
2
- export type SinglyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
2
+ export type SinglyLinkedListOptions<E, R> = LinearBaseOptions<E, R>;
@@ -1,2 +1,2 @@
1
1
  import { HeapOptions } from '../heap';
2
- export type PriorityQueueOptions<E, R> = HeapOptions<E, R> & {};
2
+ export type PriorityQueueOptions<E, R> = HeapOptions<E, R>;
@@ -1,2 +1,2 @@
1
1
  import { IterableElementBaseOptions } from '../base';
2
- export type StackOptions<E, R> = IterableElementBaseOptions<E, R> & {};
2
+ export type StackOptions<E, R> = IterableElementBaseOptions<E, R>;
@@ -671,7 +671,7 @@ var queueTyped = (() => {
671
671
  */
672
672
  constructor(elements = [], options) {
673
673
  super(options);
674
- __publicField(this, "_equals", Object.is);
674
+ __publicField(this, "_equals", (a, b) => Object.is(a, b));
675
675
  __publicField(this, "_head");
676
676
  __publicField(this, "_tail");
677
677
  __publicField(this, "_length", 0);
@@ -759,6 +759,7 @@ var queueTyped = (() => {
759
759
  * @returns Removed element or undefined.
760
760
  */
761
761
  pop() {
762
+ var _a;
762
763
  if (!this.head) return void 0;
763
764
  if (this.head === this.tail) {
764
765
  const value2 = this.head.value;
@@ -768,8 +769,8 @@ var queueTyped = (() => {
768
769
  return value2;
769
770
  }
770
771
  let current = this.head;
771
- while (current.next !== this.tail) current = current.next;
772
- const value = this.tail.value;
772
+ while (current.next && current.next !== this.tail) current = current.next;
773
+ const value = (_a = this.tail) == null ? void 0 : _a.value;
773
774
  current.next = void 0;
774
775
  this._tail = current;
775
776
  this._length--;
@@ -857,8 +858,8 @@ var queueTyped = (() => {
857
858
  at(index) {
858
859
  if (index < 0 || index >= this._length) return void 0;
859
860
  let current = this.head;
860
- for (let i = 0; i < index; i++) current = current.next;
861
- return current.value;
861
+ for (let i = 0; i < index && current; i++) current = current.next;
862
+ return current == null ? void 0 : current.value;
862
863
  }
863
864
  /**
864
865
  * Type guard: check whether the input is a SinglyLinkedListNode.
@@ -878,7 +879,7 @@ var queueTyped = (() => {
878
879
  getNodeAt(index) {
879
880
  if (index < 0 || index >= this._length) return void 0;
880
881
  let current = this.head;
881
- for (let i = 0; i < index; i++) current = current.next;
882
+ for (let i = 0; i < index && current; i++) current = current.next;
882
883
  return current;
883
884
  }
884
885
  /**
@@ -1724,7 +1725,7 @@ var queueTyped = (() => {
1724
1725
  */
1725
1726
  constructor(elements = [], options) {
1726
1727
  super(options);
1727
- __publicField(this, "_equals", Object.is);
1728
+ __publicField(this, "_equals", (a, b) => Object.is(a, b));
1728
1729
  __publicField(this, "_bucketSize", 1 << 12);
1729
1730
  __publicField(this, "_bucketFirst", 0);
1730
1731
  __publicField(this, "_firstInBucket", 0);