data-structure-typed 1.12.9 → 1.12.11

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 (95) hide show
  1. package/README.md +7 -0
  2. package/package.json +3 -3
  3. package/src/assets/logo.png +0 -0
  4. package/src/data-structures/binary-tree/avl-tree.ts +15 -6
  5. package/src/data-structures/binary-tree/binary-indexed-tree.ts +11 -2
  6. package/src/data-structures/binary-tree/binary-tree.ts +70 -58
  7. package/src/data-structures/binary-tree/bst.ts +94 -7
  8. package/src/data-structures/binary-tree/segment-tree.ts +41 -2
  9. package/src/data-structures/binary-tree/tree-multiset.ts +35 -4
  10. package/src/data-structures/graph/abstract-graph.ts +12 -4
  11. package/src/data-structures/graph/directed-graph.ts +26 -39
  12. package/src/data-structures/graph/undirected-graph.ts +18 -2
  13. package/src/data-structures/hash/coordinate-map.ts +5 -2
  14. package/src/data-structures/hash/coordinate-set.ts +5 -2
  15. package/src/data-structures/heap/heap.ts +13 -10
  16. package/src/data-structures/heap/max-heap.ts +5 -2
  17. package/src/data-structures/heap/min-heap.ts +5 -2
  18. package/src/data-structures/index.ts +2 -0
  19. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -6
  20. package/src/data-structures/linked-list/singly-linked-list.ts +5 -2
  21. package/src/data-structures/matrix/matrix.ts +5 -2
  22. package/src/data-structures/matrix/matrix2d.ts +5 -2
  23. package/src/data-structures/matrix/navigator.ts +5 -2
  24. package/src/data-structures/matrix/vector2d.ts +5 -2
  25. package/src/data-structures/priority-queue/max-priority-queue.ts +5 -2
  26. package/src/data-structures/priority-queue/min-priority-queue.ts +5 -2
  27. package/src/data-structures/priority-queue/priority-queue.ts +7 -4
  28. package/src/data-structures/queue/deque.ts +12 -9
  29. package/src/data-structures/queue/queue.ts +4 -4
  30. package/src/data-structures/stack/stack.ts +1 -1
  31. package/src/data-structures/trie/trie.ts +7 -4
  32. package/src/utils/index.ts +2 -1
  33. package/src/utils/types/utils.ts +10 -12
  34. package/src/utils/utils.ts +57 -11
  35. package/tests/unit/data-structures/binary-tree/bst.test.ts +1 -1
  36. package/tests/unit/data-structures/graph/directed-graph.test.ts +1 -0
  37. package/docs/.nojekyll +0 -1
  38. package/docs/assets/highlight.css +0 -85
  39. package/docs/assets/main.js +0 -58
  40. package/docs/assets/search.js +0 -1
  41. package/docs/assets/style.css +0 -1367
  42. package/docs/classes/AVLTree.html +0 -2046
  43. package/docs/classes/AVLTreeNode.html +0 -423
  44. package/docs/classes/AaTree.html +0 -117
  45. package/docs/classes/AbstractEdge.html +0 -198
  46. package/docs/classes/AbstractGraph.html +0 -891
  47. package/docs/classes/AbstractVertex.html +0 -164
  48. package/docs/classes/ArrayDeque.html +0 -384
  49. package/docs/classes/BST.html +0 -1893
  50. package/docs/classes/BSTNode.html +0 -425
  51. package/docs/classes/BTree.html +0 -117
  52. package/docs/classes/BinaryIndexedTree.html +0 -244
  53. package/docs/classes/BinaryTree.html +0 -1754
  54. package/docs/classes/BinaryTreeNode.html +0 -396
  55. package/docs/classes/Character.html +0 -165
  56. package/docs/classes/CoordinateMap.html +0 -394
  57. package/docs/classes/CoordinateSet.html +0 -355
  58. package/docs/classes/Deque.html +0 -617
  59. package/docs/classes/DirectedEdge.html +0 -247
  60. package/docs/classes/DirectedGraph.html +0 -1207
  61. package/docs/classes/DirectedVertex.html +0 -154
  62. package/docs/classes/DoublyLinkedList.html +0 -619
  63. package/docs/classes/DoublyLinkedListNode.html +0 -160
  64. package/docs/classes/Heap.html +0 -315
  65. package/docs/classes/Matrix2D.html +0 -447
  66. package/docs/classes/MatrixNTI2D.html +0 -181
  67. package/docs/classes/MaxHeap.html +0 -325
  68. package/docs/classes/MaxPriorityQueue.html +0 -668
  69. package/docs/classes/MinHeap.html +0 -326
  70. package/docs/classes/MinPriorityQueue.html +0 -668
  71. package/docs/classes/Navigator.html +0 -285
  72. package/docs/classes/ObjectDeque.html +0 -289
  73. package/docs/classes/PriorityQueue.html +0 -643
  74. package/docs/classes/Queue.html +0 -337
  75. package/docs/classes/RBTree.html +0 -117
  76. package/docs/classes/SegmentTree.html +0 -234
  77. package/docs/classes/SegmentTreeNode.html +0 -302
  78. package/docs/classes/SinglyLinkedList.html +0 -1035
  79. package/docs/classes/SinglyLinkedListNode.html +0 -304
  80. package/docs/classes/SplayTree.html +0 -117
  81. package/docs/classes/Stack.html +0 -313
  82. package/docs/classes/TreeMultiSet.html +0 -1897
  83. package/docs/classes/Trie.html +0 -317
  84. package/docs/classes/TrieNode.html +0 -221
  85. package/docs/classes/TwoThreeTree.html +0 -117
  86. package/docs/classes/UndirectedEdge.html +0 -220
  87. package/docs/classes/UndirectedGraph.html +0 -1006
  88. package/docs/classes/UndirectedVertex.html +0 -154
  89. package/docs/classes/Vector2D.html +0 -746
  90. package/docs/enums/CP.html +0 -126
  91. package/docs/enums/FamilyPosition.html +0 -126
  92. package/docs/enums/LoopType.html +0 -119
  93. package/docs/index.html +0 -288
  94. package/docs/modules.html +0 -146
  95. package/src/utils/trampoline.ts +0 -51
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import {arrayRemove, uuidV4} from '../../utils';
6
9
  import {PriorityQueue} from '../priority-queue';
