data-structure-typed 1.12.10 → 1.12.21
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/README.md +7 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +14 -5
- package/dist/data-structures/binary-tree/avl-tree.js +15 -6
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +11 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +11 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +26 -17
- package/dist/data-structures/binary-tree/binary-tree.js +72 -62
- package/dist/data-structures/binary-tree/bst.d.ts +92 -5
- package/dist/data-structures/binary-tree/bst.js +89 -5
- package/dist/data-structures/binary-tree/segment-tree.d.ts +41 -2
- package/dist/data-structures/binary-tree/segment-tree.js +41 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +34 -3
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -4
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -0
- package/dist/data-structures/graph/abstract-graph.js +12 -4
- package/dist/data-structures/graph/directed-graph.d.ts +18 -4
- package/dist/data-structures/graph/directed-graph.js +24 -37
- package/dist/data-structures/graph/undirected-graph.d.ts +13 -0
- package/dist/data-structures/graph/undirected-graph.js +18 -2
- package/dist/data-structures/hash/coordinate-map.d.ts +5 -2
- package/dist/data-structures/hash/coordinate-map.js +5 -2
- package/dist/data-structures/hash/coordinate-set.d.ts +5 -2
- package/dist/data-structures/hash/coordinate-set.js +5 -2
- package/dist/data-structures/heap/heap.d.ts +9 -6
- package/dist/data-structures/heap/heap.js +8 -8
- package/dist/data-structures/heap/max-heap.d.ts +5 -2
- package/dist/data-structures/heap/max-heap.js +5 -2
- package/dist/data-structures/heap/min-heap.d.ts +5 -2
- package/dist/data-structures/heap/min-heap.js +5 -2
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/doubly-linked-list.js +4 -4
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +5 -2
- package/dist/data-structures/linked-list/singly-linked-list.js +5 -2
- package/dist/data-structures/matrix/matrix.d.ts +5 -2
- package/dist/data-structures/matrix/matrix.js +5 -2
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -2
- package/dist/data-structures/matrix/matrix2d.js +5 -2
- package/dist/data-structures/matrix/navigator.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.js +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +7 -4
- package/dist/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/data-structures/queue/deque.d.ts +12 -9
- package/dist/data-structures/queue/deque.js +12 -9
- package/dist/data-structures/queue/queue.d.ts +4 -4
- package/dist/data-structures/queue/queue.js +4 -4
- package/dist/data-structures/stack/stack.d.ts +1 -1
- package/dist/data-structures/stack/stack.js +1 -1
- package/dist/data-structures/trie/trie.d.ts +6 -3
- package/dist/data-structures/trie/trie.js +7 -4
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/utils.d.ts +8 -10
- package/dist/utils/types/utils.js +0 -1
- package/dist/utils/utils.d.ts +18 -8
- package/dist/utils/utils.js +93 -47
- package/package.json +3 -3
- package/src/assets/logo.png +0 -0
- package/src/data-structures/binary-tree/avl-tree.ts +15 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +11 -2
- package/src/data-structures/binary-tree/binary-tree.ts +70 -58
- package/src/data-structures/binary-tree/bst.ts +94 -7
- package/src/data-structures/binary-tree/segment-tree.ts +41 -2
- package/src/data-structures/binary-tree/tree-multiset.ts +35 -4
- package/src/data-structures/graph/abstract-graph.ts +12 -4
- package/src/data-structures/graph/directed-graph.ts +26 -39
- package/src/data-structures/graph/undirected-graph.ts +18 -2
- package/src/data-structures/hash/coordinate-map.ts +5 -2
- package/src/data-structures/hash/coordinate-set.ts +5 -2
- package/src/data-structures/heap/heap.ts +13 -10
- package/src/data-structures/heap/max-heap.ts +5 -2
- package/src/data-structures/heap/min-heap.ts +5 -2
- package/src/data-structures/index.ts +2 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +9 -6
- package/src/data-structures/linked-list/singly-linked-list.ts +5 -2
- package/src/data-structures/matrix/matrix.ts +5 -2
- package/src/data-structures/matrix/matrix2d.ts +5 -2
- package/src/data-structures/matrix/navigator.ts +5 -2
- package/src/data-structures/matrix/vector2d.ts +5 -2
- package/src/data-structures/priority-queue/max-priority-queue.ts +5 -2
- package/src/data-structures/priority-queue/min-priority-queue.ts +5 -2
- package/src/data-structures/priority-queue/priority-queue.ts +7 -4
- package/src/data-structures/queue/deque.ts +12 -9
- package/src/data-structures/queue/queue.ts +4 -4
- package/src/data-structures/stack/stack.ts +1 -1
- package/src/data-structures/trie/trie.ts +7 -4
- package/src/utils/index.ts +2 -1
- package/src/utils/types/utils.ts +10 -12
- package/src/utils/utils.ts +57 -11
- package/tests/unit/data-structures/binary-tree/bst.test.ts +1 -1
- package/tests/unit/data-structures/graph/directed-graph.test.ts +1 -0
- package/dist/utils/trampoline.d.ts +0 -14
- package/dist/utils/trampoline.js +0 -130
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -85
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/classes/AVLTree.html +0 -2046
- package/docs/classes/AVLTreeNode.html +0 -423
- package/docs/classes/AaTree.html +0 -117
- package/docs/classes/AbstractEdge.html +0 -198
- package/docs/classes/AbstractGraph.html +0 -891
- package/docs/classes/AbstractVertex.html +0 -164
- package/docs/classes/ArrayDeque.html +0 -384
- package/docs/classes/BST.html +0 -1893
- package/docs/classes/BSTNode.html +0 -425
- package/docs/classes/BTree.html +0 -117
- package/docs/classes/BinaryIndexedTree.html +0 -244
- package/docs/classes/BinaryTree.html +0 -1754
- package/docs/classes/BinaryTreeNode.html +0 -396
- package/docs/classes/Character.html +0 -165
- package/docs/classes/CoordinateMap.html +0 -394
- package/docs/classes/CoordinateSet.html +0 -355
- package/docs/classes/Deque.html +0 -617
- package/docs/classes/DirectedEdge.html +0 -247
- package/docs/classes/DirectedGraph.html +0 -1207
- package/docs/classes/DirectedVertex.html +0 -154
- package/docs/classes/DoublyLinkedList.html +0 -619
- package/docs/classes/DoublyLinkedListNode.html +0 -160
- package/docs/classes/Heap.html +0 -315
- package/docs/classes/Matrix2D.html +0 -447
- package/docs/classes/MatrixNTI2D.html +0 -181
- package/docs/classes/MaxHeap.html +0 -325
- package/docs/classes/MaxPriorityQueue.html +0 -668
- package/docs/classes/MinHeap.html +0 -326
- package/docs/classes/MinPriorityQueue.html +0 -668
- package/docs/classes/Navigator.html +0 -285
- package/docs/classes/ObjectDeque.html +0 -289
- package/docs/classes/PriorityQueue.html +0 -643
- package/docs/classes/Queue.html +0 -337
- package/docs/classes/RBTree.html +0 -117
- package/docs/classes/SegmentTree.html +0 -234
- package/docs/classes/SegmentTreeNode.html +0 -302
- package/docs/classes/SinglyLinkedList.html +0 -1035
- package/docs/classes/SinglyLinkedListNode.html +0 -304
- package/docs/classes/SplayTree.html +0 -117
- package/docs/classes/Stack.html +0 -313
- package/docs/classes/TreeMultiSet.html +0 -1897
- package/docs/classes/Trie.html +0 -317
- package/docs/classes/TrieNode.html +0 -221
- package/docs/classes/TwoThreeTree.html +0 -117
- package/docs/classes/UndirectedEdge.html +0 -220
- package/docs/classes/UndirectedGraph.html +0 -1006
- package/docs/classes/UndirectedVertex.html +0 -154
- package/docs/classes/Vector2D.html +0 -746
- package/docs/enums/CP.html +0 -126
- package/docs/enums/FamilyPosition.html +0 -126
- package/docs/enums/LoopType.html +0 -119
- package/docs/index.html +0 -288
- package/docs/modules.html +0 -146
- package/src/utils/trampoline.ts +0 -51
|
@@ -53,13 +53,21 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
exports.UndirectedGraph = exports.UndirectedEdge = exports.UndirectedVertex = void 0;
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* data-structure-typed
|
|
57
|
+
*
|
|
58
|
+
* @author Tyler Zeng
|
|
59
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
60
|
+
* @license MIT License
|
|
58
61
|
*/
|
|
59
62
|
var utils_1 = require("../../utils");
|
|
60
63
|
var abstract_graph_1 = require("./abstract-graph");
|
|
61
64
|
var UndirectedVertex = /** @class */ (function (_super) {
|
|
62
65
|
__extends(UndirectedVertex, _super);
|
|
66
|
+
/**
|
|
67
|
+
* The constructor function initializes an object with a given id.
|
|
68
|
+
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
|
|
69
|
+
* vertex within a graph or network.
|
|
70
|
+
*/
|
|
63
71
|
function UndirectedVertex(id) {
|
|
64
72
|
return _super.call(this, id) || this;
|
|
65
73
|
}
|
|
@@ -68,6 +76,14 @@ var UndirectedVertex = /** @class */ (function (_super) {
|
|
|
68
76
|
exports.UndirectedVertex = UndirectedVertex;
|
|
69
77
|
var UndirectedEdge = /** @class */ (function (_super) {
|
|
70
78
|
__extends(UndirectedEdge, _super);
|
|
79
|
+
/**
|
|
80
|
+
* The constructor function initializes an instance of a class with two vertex IDs and an optional weight.
|
|
81
|
+
* @param {VertexId} v1 - The parameter `v1` is of type `VertexId` and represents the first vertex in the edge.
|
|
82
|
+
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
|
|
83
|
+
* graph.
|
|
84
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
|
|
85
|
+
* between two vertices.
|
|
86
|
+
*/
|
|
71
87
|
function UndirectedEdge(v1, v2, weight) {
|
|
72
88
|
var _this = _super.call(this, weight) || this;
|
|
73
89
|
_this._vertices = [v1, v2];
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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 declare class CoordinateMap<V> extends Map<any, V> {
|
|
6
9
|
private readonly _joint;
|
|
@@ -17,8 +17,11 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.CoordinateMap = void 0;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* data-structure-typed
|
|
21
|
+
*
|
|
22
|
+
* @author Tyler Zeng
|
|
23
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
24
|
+
* @license MIT License
|
|
22
25
|
*/
|
|
23
26
|
var CoordinateMap = /** @class */ (function (_super) {
|
|
24
27
|
__extends(CoordinateMap, _super);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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 declare class CoordinateSet extends Set {
|
|
6
9
|
private readonly _joint;
|
|
@@ -17,8 +17,11 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.CoordinateSet = void 0;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* data-structure-typed
|
|
21
|
+
*
|
|
22
|
+
* @author Tyler Zeng
|
|
23
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
24
|
+
* @license MIT License
|
|
22
25
|
*/
|
|
23
26
|
var CoordinateSet = /** @class */ (function (_super) {
|
|
24
27
|
__extends(CoordinateSet, _super);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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';
|
|
@@ -34,16 +37,16 @@ export declare abstract class Heap<T> {
|
|
|
34
37
|
*/
|
|
35
38
|
peekLast(): HeapItem<T> | null;
|
|
36
39
|
/**
|
|
37
|
-
* The `
|
|
40
|
+
* The `add` function adds an element to a priority queue with an optional priority value.
|
|
38
41
|
* @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any
|
|
39
42
|
* type.
|
|
40
43
|
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
|
|
41
|
-
* element being
|
|
44
|
+
* element being added to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
|
|
42
45
|
* the value of `element`. If the `element` parameter is not a number, then the
|
|
43
|
-
* @returns The `
|
|
46
|
+
* @returns The `add` method returns the instance of the `Heap` class.
|
|
44
47
|
* @throws {Error} if priority is not a valid number
|
|
45
48
|
*/
|
|
46
|
-
|
|
49
|
+
add(element: T, priority?: number): Heap<T>;
|
|
47
50
|
/**
|
|
48
51
|
* The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an element with the highest priority in the queue
|
|
49
52
|
* @returns either a HeapItem<T> object or null.
|
|
@@ -52,33 +52,33 @@ var Heap = /** @class */ (function () {
|
|
|
52
52
|
return this._pq.leaf();
|
|
53
53
|
};
|
|
54
54
|
/**
|
|
55
|
-
* The `
|
|
55
|
+
* The `add` function adds an element to a priority queue with an optional priority value.
|
|
56
56
|
* @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any
|
|
57
57
|
* type.
|
|
58
58
|
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
|
|
59
|
-
* element being
|
|
59
|
+
* element being added to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
|
|
60
60
|
* the value of `element`. If the `element` parameter is not a number, then the
|
|
61
|
-
* @returns The `
|
|
61
|
+
* @returns The `add` method returns the instance of the `Heap` class.
|
|
62
62
|
* @throws {Error} if priority is not a valid number
|
|
63
63
|
*/
|
|
64
|
-
Heap.prototype.
|
|
64
|
+
Heap.prototype.add = function (element, priority) {
|
|
65
65
|
if (typeof element === 'number') {
|
|
66
66
|
priority = element;
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
69
|
if (priority === undefined) {
|
|
70
|
-
throw new Error('.
|
|
70
|
+
throw new Error('.add expects a numeric priority');
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
if (priority && Number.isNaN(+priority)) {
|
|
74
|
-
throw new Error('.
|
|
74
|
+
throw new Error('.add expects a numeric priority');
|
|
75
75
|
}
|
|
76
76
|
if (Number.isNaN(+priority) && Number.isNaN(this._priorityCb(element))) {
|
|
77
|
-
throw new Error('.
|
|
77
|
+
throw new Error('.add expects a numeric priority '
|
|
78
78
|
+ 'or a constructor callback that returns a number');
|
|
79
79
|
}
|
|
80
80
|
var _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element);
|
|
81
|
-
this._pq.
|
|
81
|
+
this._pq.add({ priority: _priority, element: element });
|
|
82
82
|
return this;
|
|
83
83
|
};
|
|
84
84
|
/**
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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 { Heap } from './heap';
|
|
6
9
|
import { PriorityQueue } from '../priority-queue';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Tyler Zeng
|
|
6
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
5
8
|
*/
|
|
6
9
|
var __extends = (this && this.__extends) || (function () {
|
|
7
10
|
var extendStatics = function (d, b) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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 { Heap } from './heap';
|
|
6
9
|
import { PriorityQueue } from '../priority-queue';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Tyler Zeng
|
|
6
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
5
8
|
*/
|
|
6
9
|
var __extends = (this && this.__extends) || (function () {
|
|
7
10
|
var extendStatics = function (d, b) {
|
|
@@ -16,14 +16,14 @@ export declare class DoublyLinkedList<T> {
|
|
|
16
16
|
* the doubly linked list.
|
|
17
17
|
* @returns A boolean value is being returned.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
addFirst(val: T): boolean;
|
|
20
20
|
/**
|
|
21
21
|
* The function adds a new node with a given value to the end of a doubly linked list.
|
|
22
22
|
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the end of the
|
|
23
23
|
* doubly linked list.
|
|
24
24
|
* @returns a boolean value, which is always true.
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
addLast(val: T): boolean;
|
|
27
27
|
peekFirst(): T | null;
|
|
28
28
|
peekFirst(by: 'val'): T | null;
|
|
29
29
|
peekFirst(by: 'node'): DoublyLinkedListNode<T> | null;
|
|
@@ -33,7 +33,7 @@ var DoublyLinkedList = /** @class */ (function () {
|
|
|
33
33
|
* the doubly linked list.
|
|
34
34
|
* @returns A boolean value is being returned.
|
|
35
35
|
*/
|
|
36
|
-
DoublyLinkedList.prototype.
|
|
36
|
+
DoublyLinkedList.prototype.addFirst = function (val) {
|
|
37
37
|
var newNode = new DoublyLinkedListNode(val);
|
|
38
38
|
if (this._size === 0) {
|
|
39
39
|
this._first = newNode;
|
|
@@ -54,7 +54,7 @@ var DoublyLinkedList = /** @class */ (function () {
|
|
|
54
54
|
* doubly linked list.
|
|
55
55
|
* @returns a boolean value, which is always true.
|
|
56
56
|
*/
|
|
57
|
-
DoublyLinkedList.prototype.
|
|
57
|
+
DoublyLinkedList.prototype.addLast = function (val) {
|
|
58
58
|
var newNode = new DoublyLinkedListNode(val);
|
|
59
59
|
if (this._size === 0) {
|
|
60
60
|
this._first = newNode;
|
|
@@ -247,9 +247,9 @@ var DoublyLinkedList = /** @class */ (function () {
|
|
|
247
247
|
if (index < 0 || index > this._size)
|
|
248
248
|
return false;
|
|
249
249
|
if (index === 0)
|
|
250
|
-
return !!this.
|
|
250
|
+
return !!this.addFirst(val);
|
|
251
251
|
if (index === this._size)
|
|
252
|
-
return !!this.
|
|
252
|
+
return !!this.addLast(val);
|
|
253
253
|
var newNode = new DoublyLinkedListNode(val);
|
|
254
254
|
var prevNode = this.get(index - 1, 'node');
|
|
255
255
|
var nextNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
* The class which represents one link or node in a linked list
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Tyler Zeng
|
|
6
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
5
8
|
*/
|
|
6
9
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
7
10
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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 declare class MatrixNTI2D<T = number> {
|
|
6
9
|
private readonly _matrix;
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MatrixNTI2D = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
7
10
|
*/
|
|
8
11
|
// todo need to be improved
|
|
9
12
|
var MatrixNTI2D = /** @class */ (function () {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
export declare class Matrix2D {
|
|
@@ -5,8 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Matrix2D = void 0;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* data-structure-typed
|
|
9
|
+
*
|
|
10
|
+
* @author Tyler Zeng
|
|
11
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
12
|
+
* @license MIT License
|
|
10
13
|
*/
|
|
11
14
|
var vector2d_1 = __importDefault(require("./vector2d"));
|
|
12
15
|
var Matrix2D = /** @class */ (function () {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
export declare class Character {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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 declare class Vector2D {
|
|
6
9
|
x: number;
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Vector2D = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
7
10
|
*/
|
|
8
11
|
var Vector2D = /** @class */ (function () {
|
|
9
12
|
function Vector2D(x, y, w // needed for matrix multiplication
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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';
|
|
@@ -17,8 +17,11 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.MaxPriorityQueue = void 0;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* data-structure-typed
|
|
21
|
+
*
|
|
22
|
+
* @author Tyler Zeng
|
|
23
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
24
|
+
* @license MIT License
|
|
22
25
|
*/
|
|
23
26
|
var priority_queue_1 = require("./priority-queue");
|
|
24
27
|
var MaxPriorityQueue = /** @class */ (function (_super) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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';
|
|
@@ -17,8 +17,11 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.MinPriorityQueue = void 0;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* data-structure-typed
|
|
21
|
+
*
|
|
22
|
+
* @author Tyler Zeng
|
|
23
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
24
|
+
* @license MIT License
|
|
22
25
|
*/
|
|
23
26
|
var priority_queue_1 = require("./priority-queue");
|
|
24
27
|
var MinPriorityQueue = /** @class */ (function (_super) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
export declare class PriorityQueue<T = number> {
|
|
@@ -29,11 +32,11 @@ export declare class PriorityQueue<T = number> {
|
|
|
29
32
|
*/
|
|
30
33
|
static isPriorityQueueified<T>(options: Omit<PriorityQueueOptions<T>, 'isFix'>): boolean;
|
|
31
34
|
/**
|
|
32
|
-
* The "
|
|
35
|
+
* The "add" function adds a node to the heap and ensures that the heap property is maintained.
|
|
33
36
|
* @param {T} node - The parameter "node" is of type T, which means it can be any data type. It represents the node
|
|
34
37
|
* that needs to be added to the heap.
|
|
35
38
|
*/
|
|
36
|
-
|
|
39
|
+
add(node: T): void;
|
|
37
40
|
/**
|
|
38
41
|
* The `peek` function returns the first element of the `nodes` array if it exists, otherwise it returns `null`.
|
|
39
42
|
* @returns The `peek()` function is returning the first element (`T`) of the `nodes` array if the `size` is not zero.
|
|
@@ -87,11 +87,11 @@ var PriorityQueue = /** @class */ (function () {
|
|
|
87
87
|
return new PriorityQueue(__assign(__assign({}, options), { isFix: true })).isValid();
|
|
88
88
|
};
|
|
89
89
|
/**
|
|
90
|
-
* The "
|
|
90
|
+
* The "add" function adds a node to the heap and ensures that the heap property is maintained.
|
|
91
91
|
* @param {T} node - The parameter "node" is of type T, which means it can be any data type. It represents the node
|
|
92
92
|
* that needs to be added to the heap.
|
|
93
93
|
*/
|
|
94
|
-
PriorityQueue.prototype.
|
|
94
|
+
PriorityQueue.prototype.add = function (node) {
|
|
95
95
|
this.nodes.push(node);
|
|
96
96
|
this._heapifyUp(this.size - 1);
|
|
97
97
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
export declare class Deque<T> extends DoublyLinkedList<T> {
|
|
@@ -15,8 +18,8 @@ export declare class ObjectDeque<T> {
|
|
|
15
18
|
protected _size: number;
|
|
16
19
|
constructor(capacity?: number);
|
|
17
20
|
size(): number;
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
addFirst(value: T): void;
|
|
22
|
+
addLast(value: T): void;
|
|
20
23
|
pollFirst(): T | undefined;
|
|
21
24
|
peekFirst(): T | undefined;
|
|
22
25
|
pollLast(): T | undefined;
|
|
@@ -28,11 +31,11 @@ export declare class ArrayDeque<T> {
|
|
|
28
31
|
protected _nodes: T[];
|
|
29
32
|
get size(): number;
|
|
30
33
|
/**
|
|
31
|
-
* The function "
|
|
34
|
+
* The function "addLast" adds a value to the end of an array.
|
|
32
35
|
* @param {T} value - The value parameter represents the value that you want to add to the end of the array.
|
|
33
36
|
* @returns The return value is the new length of the array after the value has been added.
|
|
34
37
|
*/
|
|
35
|
-
|
|
38
|
+
addLast(value: T): number;
|
|
36
39
|
/**
|
|
37
40
|
* The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
|
|
38
41
|
* @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
|
|
@@ -45,12 +48,12 @@ export declare class ArrayDeque<T> {
|
|
|
45
48
|
*/
|
|
46
49
|
pollFirst(): T | null;
|
|
47
50
|
/**
|
|
48
|
-
* The function "
|
|
51
|
+
* The function "addFirst" adds a value to the beginning of an array.
|
|
49
52
|
* @param {T} value - The value parameter represents the value that you want to add to the beginning of the array.
|
|
50
|
-
* @returns The return value of the `
|
|
53
|
+
* @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
|
|
51
54
|
* `value` at the beginning.
|
|
52
55
|
*/
|
|
53
|
-
|
|
56
|
+
addFirst(value: T): number;
|
|
54
57
|
/**
|
|
55
58
|
* The `peekFirst` function returns the first element of an array or null if the array is empty.
|
|
56
59
|
* @returns The function `peekFirst()` is returning the first element (`T`) of the `_nodes` array. If the array is
|
|
@@ -17,8 +17,11 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.ArrayDeque = exports.ObjectDeque = exports.Deque = void 0;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* data-structure-typed
|
|
21
|
+
*
|
|
22
|
+
* @author Tyler Zeng
|
|
23
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
24
|
+
* @license MIT License
|
|
22
25
|
*/
|
|
23
26
|
var linked_list_1 = require("../linked-list");
|
|
24
27
|
// O(n) time complexity of obtaining the value
|
|
@@ -47,7 +50,7 @@ var ObjectDeque = /** @class */ (function () {
|
|
|
47
50
|
ObjectDeque.prototype.size = function () {
|
|
48
51
|
return this._size;
|
|
49
52
|
};
|
|
50
|
-
ObjectDeque.prototype.
|
|
53
|
+
ObjectDeque.prototype.addFirst = function (value) {
|
|
51
54
|
if (this._size === 0) {
|
|
52
55
|
var mid = Math.floor(this._capacity / 2);
|
|
53
56
|
this._first = mid;
|
|
@@ -59,7 +62,7 @@ var ObjectDeque = /** @class */ (function () {
|
|
|
59
62
|
this._nodes[this._first] = value;
|
|
60
63
|
this._size++;
|
|
61
64
|
};
|
|
62
|
-
ObjectDeque.prototype.
|
|
65
|
+
ObjectDeque.prototype.addLast = function (value) {
|
|
63
66
|
if (this._size === 0) {
|
|
64
67
|
var mid = Math.floor(this._capacity / 2);
|
|
65
68
|
this._first = mid;
|
|
@@ -120,11 +123,11 @@ var ArrayDeque = /** @class */ (function () {
|
|
|
120
123
|
configurable: true
|
|
121
124
|
});
|
|
122
125
|
/**
|
|
123
|
-
* The function "
|
|
126
|
+
* The function "addLast" adds a value to the end of an array.
|
|
124
127
|
* @param {T} value - The value parameter represents the value that you want to add to the end of the array.
|
|
125
128
|
* @returns The return value is the new length of the array after the value has been added.
|
|
126
129
|
*/
|
|
127
|
-
ArrayDeque.prototype.
|
|
130
|
+
ArrayDeque.prototype.addLast = function (value) {
|
|
128
131
|
return this._nodes.push(value);
|
|
129
132
|
};
|
|
130
133
|
/**
|
|
@@ -145,12 +148,12 @@ var ArrayDeque = /** @class */ (function () {
|
|
|
145
148
|
return (_a = this._nodes.shift()) !== null && _a !== void 0 ? _a : null;
|
|
146
149
|
};
|
|
147
150
|
/**
|
|
148
|
-
* The function "
|
|
151
|
+
* The function "addFirst" adds a value to the beginning of an array.
|
|
149
152
|
* @param {T} value - The value parameter represents the value that you want to add to the beginning of the array.
|
|
150
|
-
* @returns The return value of the `
|
|
153
|
+
* @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
|
|
151
154
|
* `value` at the beginning.
|
|
152
155
|
*/
|
|
153
|
-
ArrayDeque.prototype.
|
|
156
|
+
ArrayDeque.prototype.addFirst = function (value) {
|
|
154
157
|
return this._nodes.unshift(value);
|
|
155
158
|
};
|
|
156
159
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license MIT
|
|
3
|
-
* @copyright
|
|
3
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
4
|
* @class
|
|
5
5
|
*/
|
|
6
6
|
export declare class Queue<T> {
|
|
@@ -23,11 +23,11 @@ export declare class Queue<T> {
|
|
|
23
23
|
*/
|
|
24
24
|
static fromArray<T>(elements: T[]): Queue<T>;
|
|
25
25
|
/**
|
|
26
|
-
* The
|
|
26
|
+
* 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.
|
|
27
27
|
* @param {T} element - The `element` parameter represents the element that you want to add to the queue.
|
|
28
|
-
* @returns The `
|
|
28
|
+
* @returns The `add` method is returning a `Queue<T>` object.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
add(element: T): Queue<T>;
|
|
31
31
|
/**
|
|
32
32
|
* The `poll` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
33
33
|
* necessary to optimize performance.
|