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.
- package/CHANGELOG.md +1 -1
- package/README.md +9 -9
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +17 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +86 -32
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +8 -8
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/bst.js +2 -2
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/cjs/data-structures/graph/abstract-graph.js +5 -5
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +4 -4
- package/dist/cjs/data-structures/graph/directed-graph.js +6 -6
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/map-graph.js +1 -1
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +3 -3
- package/dist/cjs/data-structures/graph/undirected-graph.js +4 -4
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +10 -5
- package/dist/cjs/data-structures/heap/heap.js +10 -10
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +4 -1
- package/dist/cjs/data-structures/heap/max-heap.js +9 -7
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +4 -1
- package/dist/cjs/data-structures/heap/min-heap.js +9 -7
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix2d.d.ts +1 -2
- package/dist/cjs/data-structures/matrix/matrix2d.js +3 -7
- package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -1
- package/dist/cjs/data-structures/matrix/vector2d.js +0 -1
- package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +4 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +9 -7
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +4 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +9 -7
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +5 -2
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/cjs/types/helpers.d.ts +1 -4
- package/dist/cjs/types/helpers.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +17 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +86 -32
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +8 -8
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/bst.js +2 -2
- package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +2 -2
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/mjs/data-structures/graph/abstract-graph.js +5 -5
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +4 -4
- package/dist/mjs/data-structures/graph/directed-graph.js +6 -6
- package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/map-graph.js +1 -1
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +3 -3
- package/dist/mjs/data-structures/graph/undirected-graph.js +4 -4
- package/dist/mjs/data-structures/heap/heap.d.ts +10 -5
- package/dist/mjs/data-structures/heap/heap.js +10 -10
- package/dist/mjs/data-structures/heap/max-heap.d.ts +4 -1
- package/dist/mjs/data-structures/heap/max-heap.js +9 -7
- package/dist/mjs/data-structures/heap/min-heap.d.ts +4 -1
- package/dist/mjs/data-structures/heap/min-heap.js +9 -7
- package/dist/mjs/data-structures/matrix/matrix2d.d.ts +1 -2
- package/dist/mjs/data-structures/matrix/matrix2d.js +3 -7
- package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -1
- package/dist/mjs/data-structures/matrix/vector2d.js +0 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +4 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +9 -7
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +4 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +9 -7
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +5 -2
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/mjs/types/helpers.d.ts +1 -4
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +5 -5
- package/src/data-structures/binary-tree/avl-tree.ts +5 -4
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +21 -1
- package/src/data-structures/binary-tree/binary-tree.ts +37 -93
- package/src/data-structures/binary-tree/bst.ts +11 -17
- package/src/data-structures/binary-tree/rb-tree.ts +2 -1
- package/src/data-structures/binary-tree/tree-multiset.ts +4 -3
- package/src/data-structures/graph/abstract-graph.ts +16 -15
- package/src/data-structures/graph/directed-graph.ts +8 -7
- package/src/data-structures/graph/map-graph.ts +2 -2
- package/src/data-structures/graph/undirected-graph.ts +9 -8
- package/src/data-structures/hash/hash-map.ts +1 -1
- package/src/data-structures/hash/tree-map.ts +1 -2
- package/src/data-structures/hash/tree-set.ts +1 -2
- package/src/data-structures/heap/heap.ts +12 -12
- package/src/data-structures/heap/max-heap.ts +8 -6
- package/src/data-structures/heap/min-heap.ts +8 -6
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/matrix/matrix2d.ts +1 -3
- package/src/data-structures/matrix/vector2d.ts +1 -4
- package/src/data-structures/priority-queue/max-priority-queue.ts +8 -6
- package/src/data-structures/priority-queue/min-priority-queue.ts +8 -6
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/queue/deque.ts +4 -5
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -4
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/helpers.ts +1 -7
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +2 -2
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +141 -1
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +35 -0
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +269 -47
- package/test/unit/data-structures/binary-tree/bst.test.ts +391 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +73 -7
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +241 -186
- package/test/unit/data-structures/graph/directed-graph.test.ts +37 -7
- package/test/unit/data-structures/graph/map-graph.test.ts +82 -1
- package/test/unit/data-structures/graph/overall.test.ts +2 -2
- package/test/unit/data-structures/graph/undirected-graph.test.ts +84 -2
- package/test/unit/data-structures/heap/heap.test.ts +2 -2
- package/test/unit/data-structures/heap/max-heap.test.ts +1 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/matrix/matrix2d.test.ts +207 -0
- package/test/unit/data-structures/matrix/navigator.test.ts +166 -1
- package/test/unit/data-structures/matrix/vector2d.test.ts +171 -0
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +3 -3
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +10 -10
- package/test/unit/data-structures/queue/deque.test.ts +264 -1
- 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
|
-
|
|
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
|
|
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
|
-
|
|
136
|
-
return this.
|
|
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(
|
|
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>(
|
|
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(
|
|
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(
|
|
36
|
-
|
|
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(
|
|
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(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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(
|
|
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 =
|
|
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.
|
|
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.
|
|
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;
|
|
@@ -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(
|
|
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(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
14
|
-
super(
|
|
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,
|
|
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
|
|
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
|
|
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",
|