linked-list-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 +10 -10
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +11 -10
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +10 -10
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +11 -10
  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/linked-list-typed.js +11 -10
  23. package/dist/umd/linked-list-typed.js.map +1 -1
  24. package/dist/umd/linked-list-typed.min.js +1 -1
  25. package/dist/umd/linked-list-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>;
@@ -674,7 +674,7 @@ var linkedListTyped = (() => {
674
674
  */
675
675
  constructor(elements = [], options) {
676
676
  super(options);
677
- __publicField(this, "_equals", Object.is);
677
+ __publicField(this, "_equals", (a, b) => Object.is(a, b));
678
678
  __publicField(this, "_head");
679
679
  __publicField(this, "_tail");
680
680
  __publicField(this, "_length", 0);
@@ -762,6 +762,7 @@ var linkedListTyped = (() => {
762
762
  * @returns Removed element or undefined.
763
763
  */
764
764
  pop() {
765
+ var _a;
765
766
  if (!this.head) return void 0;
766
767
  if (this.head === this.tail) {
767
768
  const value2 = this.head.value;
@@ -771,8 +772,8 @@ var linkedListTyped = (() => {
771
772
  return value2;
772
773
  }
773
774
  let current = this.head;
774
- while (current.next !== this.tail) current = current.next;
775
- const value = this.tail.value;
775
+ while (current.next && current.next !== this.tail) current = current.next;
776
+ const value = (_a = this.tail) == null ? void 0 : _a.value;
776
777
  current.next = void 0;
777
778
  this._tail = current;
778
779
  this._length--;
@@ -860,8 +861,8 @@ var linkedListTyped = (() => {
860
861
  at(index) {
861
862
  if (index < 0 || index >= this._length) return void 0;
862
863
  let current = this.head;
863
- for (let i = 0; i < index; i++) current = current.next;
864
- return current.value;
864
+ for (let i = 0; i < index && current; i++) current = current.next;
865
+ return current == null ? void 0 : current.value;
865
866
  }
866
867
  /**
867
868
  * Type guard: check whether the input is a SinglyLinkedListNode.
@@ -881,7 +882,7 @@ var linkedListTyped = (() => {
881
882
  getNodeAt(index) {
882
883
  if (index < 0 || index >= this._length) return void 0;
883
884
  let current = this.head;
884
- for (let i = 0; i < index; i++) current = current.next;
885
+ for (let i = 0; i < index && current; i++) current = current.next;
885
886
  return current;
886
887
  }
887
888
  /**
@@ -1392,7 +1393,7 @@ var linkedListTyped = (() => {
1392
1393
  */
1393
1394
  constructor(elements = [], options) {
1394
1395
  super(options);
1395
- __publicField(this, "_equals", Object.is);
1396
+ __publicField(this, "_equals", (a, b) => Object.is(a, b));
1396
1397
  __publicField(this, "_head");
1397
1398
  __publicField(this, "_tail");
1398
1399
  __publicField(this, "_length", 0);
@@ -1580,8 +1581,8 @@ var linkedListTyped = (() => {
1580
1581
  at(index) {
1581
1582
  if (index < 0 || index >= this._length) return void 0;
1582
1583
  let current = this.head;
1583
- for (let i = 0; i < index; i++) current = current.next;
1584
- return current.value;
1584
+ for (let i = 0; i < index && current; i++) current = current.next;
1585
+ return current == null ? void 0 : current.value;
1585
1586
  }
1586
1587
  /**
1587
1588
  * Get the node reference at a given index.
@@ -1592,7 +1593,7 @@ var linkedListTyped = (() => {
1592
1593
  getNodeAt(index) {
1593
1594
  if (index < 0 || index >= this._length) return void 0;
1594
1595
  let current = this.head;
1595
- for (let i = 0; i < index; i++) current = current.next;
1596
+ for (let i = 0; i < index && current; i++) current = current.next;
1596
1597
  return current;
1597
1598
  }
1598
1599
  /**