@@ -26,6 +29,11 @@ export abstract class AbstractEdge {
26
29
 
27
30
  static DEFAULT_EDGE_WEIGHT = 1;
28
31
 
32
+ /**
33
+ * The function is a protected constructor that initializes the weight and generates a unique hash code for an edge.
34
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
35
+ * no weight is provided, it will default to the value of `AbstractEdge.DEFAULT_EDGE_WEIGHT`.
36
+ */
29
37
  protected constructor(weight?: number) {
30
38
  if (weight === undefined) weight = AbstractEdge.DEFAULT_EDGE_WEIGHT;
31
39
  this._weight = weight;
@@ -535,7 +543,7 @@ export abstract class AbstractGraph<V extends AbstractVertex, E extends Abstract
535
543
  }
536
544
 
537
545
  const heap = new PriorityQueue<{ id: number, val: V }>({comparator: (a, b) => a.id - b.id});
538
- heap.offer({id: 0, val: srcVertex});
546
+ heap.add({id: 0, val: srcVertex});
539
547
 
540
548
  distMap.set(srcVertex, 0);
541
549
  preMap.set(srcVertex, null);
@@ -582,7 +590,7 @@ export abstract class AbstractGraph<V extends AbstractVertex, E extends Abstract
582
590
  const distSrcToNeighbor = distMap.get(neighbor);
583
591
  if (distSrcToNeighbor) {
584
592
  if (dist + weight < distSrcToNeighbor) {
585
- heap.offer({id: dist + weight, val: neighbor});
593
+ heap.add({id: dist + weight, val: neighbor});
586
594
  preMap.set(neighbor, cur);
587
595
  distMap.set(neighbor, dist + weight);
588
596
  }
@@ -1,18 +1,35 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import {arrayRemove} from '../../utils';
6
9
  import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
7
10
  import type {IDirectedGraph, TopologicalStatus, VertexId} from '../types';
8
11
 
9
12
  export class DirectedVertex extends AbstractVertex {
13
+ /**
14
+ * The constructor function initializes an object with a given id.
15
+ * @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
16
+ * vertex within a graph or network.
17
+ */
10
18
  constructor(id: VertexId) {
11
19
  super(id);
12
20
  }
13
21
  }
14
22
 
15
23
  export class DirectedEdge extends AbstractEdge {
24
+ /**
25
+ * The constructor function initializes the source and destination vertices of an edge, with an optional weight.
26
+ * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
27
+ * a graph.
28
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex. It represents the vertex
29
+ * to which an edge is directed.
30
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
31
+ * between two vertices.
32
+ */
16
33
  constructor(src: VertexId, dest: VertexId, weight?: number) {
17
34
  super(weight);
18
35
  this._src = src;
@@ -170,7 +187,7 @@ export class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> ext
170
187
 
171
188
  const destInEdges = this._inEdgeMap.get(dest);
172
189
  if (destInEdges && destInEdges.length > 0) {
173
- removed = arrayRemove(destInEdges, (edge: DirectedEdge) => edge.dest === dest.id)[0];
190
+ removed = arrayRemove(destInEdges, (edge: E) => edge.dest === dest.id)[0];
174
191
  }
175
192
 
176
193
  }
@@ -299,41 +316,12 @@ export class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> ext
299
316
  /**
300
317
  * when stored with adjacency list time: O(V+E)
301
318
  * when stored with adjacency matrix time: O(V^2)
302
- * The `topologicalSort` function performs a topological sort on a directed graph and returns the sorted vertices in
303
- * reverse order, or null if the graph contains a cycle.
304
- * @returns The function `topologicalSort()` returns an array of vertices in topological order if there is no cycle in
305
- * the graph. If there is a cycle in the graph, it returns `null`.
319
+ * The `topologicalSort` function performs a topological sort on a graph and returns the sorted vertices in reverse
320
+ * order, or null if the graph contains a cycle.
321
+ * @returns The `topologicalSort()` function returns an array of vertices (`V[]`) in topological order if there is no
322
+ * cycle in the graph. If there is a cycle, it returns `null`.
306
323
  */
307
324
  topologicalSort(): V[] | null {
308
- // vector<vector<int>> g;
309
- // vector<int> color;
310
- // int last;
311
- // bool hasCycle;
312
- //
313
- // bool topo_sort() {
314
- // int n = g.size();
315
- // vector<int> degree(n, 0);
316
- // queue<int> q;
317
- // for (int i = 0; i < n; i++) {
318
- // degree[i] = g[i].size();
319
- // if (degree[i] <= 1) {
320
- // q.push(i);
321
- // }
322
- // }
323
- // int cnt = 0;
324
- // while (!q.empty()) {
325
- // cnt++;
326
- // int root = q.front();
327
- // q.pop();
328
- // for (auto child : g[root]) {
329
- // degree[child]--;
330
- // if (degree[child] == 1) {
331
- // q.push(child);
332
- // }
333
- // }
334
- // }
335
- // return (cnt != n);
336
- // }
337
325
  // When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
338
326
  // When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
339
327
  const statusMap: Map<V, TopologicalStatus> = new Map<V, TopologicalStatus>();
@@ -364,9 +352,8 @@ export class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> ext
364
352
  }
365
353
  }
366
354
 
367
- if (hasCycle) {
368
- return null;
369
- }
355
+ if (hasCycle) return null;
356
+
370
357
  return sorted.reverse();
371
358
  }
372
359
 
@@ -1,18 +1,34 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import {arrayRemove} from '../../utils';
6
9
  import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
7
10
  import type {VertexId} from '../types';
8
11
 
9
12
  export class UndirectedVertex extends AbstractVertex {
13
+ /**
14
+ * The constructor function initializes an object with a given id.
15
+ * @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
16
+ * vertex within a graph or network.
17
+ */
10
18
  constructor(id: VertexId) {
11
19
  super(id);
12
20
  }
13
21
  }
14
22
 
15
23
  export class UndirectedEdge extends AbstractEdge {
24
+ /**
25
+ * The constructor function initializes an instance of a class with two vertex IDs and an optional weight.
26
+ * @param {VertexId} v1 - The parameter `v1` is of type `VertexId` and represents the first vertex in the edge.
27
+ * @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
28
+ * graph.
29
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
30
+ * between two vertices.
31
+ */
16
32
  constructor(v1: VertexId, v2: VertexId, weight?: number) {
17
33
  super(weight);
18
34
  this._vertices = [v1, v2];
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  export class CoordinateMap<V> extends Map<any, V> {
6
9
  private readonly _joint: string = '_';
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  export class CoordinateSet extends Set {
6
9
  private readonly _joint: string = '_';
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import {PriorityQueue} from '../priority-queue';
6
9
  import type {HeapItem, HeapOptions} from '../types';
@@ -59,37 +62,37 @@ export abstract class Heap<T> {
59
62
  }
60
63
 
61
64
  /**
62
- * The `offer` function adds an element to a priority queue with an optional priority value.
65
+ * The `add` function adds an element to a priority queue with an optional priority value.
63
66
  * @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any
64
67
  * type.
65
68
  * @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
66
- * element being offered to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
69
+ * element being added to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
67
70
  * the value of `element`. If the `element` parameter is not a number, then the
68
- * @returns The `offer` method returns the instance of the `Heap` class.
71
+ * @returns The `add` method returns the instance of the `Heap` class.
69
72
  * @throws {Error} if priority is not a valid number
70
73
  */
71
- offer(element: T, priority?: number): Heap<T> {
74
+ add(element: T, priority?: number): Heap<T> {
72
75
  if (typeof element === 'number') {
73
76
  priority = element;
74
77
  } else {
75
78
  if (priority === undefined) {
76
- throw new Error('.offer expects a numeric priority');
79
+ throw new Error('.add expects a numeric priority');
77
80
  }
78
81
  }
79
82
 
80
83
  if (priority && Number.isNaN(+priority)) {
81
- throw new Error('.offer expects a numeric priority');
84
+ throw new Error('.add expects a numeric priority');
82
85
  }
83
86
 
84
87
  if (Number.isNaN(+priority) && Number.isNaN(this._priorityCb(element))) {
85
88
  throw new Error(
86
- '.offer expects a numeric priority '
89
+ '.add expects a numeric priority '
87
90
  + 'or a constructor callback that returns a number'
88
91
  );
89
92
  }
90
93
 
91
94
  const _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element);
92
- this._pq.offer({priority: _priority, element});
95
+ this._pq.add({priority: _priority, element});
93
96
  return this;
94
97
  }
95
98
 
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
 
6
9
  import {Heap} from './heap';
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
 
6
9
  import {Heap} from './heap';
@@ -8,4 +8,6 @@ export * from './heap';
8
8
  export * from './priority-queue';
9
9
  export * from './matrix';
10
10
  export * from './trie';
11
+ export * from './types';
12
+
11
13
 
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import type {DoublyLinkedListGetBy} from '../types';
6
9
 
@@ -34,7 +37,7 @@ export class DoublyLinkedList<T> {
34
37
  * the doubly linked list.
35
38
  * @returns A boolean value is being returned.
36
39
  */
37
- offerFirst(val: T): boolean {
40
+ addFirst(val: T): boolean {
38
41
  const newNode = new DoublyLinkedListNode(val);
39
42
  if (this._size === 0) {
40
43
  this._first = newNode;
@@ -54,7 +57,7 @@ export class DoublyLinkedList<T> {
54
57
  * doubly linked list.
55
58
  * @returns a boolean value, which is always true.
56
59
  */
57
- offerLast(val: T): boolean {
60
+ addLast(val: T): boolean {
58
61
  const newNode = new DoublyLinkedListNode(val);
59
62
  if (this._size === 0) {
60
63
  this._first = newNode;
@@ -247,8 +250,8 @@ export class DoublyLinkedList<T> {
247
250
  */
248
251
  insert(index: number, val: T): boolean {
249
252
  if (index < 0 || index > this._size) return false;
250
- if (index === 0) return !!this.offerFirst(val);
251
- if (index === this._size) return !!this.offerLast(val);
253
+ if (index === 0) return !!this.addFirst(val);
254
+ if (index === this._size) return !!this.addLast(val);
252
255
 
253
256
  const newNode = new DoublyLinkedListNode(val);
254
257
  const prevNode = this.get(index - 1, 'node');
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
 
6
9
  /**
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  // todo need to be improved
6
9
  export class MatrixNTI2D<T = number> {
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import Vector2D from './vector2d'
6
9
 
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import type {Direction, NavigatorParams, Turning} from '../types';
6
9
 
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  export class Vector2D {
6
9
  constructor(
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import {PriorityQueue} from './priority-queue';
6
9
  import type {PriorityQueueOptions} from '../types';
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import {PriorityQueue} from './priority-queue';
6
9
  import type {PriorityQueueOptions} from '../types';
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import type {PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions} from '../types';
6
9
 
@@ -52,11 +55,11 @@ export class PriorityQueue<T = number> {
52
55
  }
53
56
 
54
57
  /**
55
- * The "offer" function adds a node to the heap and ensures that the heap property is maintained.
58
+ * The "add" function adds a node to the heap and ensures that the heap property is maintained.
56
59
  * @param {T} node - The parameter "node" is of type T, which means it can be any data type. It represents the node
57
60
  * that needs to be added to the heap.
58
61
  */
59
- offer(node: T) {
62
+ add(node: T) {
60
63
  this.nodes.push(node);
61
64
  this._heapifyUp(this.size - 1);
62
65
  }
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import {DoublyLinkedList} from '../linked-list';
6
9
 
@@ -28,7 +31,7 @@ export class ObjectDeque<T> {
28
31
  return this._size;
29
32
  }
30
33
 
31
- offerFirst(value: T) {
34
+ addFirst(value: T) {
32
35
  if (this._size === 0) {
33
36
  const mid = Math.floor(this._capacity / 2);
34
37
  this._first = mid;
@@ -40,7 +43,7 @@ export class ObjectDeque<T> {
40
43
  this._size++;
41
44
  }
42
45
 
43
- offerLast(value: T) {
46
+ addLast(value: T) {
44
47
  if (this._size === 0) {
45
48
  const mid = Math.floor(this._capacity / 2);
46
49
  this._first = mid;
@@ -98,11 +101,11 @@ export class ArrayDeque<T> {
98
101
  }
99
102
 
100
103
  /**
101
- * The function "offerLast" adds a value to the end of an array.
104
+ * The function "addLast" adds a value to the end of an array.
102
105
  * @param {T} value - The value parameter represents the value that you want to add to the end of the array.
103
106
  * @returns The return value is the new length of the array after the value has been added.
104
107
  */
105
- offerLast(value: T) {
108
+ addLast(value: T) {
106
109
  return this._nodes.push(value);
107
110
  }
108
111
 
@@ -124,12 +127,12 @@ export class ArrayDeque<T> {
124
127
  }
125
128
 
126
129
  /**
127
- * The function "offerFirst" adds a value to the beginning of an array.
130
+ * The function "addFirst" adds a value to the beginning of an array.
128
131
  * @param {T} value - The value parameter represents the value that you want to add to the beginning of the array.
129
- * @returns The return value of the `offerFirst` function is the new length of the array `_nodes` after adding the
132
+ * @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
130
133
  * `value` at the beginning.
131
134
  */
132
- offerFirst(value: T) {
135
+ addFirst(value: T) {
133
136
  return this._nodes.unshift(value);
134
137
  }
135
138
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license MIT
3
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @copyright Tyler Zeng <zrwusa@gmail.com>
4
4
  * @class
5
5
  */
6
6
  export class Queue<T> {
@@ -31,11 +31,11 @@ export class Queue<T> {
31
31
  }
32
32
 
33
33
  /**
34
- * The offer function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
34
+ * The add function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
35
35
  * @param {T} element - The `element` parameter represents the element that you want to add to the queue.
36
- * @returns The `offer` method is returning a `Queue<T>` object.
36
+ * @returns The `add` method is returning a `Queue<T>` object.
37
37
  */
38
- offer(element: T): Queue<T> {
38
+ add(element: T): Queue<T> {
39
39
  this._nodes.push(element);
40
40
  return this;
41
41
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license MIT
3
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @copyright Tyler Zeng <zrwusa@gmail.com>
4
4
  * @class
5
5
  */
6
6
  export class Stack<T> {
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  export class TrieNode {
6
9
  protected _value;
@@ -45,7 +48,7 @@ export class Trie {
45
48
  this._root = new TrieNode('');
46
49
  if (words) {
47
50
  for (const i of words) {
48
- this.put(i);
51
+ this.add(i);
49
52
  }
50
53
  }
51
54
  }
@@ -60,7 +63,7 @@ export class Trie {
60
63
  this._root = v;
61
64
  }
62
65
 
63
- put(word: string): boolean {
66
+ add(word: string): boolean {
64
67
  let cur = this._root;
65
68
  for (const c of word) {
66
69
  let nodeC = cur.children.get(c);
@@ -1 +1,2 @@
1
- export * from './utils';
1
+ export * from './utils';
2
+ export * from './types';
@@ -1,3 +1,12 @@
1
+ export type JSONSerializable = {
2
+ [key: string]: any
3
+ }
4
+ export type JSONValue = string | number | boolean | undefined | JSONObject;
5
+
6
+ export interface JSONObject {
7
+ [key: string]: JSONValue;
8
+ }
9
+
1
10
  export type AnyFunction<A extends any[] = any[], R = any> = (...args: A) => R;
2
11
  export type Primitive =
3
12
  | number
@@ -32,16 +41,6 @@ export type DeepLeavesWrap<T, TComplex> =
32
41
 
33
42
  type Json = null | string | number | boolean | Json [] | { [name: string]: Json }
34
43
 
35
- export type JSONSerializable = {
36
- [key: string]: any
37
- }
38
-
39
- export type JSONValue = string | number | boolean | undefined | JSONObject;
40
-
41
- export interface JSONObject {
42
- [key: string]: JSONValue;
43
- }
44
-
45
44
  export type TypeName<T> = T extends string
46
45
  ? 'string'
47
46
  : T extends number
@@ -173,8 +172,7 @@ export type CurryFunc<T> = T extends (...args: infer Args) => infer R
173
172
 
174
173
 
175
174
  export type ToThunkFn = () => ReturnType<TrlFn>;
176
- const THUNK_SYMBOL = Symbol('thunk')
177
- export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: typeof THUNK_SYMBOL };
175
+ export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: Symbol };
178
176
  export type TrlFn = (...args: any[]) => any;
179
177
  export type TrlAsyncFn = (...args: any[]) => any;
180
178