linked-list-typed 1.38.2 → 1.38.5

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 (43) hide show
  1. package/.dependency-cruiser.js +422 -422
  2. package/.eslintrc.js +59 -59
  3. package/.prettierrc.js +14 -14
  4. package/README.md +15 -3
  5. package/coverage/clover.xml +11 -7
  6. package/coverage/coverage-final.json +165 -1
  7. package/coverage/coverage-summary.json +59 -2
  8. package/coverage/lcov-report/base.css +278 -99
  9. package/coverage/lcov-report/index.html +69 -65
  10. package/coverage/lcov-report/index.ts.html +39 -36
  11. package/coverage/lcov-report/sorter.js +15 -5
  12. package/dist/data-structures/binary-tree/binary-tree.d.ts +9 -9
  13. package/dist/data-structures/binary-tree/bst.d.ts +4 -4
  14. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +12 -3
  15. package/dist/data-structures/linked-list/singly-linked-list.d.ts +17 -4
  16. package/dist/data-structures/linked-list/singly-linked-list.js +2 -0
  17. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  18. package/dist/types/helpers.d.ts +1 -1
  19. package/jest.config.js +6 -6
  20. package/package.json +4 -1
  21. package/src/data-structures/binary-tree/avl-tree.ts +1 -1
  22. package/src/data-structures/binary-tree/binary-indexed-tree.ts +1 -1
  23. package/src/data-structures/binary-tree/binary-tree.ts +21 -21
  24. package/src/data-structures/binary-tree/bst.ts +7 -7
  25. package/src/data-structures/binary-tree/tree-multiset.ts +2 -1
  26. package/src/data-structures/graph/abstract-graph.ts +11 -10
  27. package/src/data-structures/graph/directed-graph.ts +2 -1
  28. package/src/data-structures/graph/undirected-graph.ts +5 -4
  29. package/src/data-structures/hash/hash-map.ts +1 -1
  30. package/src/data-structures/hash/tree-map.ts +1 -2
  31. package/src/data-structures/hash/tree-set.ts +1 -2
  32. package/src/data-structures/linked-list/doubly-linked-list.ts +2 -4
  33. package/src/data-structures/linked-list/singly-linked-list.ts +3 -8
  34. package/src/data-structures/matrix/matrix.ts +1 -1
  35. package/src/data-structures/matrix/vector2d.ts +1 -2
  36. package/src/data-structures/queue/deque.ts +4 -5
  37. package/src/data-structures/queue/queue.ts +1 -1
  38. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  39. package/src/types/data-structures/matrix/navigator.ts +1 -1
  40. package/src/types/helpers.ts +1 -1
  41. package/src/types/utils/utils.ts +1 -1
  42. package/src/types/utils/validate-type.ts +2 -2
  43. package/tsconfig.json +1 -2
@@ -238,9 +238,9 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
238
238
  * @returns either the first node that matches the given nodeProperty and callback, or null if no
239
239
  * matching node is found.
240
240
  */
