data-structure-typed 1.38.9 → 1.39.1

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 (153) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +9 -9
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +2 -2
  4. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
  6. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +17 -0
  7. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +86 -32
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js +8 -8
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
  12. package/dist/cjs/data-structures/binary-tree/bst.js +2 -2
  13. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +2 -2
  16. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  17. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +4 -4
  18. package/dist/cjs/data-structures/graph/abstract-graph.js +5 -5
  19. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/directed-graph.d.ts +4 -4
  21. package/dist/cjs/data-structures/graph/directed-graph.js +6 -6
  22. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
  24. package/dist/cjs/data-structures/graph/map-graph.js +1 -1
  25. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +3 -3
  27. package/dist/cjs/data-structures/graph/undirected-graph.js +4 -4
  28. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  30. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  31. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  32. package/dist/cjs/data-structures/heap/heap.d.ts +10 -5
  33. package/dist/cjs/data-structures/heap/heap.js +10 -10
  34. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  35. package/dist/cjs/data-structures/heap/max-heap.d.ts +4 -1
  36. package/dist/cjs/data-structures/heap/max-heap.js +9 -7
  37. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  38. package/dist/cjs/data-structures/heap/min-heap.d.ts +4 -1
  39. package/dist/cjs/data-structures/heap/min-heap.js +9 -7
  40. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  41. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  42. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  43. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +1 -2
  44. package/dist/cjs/data-structures/matrix/matrix2d.js +3 -7
  45. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
  46. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -1
  47. package/dist/cjs/data-structures/matrix/vector2d.js +0 -1
  48. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  49. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +4 -1
  50. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +9 -7
  51. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  52. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +4 -1
  53. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +9 -7
  54. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  55. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +5 -2
  56. package/dist/cjs/data-structures/priority-queue/priority-queue.js +2 -2
  57. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  58. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  59. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  60. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  61. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
  62. package/dist/cjs/types/helpers.d.ts +1 -4
  63. package/dist/cjs/types/helpers.js.map +1 -1
  64. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +2 -2
  65. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
  66. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +17 -0
  67. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +86 -32
  68. package/dist/mjs/data-structures/binary-tree/binary-tree.js +8 -8
  69. package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
  70. package/dist/mjs/data-structures/binary-tree/bst.js +2 -2
  71. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +2 -2
  72. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +4 -4
  73. package/dist/mjs/data-structures/graph/abstract-graph.js +5 -5
  74. package/dist/mjs/data-structures/graph/directed-graph.d.ts +4 -4
  75. package/dist/mjs/data-structures/graph/directed-graph.js +6 -6
  76. package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
  77. package/dist/mjs/data-structures/graph/map-graph.js +1 -1
  78. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +3 -3
  79. package/dist/mjs/data-structures/graph/undirected-graph.js +4 -4
  80. package/dist/mjs/data-structures/heap/heap.d.ts +10 -5
  81. package/dist/mjs/data-structures/heap/heap.js +10 -10
  82. package/dist/mjs/data-structures/heap/max-heap.d.ts +4 -1
  83. package/dist/mjs/data-structures/heap/max-heap.js +9 -7
  84. package/dist/mjs/data-structures/heap/min-heap.d.ts +4 -1
  85. package/dist/mjs/data-structures/heap/min-heap.js +9 -7
  86. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +1 -2
  87. package/dist/mjs/data-structures/matrix/matrix2d.js +3 -7
  88. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -1
  89. package/dist/mjs/data-structures/matrix/vector2d.js +0 -1
  90. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +4 -1
  91. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +9 -7
  92. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +4 -1
  93. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +9 -7
  94. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +5 -2
  95. package/dist/mjs/data-structures/priority-queue/priority-queue.js +2 -2
  96. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  97. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
  98. package/dist/mjs/types/helpers.d.ts +1 -4
  99. package/dist/umd/data-structure-typed.min.js +1 -1
  100. package/dist/umd/data-structure-typed.min.js.map +1 -1
  101. package/package.json +5 -5
  102. package/src/data-structures/binary-tree/avl-tree.ts +5 -4
  103. package/src/data-structures/binary-tree/binary-indexed-tree.ts +21 -1
  104. package/src/data-structures/binary-tree/binary-tree.ts +37 -93
  105. package/src/data-structures/binary-tree/bst.ts +11 -17
  106. package/src/data-structures/binary-tree/rb-tree.ts +2 -1
  107. package/src/data-structures/binary-tree/tree-multiset.ts +4 -3
  108. package/src/data-structures/graph/abstract-graph.ts +16 -15
  109. package/src/data-structures/graph/directed-graph.ts +8 -7
  110. package/src/data-structures/graph/map-graph.ts +2 -2
  111. package/src/data-structures/graph/undirected-graph.ts +9 -8
  112. package/src/data-structures/hash/hash-map.ts +1 -1
  113. package/src/data-structures/hash/tree-map.ts +1 -2
  114. package/src/data-structures/hash/tree-set.ts +1 -2
  115. package/src/data-structures/heap/heap.ts +12 -12
  116. package/src/data-structures/heap/max-heap.ts +8 -6
  117. package/src/data-structures/heap/min-heap.ts +8 -6
  118. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  119. package/src/data-structures/matrix/matrix.ts +1 -1
  120. package/src/data-structures/matrix/matrix2d.ts +1 -3
  121. package/src/data-structures/matrix/vector2d.ts +1 -4
  122. package/src/data-structures/priority-queue/max-priority-queue.ts +8 -6
  123. package/src/data-structures/priority-queue/min-priority-queue.ts +8 -6
  124. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  125. package/src/data-structures/queue/deque.ts +4 -5
  126. package/src/data-structures/queue/queue.ts +1 -1
  127. package/src/interfaces/binary-tree.ts +2 -2
  128. package/src/types/data-structures/binary-tree/binary-tree.ts +0 -4
  129. package/src/types/data-structures/matrix/navigator.ts +1 -1
  130. package/src/types/helpers.ts +1 -7
  131. package/src/types/utils/utils.ts +1 -1
  132. package/src/types/utils/validate-type.ts +2 -2
  133. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +141 -1
  134. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +35 -0
  135. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +269 -47
  136. package/test/unit/data-structures/binary-tree/bst.test.ts +391 -1
  137. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +73 -7
  138. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +241 -186
  139. package/test/unit/data-structures/graph/directed-graph.test.ts +37 -7
  140. package/test/unit/data-structures/graph/map-graph.test.ts +82 -1
  141. package/test/unit/data-structures/graph/overall.test.ts +2 -2
  142. package/test/unit/data-structures/graph/undirected-graph.test.ts +84 -2
  143. package/test/unit/data-structures/heap/heap.test.ts +2 -2
  144. package/test/unit/data-structures/heap/max-heap.test.ts +1 -1
  145. package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
  146. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +1 -1
  147. package/test/unit/data-structures/matrix/matrix2d.test.ts +207 -0
  148. package/test/unit/data-structures/matrix/navigator.test.ts +166 -1
  149. package/test/unit/data-structures/matrix/vector2d.test.ts +171 -0
  150. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +3 -3
  151. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +10 -10
  152. package/test/unit/data-structures/queue/deque.test.ts +264 -1
  153. package/test/unit/data-structures/queue/queue.test.ts +3 -1
@@ -110,7 +110,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
110
110
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
111
111
  * @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
112
112
  */
113
- removeEdgeBetween(v1, v2) {
113
+ deleteEdgeBetween(v1, v2) {
114
114
  const vertex1 = this._getVertex(v1);
115
115
  const vertex2 = this._getVertex(v2);
116
116
  if (!vertex1 || !vertex2) {
@@ -128,12 +128,12 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
128
128
  return removed;
129
129
  }
130
130
  /**
131
- * The removeEdge function removes an edge between two vertices in a graph.
131
+ * The deleteEdge function removes an edge between two vertices in a graph.
132
132
  * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
133
133
  * @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
134
134
  */
135
- removeEdge(edge) {
136
- return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
135
+ deleteEdge(edge) {
136
+ return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
137
137
  }
138
138
  /**
139
139
  * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
@@ -5,10 +5,13 @@
5
5
  * @license MIT License
6
6
  */
7
7
  import type { Comparator, DFSOrderPattern } from '../../types';
8
- export declare class Heap<E> {
8
+ export declare class Heap<E = any> {
9
9
  protected nodes: E[];
10
10
  protected readonly comparator: Comparator<E>;
11
- constructor(comparator: Comparator<E>);
11
+ constructor(options: {
12
+ comparator: Comparator<E>;
13
+ nodes?: E[];
14
+ });
12
15
  /**
13
16
  * Get the size (number of elements) of the heap.
14
17
  */
@@ -20,11 +23,13 @@ export declare class Heap<E> {
20
23
  get leaf(): E | undefined;
21
24
  /**
22
25
  * Static method that creates a binary heap from an array of nodes and a comparison function.
23
- * @param nodes
24
- * @param comparator - Comparison function.
25
26
  * @returns A new Heap instance.
27
+ * @param options
26
28
  */
27
- static heapify<E>(nodes: E[], comparator: Comparator<E>): Heap<E>;
29
+ static heapify<E>(options: {
30
+ nodes: E[];
31
+ comparator: Comparator<E>;
32
+ }): Heap<E>;
28
33
  /**
29
34
  * Insert an element into the heap and maintain the heap properties.
30
35
  * @param element - The element to be inserted.
@@ -10,8 +10,12 @@ exports.FibonacciHeap = exports.FibonacciHeapNode = exports.Heap = void 0;
10
10
  class Heap {
11
11
  nodes = [];
12
12
  comparator;
13
- constructor(comparator) {
14
- this.comparator = comparator;
13
+ constructor(options) {
14
+ this.comparator = options.comparator;
15
+ if (options.nodes && options.nodes.length > 0) {
16
+ this.nodes = options.nodes;
17
+ this.fix();
18
+ }
15
19
  }
16
20
  /**
17
21
  * Get the size (number of elements) of the heap.
@@ -28,15 +32,11 @@ class Heap {
28
32
  }
29
33
  /**
30
34
  * Static method that creates a binary heap from an array of nodes and a comparison function.
31
- * @param nodes
32
- * @param comparator - Comparison function.
33
35
  * @returns A new Heap instance.
36
+ * @param options
34
37
  */
35
- static heapify(nodes, comparator) {
36
- const binaryHeap = new Heap(comparator);
37
- binaryHeap.nodes = [...nodes];
38
- binaryHeap.fix(); // Fix heap properties
39
- return binaryHeap;
38
+ static heapify(options) {
39
+ return new Heap(options);
40
40
  }
41
41
  /**
42
42
  * Insert an element into the heap and maintain the heap properties.
@@ -161,7 +161,7 @@ class Heap {
161
161
  * @returns A new Heap instance containing the same elements.
162
162
  */
163
163
  clone() {
164
- const clonedHeap = new Heap(this.comparator);
164
+ const clonedHeap = new Heap({ comparator: this.comparator });
165
165
  clonedHeap.nodes = [...this.nodes];
166
166
  return clonedHeap;
167
167
  }
@@ -8,5 +8,8 @@
8
8
  import { Heap } from './heap';
9
9
  import type { Comparator } from '../../types';
10
10
  export declare class MaxHeap<E = any> extends Heap<E> {
11
- constructor(comparator?: Comparator<E>);
11
+ constructor(options?: {
12
+ comparator: Comparator<E>;
13
+ nodes?: E[];
14
+ });
12
15
  }
@@ -10,15 +10,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.MaxHeap = void 0;
11
11
  const heap_1 = require("./heap");
12
12
  class MaxHeap extends heap_1.Heap {
13
- constructor(comparator = (a, b) => {
14
- if (!(typeof a === 'number' && typeof b === 'number')) {
15
- throw new Error('The a, b params of compare function must be number');
16
- }
17
- else {
18
- return b - a;
13
+ constructor(options = {
14
+ comparator: (a, b) => {
15
+ if (!(typeof a === 'number' && typeof b === 'number')) {
16
+ throw new Error('The a, b params of compare function must be number');
17
+ }
18
+ else {
19
+ return b - a;
20
+ }
19
21
  }
20
22
  }) {
21
- super(comparator);
23
+ super(options);
22
24
  }
23
25
  }
24
26
  exports.MaxHeap = MaxHeap;
@@ -8,5 +8,8 @@
8
8
  import { Heap } from './heap';
9
9
  import type { Comparator } from '../../types';
10
10
  export declare class MinHeap<E = any> extends Heap<E> {
11
- constructor(comparator?: Comparator<E>);
11
+ constructor(options?: {
12
+ comparator: Comparator<E>;
13
+ nodes?: E[];
14
+ });
12
15
  }
@@ -10,15 +10,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.MinHeap = void 0;
11
11
  const heap_1 = require("./heap");
12
12
  class MinHeap extends heap_1.Heap {
13
- constructor(comparator = (a, b) => {
14
- if (!(typeof a === 'number' && typeof b === 'number')) {
15
- throw new Error('The a, b params of compare function must be number');
16
- }
17
- else {
18
- return a - b;
13
+ constructor(options = {
14
+ comparator: (a, b) => {
15
+ if (!(typeof a === 'number' && typeof b === 'number')) {
16
+ throw new Error('The a, b params of compare function must be number');
17
+ }
18
+ else {
19
+ return a - b;
20
+ }
19
21
  }
20
22
  }) {
21
- super(comparator);
23
+ super(options);
22
24
  }
23
25
  }
24
26
  exports.MinHeap = MinHeap;
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import Vector2D from './vector2d';
8
+ import { Vector2D } from './vector2d';
9
9
  export declare class Matrix2D {
10
10
  private readonly _matrix;
11
11
  /**
@@ -105,4 +105,3 @@ export declare class Matrix2D {
105
105
  */
106
106
  toVector(): Vector2D;
107
107
  }
108
- export default Matrix2D;
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Matrix2D = void 0;
7
4
  /**
@@ -11,7 +8,7 @@ exports.Matrix2D = void 0;
11
8
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
12
9
  * @license MIT License
13
10
  */
14
- const vector2d_1 = __importDefault(require("./vector2d"));
11
+ const vector2d_1 = require("./vector2d");
15
12
  class Matrix2D {
16
13
  _matrix;
17
14
  /**
@@ -24,7 +21,7 @@ class Matrix2D {
24
21
  if (typeof value === 'undefined') {
25
22
  this._matrix = Matrix2D.identity;
26
23
  }
27
- else if (value instanceof vector2d_1.default) {
24
+ else if (value instanceof vector2d_1.Vector2D) {
28
25
  this._matrix = Matrix2D.identity;
29
26
  this._matrix[0][0] = value.x;
30
27
  this._matrix[1][0] = value.y;
@@ -197,8 +194,7 @@ class Matrix2D {
197
194
  * the first column of the matrix.
198
195
  */
199
196
  toVector() {
200
- return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
197
+ return new vector2d_1.Vector2D(this._matrix[0][0], this._matrix[1][0]);
201
198
  }
202
199
  }
203
200
  exports.Matrix2D = Matrix2D;
204
- exports.default = Matrix2D;
@@ -198,4 +198,3 @@ export declare class Vector2D {
198
198
  */
199
199
  zero(): void;
200
200
  }
201
- export default Vector2D;
@@ -291,4 +291,3 @@ class Vector2D {
291
291
  }
292
292
  }
293
293
  exports.Vector2D = Vector2D;
294
- exports.default = Vector2D;
@@ -8,5 +8,8 @@
8
8
  import { PriorityQueue } from './priority-queue';
9
9
  import type { Comparator } from '../../types';
10
10
  export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
11
- constructor(compare?: Comparator<E>);
11
+ constructor(options?: {
12
+ comparator: Comparator<E>;
13
+ nodes?: E[];
14
+ });
12
15
  }
@@ -10,15 +10,17 @@ exports.MaxPriorityQueue = void 0;
10
10
  */
11
11
  const priority_queue_1 = require("./priority-queue");
12
12
  class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
13
- constructor(compare = (a, b) => {
14
- if (!(typeof a === 'number' && typeof b === 'number')) {
15
- throw new Error('The a, b params of compare function must be number');
16
- }
17
- else {
18
- return b - a;
13
+ constructor(options = {
14
+ comparator: (a, b) => {
15
+ if (!(typeof a === 'number' && typeof b === 'number')) {
16
+ throw new Error('The a, b params of compare function must be number');
17
+ }
18
+ else {
19
+ return b - a;
20
+ }
19
21
  }
20
22
  }) {
21
- super(compare);
23
+ super(options);
22
24
  }
23
25
  }
24
26
  exports.MaxPriorityQueue = MaxPriorityQueue;
@@ -8,5 +8,8 @@
8
8
  import { PriorityQueue } from './priority-queue';
9
9
  import type { Comparator } from '../../types';
10
10
  export declare class MinPriorityQueue<E = any> extends PriorityQueue<E> {
11
- constructor(compare?: Comparator<E>);
11
+ constructor(options?: {
12
+ comparator: Comparator<E>;
13
+ nodes?: E[];
14
+ });
12
15
  }
@@ -10,15 +10,17 @@ exports.MinPriorityQueue = void 0;
10
10
  */
11
11
  const priority_queue_1 = require("./priority-queue");
12
12
  class MinPriorityQueue extends priority_queue_1.PriorityQueue {
13
- constructor(compare = (a, b) => {
14
- if (!(typeof a === 'number' && typeof b === 'number')) {
15
- throw new Error('The a, b params of compare function must be number');
16
- }
17
- else {
18
- return a - b;
13
+ constructor(options = {
14
+ comparator: (a, b) => {
15
+ if (!(typeof a === 'number' && typeof b === 'number')) {
16
+ throw new Error('The a, b params of compare function must be number');
17
+ }
18
+ else {
19
+ return a - b;
20
+ }
19
21
  }
20
22
  }) {
21
- super(compare);
23
+ super(options);
22
24
  }
23
25
  }
24
26
  exports.MinPriorityQueue = MinPriorityQueue;
@@ -7,6 +7,9 @@
7
7
  */
8
8
  import { Heap } from '../heap';
9
9
  import { Comparator } from '../../types';
10
- export declare class PriorityQueue<E> extends Heap<E> {
11
- constructor(comparator: Comparator<E>);
10
+ export declare class PriorityQueue<E = any> extends Heap<E> {
11
+ constructor(options: {
12
+ comparator: Comparator<E>;
13
+ nodes?: E[];
14
+ });
12
15
  }
@@ -10,8 +10,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.PriorityQueue = void 0;
11
11
  const heap_1 = require("../heap");
12
12
  class PriorityQueue extends heap_1.Heap {
13
- constructor(comparator) {
14
- super(comparator);
13
+ constructor(options) {
14
+ super(options);
15
15
  }
16
16
  }
17
17
  exports.PriorityQueue = PriorityQueue;
@@ -1,7 +1,7 @@
1
1
  import { BinaryTreeNode } from '../data-structures';
2
- import { BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodeNested, MapCallback } from '../types';
2
+ import { BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodeNested, OneParamCallback } from '../types';
3
3
  export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
4
4
  createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
5
5
  add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
6
- delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): BinaryTreeDeletedResult<N>[];
6
+ delete<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeletedResult<N>[];
7
7
  }
@@ -19,8 +19,6 @@ export declare enum FamilyPosition {
19
19
  MAL_NODE = "MAL_NODE"
20
20
  }
21
21
  export type BinaryTreeNodeKey = number;
22
- export type BFSCallback<N, D = any> = (node: N, level?: number) => D;
23
- export type BFSCallbackReturn<N> = ReturnType<BFSCallback<N>>;
24
22
  export type BinaryTreeDeletedResult<N> = {
25
23
  deleted: N | null | undefined;
26
24
  needBalanced: N | null;
@@ -1,9 +1,6 @@
1
- import { BinaryTreeNodeKey } from './data-structures';
2
1
  export type Comparator<T> = (a: T, b: T) => number;
3
2
  export type DFSOrderPattern = 'pre' | 'in' | 'post';
4
- export type MapCallback<N, D = any> = (node: N) => D;
5
- export type DefaultMapCallback<N, D = BinaryTreeNodeKey> = (node: N) => D;
6
- export type MapCallbackReturn<N> = ReturnType<MapCallback<N>>;
3
+ export type OneParamCallback<N, D = any> = (node: N) => D;
7
4
  export declare enum CP {
8
5
  lt = "lt",
9
6
  eq = "eq",