241
- override get(
241
+ override get<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
242
242
  nodeProperty: BinaryTreeNodeKey | N,
243
- callback: MapCallback<N> = this._defaultCallbackByKey,
243
+ callback: C = this._defaultCallbackByKey as C,
244
244
  beginRoot = this.root,
245
245
  iterationType = this.iterationType
246
246
  ): N | null {
@@ -289,9 +289,9 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
289
289
  * traverse the binary tree. It can have one of the following values:
290
290
  * @returns an array of nodes (N[]).
291
291
  */
292
- override getNodes(
292
+ override getNodes<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
293
293
  nodeProperty: BinaryTreeNodeKey | N,
294
- callback: MapCallback<N> = this._defaultCallbackByKey,
294
+ callback: C = this._defaultCallbackByKey as C,
295
295
  onlyOne = false,
296
296
  beginRoot: N | null = this.root,
297
297
  iterationType = this.iterationType
@@ -363,12 +363,12 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
363
363
  * done recursively or iteratively. It can have two possible values:
364
364
  * @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
365
365
  */
366
- lesserOrGreaterTraverse(
367
- callback: MapCallback<N> = this._defaultCallbackByKey,
366
+ lesserOrGreaterTraverse<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
367
+ callback: C = this._defaultCallbackByKey as C,
368
368
  lesserOrGreater: CP = CP.lt,
369
369
  targetNode: N | BinaryTreeNodeKey | null = this.root,
370
370
  iterationType = this.iterationType
371
- ): MapCallbackReturn<N> {
371
+ ): ReturnType<C>[] {
372
372
  if (typeof targetNode === 'number') targetNode = this.get(targetNode);
373
373
  const ans: MapCallbackReturn<N>[] = [];
374
374
  if (!targetNode) return ans;
@@ -37,7 +37,8 @@ export class TreeMultisetNode<
37
37
  */
38
38
  export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultisetNode>
39
39
  extends AVLTree<N>
40
- implements IBinaryTree<N> {
40
+ implements IBinaryTree<N>
41
+ {
41
42
  /**
42
43
  * The constructor function for a TreeMultiset class in TypeScript, which extends another class and sets an option to
43
44
  * merge duplicated values.
@@ -105,7 +105,8 @@ export abstract class AbstractEdge<V = any> {
105
105
  export abstract class AbstractGraph<
106
106
  V extends AbstractVertex<any> = AbstractVertex<any>,
107
107
  E extends AbstractEdge<any> = AbstractEdge<any>
108
- > implements IGraph<V, E> {
108
+ > implements IGraph<V, E>
109
+ {
109
110
  private _vertices: Map<VertexKey, V> = new Map<VertexKey, V>();
110
111
 
111
112
  get vertices(): Map<VertexKey, V> {
@@ -553,14 +554,14 @@ export abstract class AbstractGraph<
553
554
  }
554
555
 
555
556
  getMinDist &&
556
- distMap.forEach((d, v) => {
557
- if (v !== srcVertex) {
558
- if (d < minDist) {
559
- minDist = d;
560
- if (genPaths) minDest = v;
557
+ distMap.forEach((d, v) => {
558
+ if (v !== srcVertex) {
559
+ if (d < minDist) {
560
+ minDist = d;
561
+ if (genPaths) minDest = v;
562
+ }
561
563
  }
562
- }
563
- });
564
+ });
564
565
 
565
566
  genPaths && getPaths(minDest);
566
567
 
@@ -622,7 +623,7 @@ export abstract class AbstractGraph<
622
623
  if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity);
623
624
  }
624
625
 
625
- const heap = new PriorityQueue<{ key: number; val: V }>((a, b) => a.key - b.key);
626
+ const heap = new PriorityQueue<{key: number; val: V}>((a, b) => a.key - b.key);
626
627
  heap.add({key: 0, val: srcVertex});
627
628
 
628
629
  distMap.set(srcVertex, 0);
@@ -851,7 +852,7 @@ export abstract class AbstractGraph<
851
852
  * `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest
852
853
  * path between vertices in the
853
854
  */
854
- floyd(): { costs: number[][]; predecessor: (V | null)[][] } {
855
+ floyd(): {costs: number[][]; predecessor: (V | null)[][]} {
855
856
  const idAndVertices = [...this._vertices];
856
857
  const n = idAndVertices.length;
857
858
 
@@ -64,7 +64,8 @@ export class DirectedEdge<V = any> extends AbstractEdge<V> {
64
64
 
65
65
  export class DirectedGraph<V extends DirectedVertex<any> = DirectedVertex, E extends DirectedEdge<any> = DirectedEdge>
66
66
  extends AbstractGraph<V, E>
67
- implements IGraph<V, E> {
67
+ implements IGraph<V, E>
68
+ {
68
69
  /**
69
70
  * The constructor function initializes an instance of a class.
70
71
  */
@@ -51,11 +51,12 @@ export class UndirectedEdge<V = number> extends AbstractEdge<V> {
51
51
  }
52
52
 
53
53
  export class UndirectedGraph<
54
- V extends UndirectedVertex<any> = UndirectedVertex,
55
- E extends UndirectedEdge<any> = UndirectedEdge
56
- >
54
+ V extends UndirectedVertex<any> = UndirectedVertex,
55
+ E extends UndirectedEdge<any> = UndirectedEdge
56
+ >
57
57
  extends AbstractGraph<V, E>
58
- implements IGraph<V, E> {
58
+ implements IGraph<V, E>
59
+ {
59
60
  /**
60
61
  * The constructor initializes a new Map object to store edges.
61
62
  */
@@ -157,7 +157,7 @@ export class HashMap<K, V> {
157
157
  }
158
158
  }
159
159
 
160
- * entries(): IterableIterator<[K, V]> {
160
+ *entries(): IterableIterator<[K, V]> {
161
161
  for (const bucket of this.table) {
162
162
  if (bucket) {
163
163
  for (const [key, value] of bucket) {
@@ -1,2 +1 @@
1
- export class TreeMap {
2
- }
1
+ export class TreeMap {}
@@ -1,2 +1 @@
1
- export class TreeSet {
2
- }
1
+ export class TreeSet {}
@@ -266,7 +266,7 @@ export class DoublyLinkedList<E = any> {
266
266
  * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
267
267
  * is found in the linked list. If no such node is found, it returns `null`.
268
268
  */
269
- findNode(val: E): DoublyLinkedListNode<E> | null {
269
+ findNode(val: E | null): DoublyLinkedListNode<E> | null {
270
270
  let current = this.head;
271
271
 
272
272
  while (current) {
@@ -341,7 +341,7 @@ export class DoublyLinkedList<E = any> {
341
341
  * @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
342
342
  * deleted from the doubly linked list, and `false` if the value or node was not found in the list.
343
343
  */
344
- delete(valOrNode: E | DoublyLinkedListNode<E>): boolean {
344
+ delete(valOrNode: E | DoublyLinkedListNode<E> | null): boolean {
345
345
  let node: DoublyLinkedListNode<E> | null;
346
346
 
347
347
  if (valOrNode instanceof DoublyLinkedListNode) {
@@ -594,8 +594,6 @@ export class DoublyLinkedList<E = any> {
594
594
  return false;
595
595
  }
596
596
 
597
- insertBefore(existingValueOrNode: E, newValue: E): boolean;
598
- insertBefore(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
599
597
 
600
598
  /**
601
599
  * The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
@@ -214,9 +214,6 @@ export class SinglyLinkedList<E = any> {
214
214
  return removedNode!.val;
215
215
  }
216
216
 
217
- delete(valueOrNode: E): boolean;
218
- delete(valueOrNode: SinglyLinkedListNode<E>): boolean;
219
-
220
217
  /**
221
218
  * The delete function removes a node with a specific value from a singly linked list.
222
219
  * @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
@@ -224,7 +221,8 @@ export class SinglyLinkedList<E = any> {
224
221
  * @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
225
222
  * successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
226
223
  */
227
- delete(valueOrNode: E | SinglyLinkedListNode<E>): boolean {
224
+ delete(valueOrNode: E | SinglyLinkedListNode<E> | null | undefined): boolean {
225
+ if (!valueOrNode) return false;
228
226
  let value: E;
229
227
  if (valueOrNode instanceof SinglyLinkedListNode) {
230
228
  value = valueOrNode.val;
@@ -397,9 +395,6 @@ export class SinglyLinkedList<E = any> {
397
395
  return null;
398
396
  }
399
397
 
400
- insertBefore(existingValue: E, newValue: E): boolean;
401
- insertBefore(existingValue: SinglyLinkedListNode<E>, newValue: E): boolean;
402
-
403
398
  /**
404
399
  * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
405
400
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
@@ -490,7 +485,7 @@ export class SinglyLinkedList<E = any> {
490
485
  return count;
491
486
  }
492
487
 
493
- * [Symbol.iterator]() {
488
+ *[Symbol.iterator]() {
494
489
  let current = this.head;
495
490
 
496
491
  while (current) {
@@ -14,7 +14,7 @@ export class MatrixNTI2D<V = any> {
14
14
  * given initial value or 0 if not provided.
15
15
  * @param options - An object containing the following properties:
16
16
  */
17
- constructor(options: { row: number; col: number; initialVal?: V }) {
17
+ constructor(options: {row: number; col: number; initialVal?: V}) {
18
18
  const {row, col, initialVal} = options;
19
19
  this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0));
20
20
  }
@@ -10,8 +10,7 @@ export class Vector2D {
10
10
  public x: number = 0,
11
11
  public y: number = 0,
12
12
  public w: number = 1 // needed for matrix multiplication
13
- ) {
14
- }
13
+ ) {}
15
14
 
16
15
  /**
17
16
  * The function checks if the x and y values of a point are both zero.
@@ -9,8 +9,7 @@ import {DoublyLinkedList} from '../linked-list';
9
9
 
10
10
  // O(n) time complexity of obtaining the value
11
11
  // O(1) time complexity of adding at the beginning and the end
12
- export class Deque<E = any> extends DoublyLinkedList<E> {
13
- }
12
+ export class Deque<E = any> extends DoublyLinkedList<E> {}
14
13
 
15
14
  // O(1) time complexity of obtaining the value
16
15
  // O(n) time complexity of adding at the beginning and the end
@@ -20,9 +19,9 @@ export class ObjectDeque<E = number> {
20
19
  if (capacity !== undefined) this._capacity = capacity;
21
20
  }
22
21
 
23
- private _nodes: { [key: number]: E } = {};
22
+ private _nodes: {[key: number]: E} = {};
24
23
 
25
- get nodes(): { [p: number]: E } {
24
+ get nodes(): {[p: number]: E} {
26
25
  return this._nodes;
27
26
  }
28
27
 
@@ -157,7 +156,7 @@ export class ObjectDeque<E = number> {
157
156
  return this._size <= 0;
158
157
  }
159
158
 
160
- protected _seNodes(value: { [p: number]: E }) {
159
+ protected _seNodes(value: {[p: number]: E}) {
161
160
  this._nodes = value;
162
161
  }
163
162
 
@@ -183,7 +183,7 @@ export class Queue<E = any> {
183
183
  return new Queue(this.nodes.slice(this.offset));
184
184
  }
185
185
 
186
- * [Symbol.iterator]() {
186
+ *[Symbol.iterator]() {
187
187
  for (const item of this.nodes) {
188
188
  yield item;
189
189
  }
@@ -24,7 +24,7 @@ export enum FamilyPosition {
24
24
 
25
25
  export type BinaryTreeNodeKey = number;
26
26
 
27
- export type BFSCallback<N> = (node: N, level?: number) => any;
27
+ export type BFSCallback<N, D = any> = (node: N, level?: number) => D;
28
28
 
29
29
  export type BFSCallbackReturn<N> = ReturnType<BFSCallback<N>>;
30
30
 
@@ -1,6 +1,6 @@
1
1
  export type Direction = 'up' | 'right' | 'down' | 'left';
2
2
 
3
- export type Turning = { [key in Direction]: Direction };
3
+ export type Turning = {[key in Direction]: Direction};
4
4
 
5
5
  export type NavigatorParams<T = any> = {
6
6
  matrix: T[][];
@@ -2,7 +2,7 @@ export type Comparator<T> = (a: T, b: T) => number;
2
2
 
3
3
  export type DFSOrderPattern = 'pre' | 'in' | 'post';
4
4
 
5
- export type MapCallback<N> = (node: N) => any;
5
+ export type MapCallback<N, D = any> = (node: N) => D;
6
6
 
7
7
  export type MapCallbackReturn<N> = ReturnType<MapCallback<N>>;
8
8
 
@@ -1,5 +1,5 @@
1
1
  export type ToThunkFn = () => ReturnType<TrlFn>;
2
- export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: symbol };
2
+ export type Thunk = () => ReturnType<ToThunkFn> & {__THUNK__: symbol};
3
3
  export type TrlFn = (...args: any[]) => any;
4
4
  export type TrlAsyncFn = (...args: any[]) => any;
5
5
 
@@ -1,6 +1,6 @@
1
- export type KeyValueObject = { [key: string]: any };
1
+ export type KeyValueObject = {[key: string]: any};
2
2
 
3
- export type KeyValueObjectWithKey = { [key: string]: any; key: string | number | symbol };
3
+ export type KeyValueObjectWithKey = {[key: string]: any; key: string | number | symbol};
4
4
 
5
5
  export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
6
6
 
package/tsconfig.json CHANGED
@@ -26,9 +26,8 @@
26
26
  "node_modules/@types"
27
27
  ]
28
28
  },
29
-
30
29
  "include": [
31
- "src",
30
+ "src"
32
31
  ],
33
32
  "exclude": [
34
33
  // "node_modules/data-structure-typed",