data-structure-typed 0.8.18 → 1.12.9
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/.dependency-cruiser.js +449 -0
- package/.idea/data-structure-typed.iml +2 -0
- package/.idea/modules.xml +1 -1
- package/README.md +298 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
- package/dist/data-structures/binary-tree/avl-tree.js +150 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
- package/dist/data-structures/binary-tree/binary-tree.js +747 -369
- package/dist/data-structures/binary-tree/bst.d.ts +20 -8
- package/dist/data-structures/binary-tree/bst.js +164 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
- package/dist/data-structures/binary-tree/segment-tree.js +95 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
- package/dist/data-structures/graph/abstract-graph.js +712 -323
- package/dist/data-structures/graph/directed-graph.d.ts +114 -12
- package/dist/data-structures/graph/directed-graph.js +372 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
- package/dist/data-structures/graph/undirected-graph.js +233 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
- package/dist/data-structures/hash/coordinate-map.js +70 -20
- package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
- package/dist/data-structures/hash/coordinate-set.js +58 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +26 -37
- package/dist/data-structures/heap/heap.js +56 -60
- package/dist/data-structures/heap/max-heap.d.ts +8 -2
- package/dist/data-structures/heap/max-heap.js +32 -9
- package/dist/data-structures/heap/min-heap.d.ts +9 -2
- package/dist/data-structures/heap/min-heap.js +33 -9
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
- package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
- package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
- package/dist/data-structures/matrix/matrix.d.ts +9 -0
- package/dist/data-structures/matrix/matrix.js +19 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
- package/dist/data-structures/matrix/matrix2d.js +158 -61
- package/dist/data-structures/matrix/navigator.d.ts +34 -16
- package/dist/data-structures/matrix/navigator.js +65 -18
- package/dist/data-structures/matrix/vector2d.d.ts +153 -29
- package/dist/data-structures/matrix/vector2d.js +249 -102
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
- package/dist/data-structures/priority-queue/priority-queue.js +285 -116
- package/dist/data-structures/queue/deque.d.ts +69 -0
- package/dist/data-structures/queue/deque.js +151 -56
- package/dist/data-structures/queue/queue.d.ts +34 -37
- package/dist/data-structures/queue/queue.js +59 -61
- package/dist/data-structures/stack/stack.d.ts +29 -35
- package/dist/data-structures/stack/stack.js +51 -56
- package/dist/data-structures/trie/trie.d.ts +36 -6
- package/dist/data-structures/trie/trie.js +256 -83
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/utils/trampoline.d.ts +14 -0
- package/dist/utils/trampoline.js +130 -0
- package/dist/utils/types/index.js +17 -0
- package/dist/{types → utils}/types/utils.d.ts +15 -1
- package/dist/{types → utils/types}/utils.js +21 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
- package/dist/utils/utils.js +651 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +85 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/classes/AVLTree.html +2046 -0
- package/docs/classes/AVLTreeNode.html +423 -0
- package/docs/classes/AaTree.html +117 -0
- package/docs/classes/AbstractEdge.html +198 -0
- package/docs/classes/AbstractGraph.html +891 -0
- package/docs/classes/AbstractVertex.html +164 -0
- package/docs/classes/ArrayDeque.html +384 -0
- package/docs/classes/BST.html +1893 -0
- package/docs/classes/BSTNode.html +425 -0
- package/docs/classes/BTree.html +117 -0
- package/docs/classes/BinaryIndexedTree.html +244 -0
- package/docs/classes/BinaryTree.html +1754 -0
- package/docs/classes/BinaryTreeNode.html +396 -0
- package/docs/classes/Character.html +165 -0
- package/docs/classes/CoordinateMap.html +394 -0
- package/docs/classes/CoordinateSet.html +355 -0
- package/docs/classes/Deque.html +617 -0
- package/docs/classes/DirectedEdge.html +247 -0
- package/docs/classes/DirectedGraph.html +1207 -0
- package/docs/classes/DirectedVertex.html +154 -0
- package/docs/classes/DoublyLinkedList.html +619 -0
- package/docs/classes/DoublyLinkedListNode.html +160 -0
- package/docs/classes/Heap.html +315 -0
- package/docs/classes/Matrix2D.html +447 -0
- package/docs/classes/MatrixNTI2D.html +181 -0
- package/docs/classes/MaxHeap.html +325 -0
- package/docs/classes/MaxPriorityQueue.html +668 -0
- package/docs/classes/MinHeap.html +326 -0
- package/docs/classes/MinPriorityQueue.html +668 -0
- package/docs/classes/Navigator.html +285 -0
- package/docs/classes/ObjectDeque.html +289 -0
- package/docs/classes/PriorityQueue.html +643 -0
- package/docs/classes/Queue.html +337 -0
- package/docs/classes/RBTree.html +117 -0
- package/docs/classes/SegmentTree.html +234 -0
- package/docs/classes/SegmentTreeNode.html +302 -0
- package/docs/classes/SinglyLinkedList.html +1035 -0
- package/docs/classes/SinglyLinkedListNode.html +304 -0
- package/docs/classes/SplayTree.html +117 -0
- package/docs/classes/Stack.html +313 -0
- package/docs/classes/TreeMultiSet.html +1897 -0
- package/docs/classes/Trie.html +317 -0
- package/docs/classes/TrieNode.html +221 -0
- package/docs/classes/TwoThreeTree.html +117 -0
- package/docs/classes/UndirectedEdge.html +220 -0
- package/docs/classes/UndirectedGraph.html +1006 -0
- package/docs/classes/UndirectedVertex.html +154 -0
- package/docs/classes/Vector2D.html +746 -0
- package/docs/enums/CP.html +126 -0
- package/docs/enums/FamilyPosition.html +126 -0
- package/docs/enums/LoopType.html +119 -0
- package/docs/index.html +288 -0
- package/docs/modules.html +146 -0
- package/jest.config.js +5 -0
- package/package.json +33 -47
- package/rename_clear_files.sh +29 -0
- package/src/assets/complexities-diff.jpg +0 -0
- package/src/assets/data-structure-complexities.jpg +0 -0
- package/src/data-structures/binary-tree/avl-tree.ts +58 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
- package/src/data-structures/binary-tree/binary-tree.ts +460 -145
- package/src/data-structures/binary-tree/bst.ts +31 -25
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/segment-tree.ts +25 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
- package/src/data-structures/diagrams/README.md +5 -0
- package/src/data-structures/graph/abstract-graph.ts +224 -108
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/src/data-structures/graph/directed-graph.ts +132 -26
- package/src/data-structures/graph/undirected-graph.ts +78 -11
- package/src/data-structures/hash/coordinate-map.ts +33 -1
- package/src/data-structures/hash/coordinate-set.ts +25 -0
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +27 -41
- package/src/data-structures/heap/max-heap.ts +8 -2
- package/src/data-structures/heap/min-heap.ts +9 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
- package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
- package/src/data-structures/matrix/matrix.ts +11 -0
- package/src/data-structures/matrix/matrix2d.ts +90 -10
- package/src/data-structures/matrix/navigator.ts +34 -14
- package/src/data-structures/matrix/vector2d.ts +187 -63
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
- package/src/data-structures/priority-queue/priority-queue.ts +200 -78
- package/src/data-structures/queue/deque.ts +71 -2
- package/src/data-structures/queue/queue.ts +37 -40
- package/src/data-structures/stack/stack.ts +32 -38
- package/src/data-structures/trie/trie.ts +83 -14
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +13 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +1 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/trampoline.ts +51 -0
- package/src/utils/types/index.ts +1 -0
- package/src/{types → utils/types}/utils.ts +27 -5
- package/src/{utils.ts → utils/utils.ts} +41 -131
- package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
- package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
- package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
- package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
- package/tsconfig.json +9 -6
- package/dist/data-structures/trampoline.d.ts +0 -25
- package/dist/data-structures/trampoline.js +0 -52
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/data-structures/trampoline.ts +0 -91
- package/src/types/index.ts +0 -1
- /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +0 -0
- /package/dist/{types → utils}/types/index.d.ts +0 -0
- /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
1
|
+
import * as _ from 'lodash';
|
|
2
2
|
import {AnyFunction} from './types';
|
|
3
3
|
|
|
4
4
|
export type JSONSerializable = {
|
|
@@ -21,7 +21,7 @@ export function randomText(length: number) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export const uuidV4 = function () {
|
|
24
|
-
return 'xxxxxxxx-xxxx-
|
|
24
|
+
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
|
25
25
|
const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
26
26
|
return v.toString(16);
|
|
27
27
|
});
|
|
@@ -60,25 +60,15 @@ export function incrementId(prefix?: string) {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
export const getValue = <T, K extends keyof T>(obj: T, names: K[]): Array<T[K]> =>
|
|
64
|
-
return names.map(i => obj[i]);
|
|
65
|
-
};
|
|
63
|
+
export const getValue = <T, K extends keyof T>(obj: T, names: K[]): Array<T[K]> => names.map(i => obj[i]);
|
|
66
64
|
|
|
67
|
-
export const isObject = (object: string | JSONObject | boolean | AnyFunction | number) =>
|
|
68
|
-
return object != null && typeof object === 'object';
|
|
69
|
-
};
|
|
65
|
+
export const isObject = (object: string | JSONObject | boolean | AnyFunction | number) => object != null && typeof object === 'object';
|
|
70
66
|
|
|
71
|
-
export const looseEqual = (a: any, b: any): boolean =>
|
|
72
|
-
return a == b;
|
|
73
|
-
};
|
|
67
|
+
export const looseEqual = (a: any, b: any): boolean => a == b;
|
|
74
68
|
|
|
75
|
-
export const strictEqual = (a: any, b: any): boolean =>
|
|
76
|
-
return a === b;
|
|
77
|
-
};
|
|
69
|
+
export const strictEqual = (a: any, b: any): boolean => a === b;
|
|
78
70
|
|
|
79
|
-
export const strictObjectIsEqual = (a: any, b: any): boolean =>
|
|
80
|
-
return Object.is(a, b);
|
|
81
|
-
};
|
|
71
|
+
export const strictObjectIsEqual = (a: any, b: any): boolean => Object.is(a, b);
|
|
82
72
|
|
|
83
73
|
export const deepObjectStrictEqual = (object1: JSONSerializable, object2: JSONSerializable) => {
|
|
84
74
|
const keys1 = Object.keys(object1);
|
|
@@ -100,10 +90,6 @@ export const deepObjectStrictEqual = (object1: JSONSerializable, object2: JSONSe
|
|
|
100
90
|
return true;
|
|
101
91
|
};
|
|
102
92
|
|
|
103
|
-
export const isTypeEqual = <T>(obj: unknown) => {
|
|
104
|
-
const m = obj as unknown as T;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
93
|
export function reverseColor(oldColor: string) {
|
|
108
94
|
const oldColorTemp = '0x' + oldColor.replace(/#/g, '');
|
|
109
95
|
const str = '000000' + (0xFFFFFF - Number(oldColorTemp)).toString(16);
|
|
@@ -152,48 +138,62 @@ export const addDays = (date: Date, days: number): Date => {
|
|
|
152
138
|
};
|
|
153
139
|
|
|
154
140
|
export class WaitManager {
|
|
141
|
+
private _time30 = 20000;
|
|
142
|
+
private readonly _nXSpeed: number = 1;
|
|
143
|
+
|
|
144
|
+
constructor(nXSpeed?: number) {
|
|
145
|
+
if (nXSpeed === undefined) nXSpeed = 1;
|
|
146
|
+
this._nXSpeed = nXSpeed;
|
|
147
|
+
}
|
|
148
|
+
|
|
155
149
|
private _time1 = 1000;
|
|
150
|
+
|
|
156
151
|
get time1(): number {
|
|
157
152
|
return this._time1 / this._nXSpeed;
|
|
158
153
|
}
|
|
159
154
|
|
|
160
155
|
private _time2 = 2000;
|
|
156
|
+
|
|
161
157
|
get time2(): number {
|
|
162
158
|
return this._time2 / this._nXSpeed;
|
|
163
159
|
}
|
|
164
160
|
|
|
165
161
|
private _time3 = 3000;
|
|
162
|
+
|
|
166
163
|
get time3(): number {
|
|
167
164
|
return this._time3 / this._nXSpeed;
|
|
168
165
|
}
|
|
169
166
|
|
|
170
167
|
private _time4 = 4000;
|
|
168
|
+
|
|
171
169
|
get time4(): number {
|
|
172
170
|
return this._time4 / this._nXSpeed;
|
|
173
171
|
}
|
|
174
172
|
|
|
175
173
|
private _time10 = 10000;
|
|
174
|
+
|
|
176
175
|
get time10(): number {
|
|
177
176
|
return this._time10 / this._nXSpeed;
|
|
178
177
|
}
|
|
179
178
|
|
|
180
179
|
private _time20 = 20000;
|
|
180
|
+
|
|
181
181
|
get time20(): number {
|
|
182
182
|
return this._time20 / this._nXSpeed;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
private _time30 = 20000;
|
|
186
|
-
|
|
187
185
|
get time50(): number {
|
|
188
186
|
return this._time30 / this._nXSpeed;
|
|
189
187
|
}
|
|
190
188
|
|
|
191
189
|
private _time60 = 60000;
|
|
190
|
+
|
|
192
191
|
get time60(): number {
|
|
193
192
|
return this._time60 / this._nXSpeed;
|
|
194
193
|
}
|
|
195
194
|
|
|
196
195
|
private _cusTime = 1000;
|
|
196
|
+
|
|
197
197
|
get cusTime(): number {
|
|
198
198
|
return this._cusTime / this._nXSpeed;
|
|
199
199
|
}
|
|
@@ -201,13 +201,6 @@ export class WaitManager {
|
|
|
201
201
|
set cusTime(v: number) {
|
|
202
202
|
this._cusTime = v;
|
|
203
203
|
}
|
|
204
|
-
|
|
205
|
-
private readonly _nXSpeed: number = 1;
|
|
206
|
-
|
|
207
|
-
constructor(nXSpeed?: number) {
|
|
208
|
-
if (nXSpeed === undefined) nXSpeed = 1;
|
|
209
|
-
this._nXSpeed = nXSpeed;
|
|
210
|
-
}
|
|
211
204
|
}
|
|
212
205
|
|
|
213
206
|
export const wait = async (ms: number, resolveValue?: any) => {
|
|
@@ -219,78 +212,6 @@ export const wait = async (ms: number, resolveValue?: any) => {
|
|
|
219
212
|
});
|
|
220
213
|
};
|
|
221
214
|
|
|
222
|
-
export class AuthAPIError extends Error {
|
|
223
|
-
protected serverErrorStack;
|
|
224
|
-
protected serverErrorCode;
|
|
225
|
-
|
|
226
|
-
constructor(serverErrorMessage: string, serverErrorCode?: string, serverErrorStack?: string) {
|
|
227
|
-
super(serverErrorMessage);
|
|
228
|
-
if (serverErrorStack) {
|
|
229
|
-
this.serverErrorStack = serverErrorStack;
|
|
230
|
-
}
|
|
231
|
-
if (serverErrorCode) {
|
|
232
|
-
this.serverErrorCode = serverErrorCode;
|
|
233
|
-
}
|
|
234
|
-
this.name = new.target.name;
|
|
235
|
-
if (typeof (Error as any).captureStackTrace === 'function') {
|
|
236
|
-
(Error as any).captureStackTrace(this, new.target);
|
|
237
|
-
}
|
|
238
|
-
if (typeof Object.setPrototypeOf === 'function') {
|
|
239
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
240
|
-
} else {
|
|
241
|
-
(this as any).__proto__ = new.target.prototype;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export class BunnyAPIError extends Error {
|
|
247
|
-
protected serverErrorStack;
|
|
248
|
-
protected serverErrorCode;
|
|
249
|
-
|
|
250
|
-
constructor(serverErrorMessage: string, serverErrorCode?: string, serverErrorStack?: string) {
|
|
251
|
-
super(serverErrorMessage);
|
|
252
|
-
if (serverErrorStack) {
|
|
253
|
-
this.serverErrorStack = serverErrorStack;
|
|
254
|
-
}
|
|
255
|
-
if (serverErrorCode) {
|
|
256
|
-
this.serverErrorCode = serverErrorCode;
|
|
257
|
-
}
|
|
258
|
-
this.name = new.target.name;
|
|
259
|
-
if (typeof (Error as any).captureStackTrace === 'function') {
|
|
260
|
-
(Error as any).captureStackTrace(this, new.target);
|
|
261
|
-
}
|
|
262
|
-
if (typeof Object.setPrototypeOf === 'function') {
|
|
263
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
264
|
-
} else {
|
|
265
|
-
(this as any).__proto__ = new.target.prototype;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export class NomicsAPIError extends Error {
|
|
271
|
-
protected serverErrorStack;
|
|
272
|
-
protected serverErrorCode;
|
|
273
|
-
|
|
274
|
-
constructor(serverErrorMessage: string, serverErrorCode?: string, serverErrorStack?: string) {
|
|
275
|
-
super(serverErrorMessage);
|
|
276
|
-
if (serverErrorStack) {
|
|
277
|
-
this.serverErrorStack = serverErrorStack;
|
|
278
|
-
}
|
|
279
|
-
if (serverErrorCode) {
|
|
280
|
-
this.serverErrorCode = serverErrorCode;
|
|
281
|
-
}
|
|
282
|
-
this.name = new.target.name;
|
|
283
|
-
if (typeof (Error as any).captureStackTrace === 'function') {
|
|
284
|
-
(Error as any).captureStackTrace(this, new.target);
|
|
285
|
-
}
|
|
286
|
-
if (typeof Object.setPrototypeOf === 'function') {
|
|
287
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
288
|
-
} else {
|
|
289
|
-
(this as any).__proto__ = new.target.prototype;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
215
|
export function extractValue<Item>(data: { key: string, value: Item }[]) {
|
|
295
216
|
let result: Item[] = [];
|
|
296
217
|
if (data && data.length > 0) {
|
|
@@ -328,14 +249,9 @@ export function randomDate(start?: Date, end?: Date, specificProbabilityStart?:
|
|
|
328
249
|
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
|
|
329
250
|
}
|
|
330
251
|
|
|
252
|
+
export const capitalizeWords = (str: string) => str.replace(/(?:^|\s)\S/g, (a: string) => a.toUpperCase());
|
|
331
253
|
|
|
332
|
-
export const
|
|
333
|
-
return str.replace(/(?:^|\s)\S/g, (a: string) => a.toUpperCase());
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
export const capitalizeFirstLetter = (str: string) => {
|
|
337
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
338
|
-
};
|
|
254
|
+
export const capitalizeFirstLetter = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
339
255
|
|
|
340
256
|
export const comparerArray = <T>(otherArray: T[], limitKeys?: string[]) => {
|
|
341
257
|
return function (current: T) {
|
|
@@ -349,17 +265,11 @@ export const comparerArray = <T>(otherArray: T[], limitKeys?: string[]) => {
|
|
|
349
265
|
};
|
|
350
266
|
};
|
|
351
267
|
|
|
352
|
-
export const onlyInA = <T>(a: T[], b: T[]) =>
|
|
353
|
-
return a.filter(comparerArray(b));
|
|
354
|
-
};
|
|
268
|
+
export const onlyInA = <T>(a: T[], b: T[]) => a.filter(comparerArray(b));
|
|
355
269
|
|
|
356
|
-
export const onlyInB = <T>(a: T[], b: T[]) =>
|
|
357
|
-
return b.filter(comparerArray(a));
|
|
358
|
-
};
|
|
270
|
+
export const onlyInB = <T>(a: T[], b: T[]) => b.filter(comparerArray(a));
|
|
359
271
|
|
|
360
|
-
export const diffAB = <T>(a: T[], b: T[]) =>
|
|
361
|
-
return onlyInA(a, b).concat(onlyInB(a, b));
|
|
362
|
-
};
|
|
272
|
+
export const diffAB = <T>(a: T[], b: T[]) => onlyInA(a, b).concat(onlyInB(a, b));
|
|
363
273
|
|
|
364
274
|
export class StringUtil {
|
|
365
275
|
// camelCase
|
|
@@ -413,8 +323,18 @@ export class StringUtil {
|
|
|
413
323
|
}
|
|
414
324
|
}
|
|
415
325
|
|
|
416
|
-
type
|
|
417
|
-
|
|
326
|
+
export type CaseType =
|
|
327
|
+
'camel'
|
|
328
|
+
| 'snake'
|
|
329
|
+
| 'pascal'
|
|
330
|
+
| 'constant'
|
|
331
|
+
| 'kebab'
|
|
332
|
+
| 'lower'
|
|
333
|
+
| 'title'
|
|
334
|
+
| 'sentence'
|
|
335
|
+
| 'path'
|
|
336
|
+
| 'dot';
|
|
337
|
+
export const deepKeysConvert = (obj: any, toType?: CaseType): any => {
|
|
418
338
|
const _toType = toType || 'snake';
|
|
419
339
|
if (Array.isArray(obj)) {
|
|
420
340
|
return obj.map(v => deepKeysConvert(v, _toType));
|
|
@@ -501,13 +421,6 @@ export const deepReplaceValues = (obj: JSONSerializable, keyReducerMap: { [key i
|
|
|
501
421
|
return newObject;
|
|
502
422
|
};
|
|
503
423
|
|
|
504
|
-
// function getCallStackSize() {
|
|
505
|
-
// let count = 0, fn = arguments.callee;
|
|
506
|
-
// while ( (fn = fn.caller) ) {
|
|
507
|
-
// count++;
|
|
508
|
-
// }
|
|
509
|
-
// return count;
|
|
510
|
-
// }
|
|
511
424
|
// TODO determine depth and pass root node as a param through callback
|
|
512
425
|
export const deepAdd = (obj: JSONSerializable, keyReducerMap: { [key in string]: (item: JSONSerializable) => any }, isItemRootParent?: boolean) => {
|
|
513
426
|
const newObject = _.clone(obj) as JSONObject | [];
|
|
@@ -529,7 +442,6 @@ export const deepAdd = (obj: JSONSerializable, keyReducerMap: { [key in string]:
|
|
|
529
442
|
|
|
530
443
|
const styleString = (color: string) => `color: ${color}; font-weight: bold`;
|
|
531
444
|
|
|
532
|
-
|
|
533
445
|
const styleHeader = (header: string) => `%c[${header}]`;
|
|
534
446
|
|
|
535
447
|
export const bunnyConsole = {
|
|
@@ -544,7 +456,6 @@ export const bunnyConsole = {
|
|
|
544
456
|
}
|
|
545
457
|
};
|
|
546
458
|
|
|
547
|
-
|
|
548
459
|
export const timeStart = () => {
|
|
549
460
|
return performance ? performance.now() : new Date().getTime();
|
|
550
461
|
};
|
|
@@ -601,5 +512,4 @@ export function zip<T = number, T1 = number>(array1: T[], array2: T1[], options?
|
|
|
601
512
|
}
|
|
602
513
|
}
|
|
603
514
|
return isToObj ? zippedObjCoords : zipped;
|
|
604
|
-
}
|
|
605
|
-
|
|
515
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import {BST, BSTNode} from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('bst-case6', () => {
|
|
4
|
+
it('should perform various operations on a Binary Search Tree', () => {
|
|
5
|
+
const arr = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
6
|
+
|
|
7
|
+
const tree = new BST();
|
|
8
|
+
|
|
9
|
+
expect(tree).toBeInstanceOf(BST);
|
|
10
|
+
|
|
11
|
+
for (const i of arr) tree.put(i, i);
|
|
12
|
+
|
|
13
|
+
expect(tree.root).toBeInstanceOf(BSTNode);
|
|
14
|
+
if (tree.root) expect(tree.root.id).toBe(11);
|
|
15
|
+
expect(tree.count).toBe(16);
|
|
16
|
+
expect(tree.has(6)).toBe(true);
|
|
17
|
+
|
|
18
|
+
const node6 = tree.get(6);
|
|
19
|
+
expect(node6 && tree.getHeight(node6)).toBe(2);
|
|
20
|
+
expect(node6 && tree.getDepth(node6)).toBe(3);
|
|
21
|
+
const getNodeById = tree.get(10, 'id');
|
|
22
|
+
expect(getNodeById?.id).toBe(10);
|
|
23
|
+
|
|
24
|
+
const getNodesByCount = tree.getNodes(1, 'count');
|
|
25
|
+
expect(getNodesByCount.length).toBe(16);
|
|
26
|
+
|
|
27
|
+
const getMinNodeByRoot = tree.getLeftMost();
|
|
28
|
+
expect(getMinNodeByRoot?.id).toBe(1);
|
|
29
|
+
|
|
30
|
+
const node15 = tree.get(15);
|
|
31
|
+
const getMinNodeBySpecificNode = node15 && tree.getLeftMost(node15);
|
|
32
|
+
expect(getMinNodeBySpecificNode?.id).toBe(12);
|
|
33
|
+
|
|
34
|
+
const subTreeSum = node15 && tree.subTreeSum(node15);
|
|
35
|
+
expect(subTreeSum).toBe(70);
|
|
36
|
+
|
|
37
|
+
const lesserSum = tree.lesserSum(10);
|
|
38
|
+
expect(lesserSum).toBe(45);
|
|
39
|
+
|
|
40
|
+
expect(node15).toBeInstanceOf(BSTNode);
|
|
41
|
+
if (node15 instanceof BSTNode) {
|
|
42
|
+
const subTreeAdd = tree.subTreeAdd(node15, 1, 'count');
|
|
43
|
+
expect(subTreeAdd).toBeDefined();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
const node11 = tree.get(11);
|
|
48
|
+
expect(node11).toBeInstanceOf(BSTNode);
|
|
49
|
+
if (node11 instanceof BSTNode) {
|
|
50
|
+
const allGreaterNodesAdd = tree.allGreaterNodesAdd(node11, 2, 'count');
|
|
51
|
+
expect(allGreaterNodesAdd).toBeDefined();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const dfs = tree.DFS('in', 'node');
|
|
55
|
+
expect(dfs[0].id).toBe(1);
|
|
56
|
+
expect(dfs[dfs.length - 1].id).toBe(16);
|
|
57
|
+
|
|
58
|
+
tree.balance();
|
|
59
|
+
const bfs = tree.BFS('node');
|
|
60
|
+
expect(tree.isBalanced()).toBe(true);
|
|
61
|
+
expect(bfs[0].id).toBe(8);
|
|
62
|
+
expect(bfs[bfs.length - 1].id).toBe(16);
|
|
63
|
+
|
|
64
|
+
const removed11 = tree.remove(11, true);
|
|
65
|
+
expect(removed11).toBeInstanceOf(Array);
|
|
66
|
+
expect(removed11[0]).toBeDefined();
|
|
67
|
+
expect(removed11[0].deleted).toBeDefined();
|
|
68
|
+
if (removed11[0].deleted) expect(removed11[0].deleted.id).toBe(11);
|
|
69
|
+
expect(tree.isAVLBalanced()).toBe(true);
|
|
70
|
+
expect(node15 && tree.getHeight(node15)).toBe(2);
|
|
71
|
+
|
|
72
|
+
const removed1 = tree.remove(1, true);
|
|
73
|
+
expect(removed1).toBeInstanceOf(Array);
|
|
74
|
+
expect(removed1[0]).toBeDefined();
|
|
75
|
+
expect(removed1[0].deleted).toBeDefined();
|
|
76
|
+
if (removed1[0].deleted) expect(removed1[0].deleted.id).toBe(1);
|
|
77
|
+
|
|
78
|
+
expect(tree.isAVLBalanced()).toBe(true);
|
|
79
|
+
expect(tree.getHeight()).toBe(4);
|
|
80
|
+
|
|
81
|
+
const removed4 = tree.remove(4, true);
|
|
82
|
+
expect(removed4).toBeInstanceOf(Array);
|
|
83
|
+
expect(removed4[0]).toBeDefined();
|
|
84
|
+
expect(removed4[0].deleted).toBeDefined();
|
|
85
|
+
if (removed4[0].deleted) expect(removed4[0].deleted.id).toBe(4);
|
|
86
|
+
expect(tree.isAVLBalanced()).toBe(true);
|
|
87
|
+
expect(tree.getHeight()).toBe(4);
|
|
88
|
+
|
|
89
|
+
const removed10 = tree.remove(10, true);
|
|
90
|
+
expect(removed10).toBeInstanceOf(Array);
|
|
91
|
+
expect(removed10[0]).toBeDefined();
|
|
92
|
+
expect(removed10[0].deleted).toBeDefined();
|
|
93
|
+
if (removed10[0].deleted) expect(removed10[0].deleted.id).toBe(10);
|
|
94
|
+
expect(tree.isAVLBalanced()).toBe(false);
|
|
95
|
+
expect(tree.getHeight()).toBe(4);
|
|
96
|
+
|
|
97
|
+
const removed15 = tree.remove(15, true);
|
|
98
|
+
expect(removed15).toBeInstanceOf(Array);
|
|
99
|
+
expect(removed15[0]).toBeDefined();
|
|
100
|
+
expect(removed15[0].deleted).toBeDefined();
|
|
101
|
+
if (removed15[0].deleted) expect(removed15[0].deleted.id).toBe(15);
|
|
102
|
+
|
|
103
|
+
expect(tree.isAVLBalanced()).toBe(true);
|
|
104
|
+
expect(tree.getHeight()).toBe(3);
|
|
105
|
+
|
|
106
|
+
const removed5 = tree.remove(5, true);
|
|
107
|
+
expect(removed5).toBeInstanceOf(Array);
|
|
108
|
+
expect(removed5[0]).toBeDefined();
|
|
109
|
+
expect(removed5[0].deleted).toBeDefined();
|
|
110
|
+
if (removed5[0].deleted) expect(removed5[0].deleted.id).toBe(5);
|
|
111
|
+
|
|
112
|
+
expect(tree.isAVLBalanced()).toBe(true);
|
|
113
|
+
expect(tree.getHeight()).toBe(3);
|
|
114
|
+
|
|
115
|
+
const removed13 = tree.remove(13, true);
|
|
116
|
+
expect(removed13).toBeInstanceOf(Array);
|
|
117
|
+
expect(removed13[0]).toBeDefined();
|
|
118
|
+
expect(removed13[0].deleted).toBeDefined();
|
|
119
|
+
if (removed13[0].deleted) expect(removed13[0].deleted.id).toBe(13);
|
|
120
|
+
expect(tree.isAVLBalanced()).toBe(true);
|
|
121
|
+
expect(tree.getHeight()).toBe(3);
|
|
122
|
+
|
|
123
|
+
const removed3 = tree.remove(3, true);
|
|
124
|
+
expect(removed3).toBeInstanceOf(Array);
|
|
125
|
+
expect(removed3[0]).toBeDefined();
|
|
126
|
+
expect(removed3[0].deleted).toBeDefined();
|
|
127
|
+
if (removed3[0].deleted) expect(removed3[0].deleted.id).toBe(3);
|
|
128
|
+
expect(tree.isAVLBalanced()).toBe(false);
|
|
129
|
+
expect(tree.getHeight()).toBe(3);
|
|
130
|
+
|
|
131
|
+
const removed8 = tree.remove(8, true);
|
|
132
|
+
expect(removed8).toBeInstanceOf(Array);
|
|
133
|
+
expect(removed8[0]).toBeDefined();
|
|
134
|
+
expect(removed8[0].deleted).toBeDefined();
|
|
135
|
+
if (removed8[0].deleted) expect(removed8[0].deleted.id).toBe(8);
|
|
136
|
+
expect(tree.isAVLBalanced()).toBe(true);
|
|
137
|
+
expect(tree.getHeight()).toBe(3);
|
|
138
|
+
|
|
139
|
+
const removed6 = tree.remove(6, true);
|
|
140
|
+
expect(removed6).toBeInstanceOf(Array);
|
|
141
|
+
expect(removed6[0]).toBeDefined();
|
|
142
|
+
expect(removed6[0].deleted).toBeDefined();
|
|
143
|
+
if (removed6[0].deleted) expect(removed6[0].deleted.id).toBe(6);
|
|
144
|
+
expect(tree.remove(6, true).length).toBe(0);
|
|
145
|
+
expect(tree.isAVLBalanced()).toBe(false);
|
|
146
|
+
expect(tree.getHeight()).toBe(3);
|
|
147
|
+
|
|
148
|
+
const removed7 = tree.remove(7, true);
|
|
149
|
+
expect(removed7).toBeInstanceOf(Array);
|
|
150
|
+
expect(removed7[0]).toBeDefined();
|
|
151
|
+
expect(removed7[0].deleted).toBeDefined();
|
|
152
|
+
if (removed7[0].deleted) expect(removed7[0].deleted.id).toBe(7);
|
|
153
|
+
expect(tree.isAVLBalanced()).toBe(false);
|
|
154
|
+
expect(tree.getHeight()).toBe(3);
|
|
155
|
+
|
|
156
|
+
const removed9 = tree.remove(9, true);
|
|
157
|
+
expect(removed9).toBeInstanceOf(Array);
|
|
158
|
+
expect(removed9[0]).toBeDefined();
|
|
159
|
+
expect(removed9[0].deleted).toBeDefined();
|
|
160
|
+
if (removed9[0].deleted) expect(removed9[0].deleted.id).toBe(9);
|
|
161
|
+
expect(tree.isAVLBalanced()).toBe(false);
|
|
162
|
+
expect(tree.getHeight()).toBe(3);
|
|
163
|
+
|
|
164
|
+
const removed14 = tree.remove(14, true);
|
|
165
|
+
expect(removed14).toBeInstanceOf(Array);
|
|
166
|
+
expect(removed14[0]).toBeDefined();
|
|
167
|
+
expect(removed14[0].deleted).toBeDefined();
|
|
168
|
+
if (removed14[0].deleted) expect(removed14[0].deleted.id).toBe(14);
|
|
169
|
+
expect(tree.isAVLBalanced()).toBe(false);
|
|
170
|
+
expect(tree.getHeight()).toBe(2);
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
expect(!tree.isAVLBalanced()).toBe(true);
|
|
174
|
+
|
|
175
|
+
const lastBFSIds = tree.BFS();
|
|
176
|
+
expect(lastBFSIds[0]).toBe(2);
|
|
177
|
+
expect(lastBFSIds[1]).toBe(12);
|
|
178
|
+
expect(lastBFSIds[2]).toBe(16);
|
|
179
|
+
|
|
180
|
+
const lastBFSNodes = tree.BFS('node');
|
|
181
|
+
expect(lastBFSNodes[0].id).toBe(2);
|
|
182
|
+
expect(lastBFSNodes[1].id).toBe(12);
|
|
183
|
+
expect(lastBFSNodes[2].id).toBe(16);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { DirectedGraph, DirectedVertex, DirectedEdge } from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('DirectedGraph', () => {
|
|
4
|
+
let graph: DirectedGraph<DirectedVertex, DirectedEdge>;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
graph = new DirectedGraph();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should add vertices', () => {
|
|
11
|
+
const vertex1 = new DirectedVertex('A');
|
|
12
|
+
const vertex2 = new DirectedVertex('B');
|
|
13
|
+
|
|
14
|
+
graph.addVertex(vertex1);
|
|
15
|
+
graph.addVertex(vertex2);
|
|
16
|
+
|
|
17
|
+
expect(graph.containsVertex(vertex1)).toBe(true);
|
|
18
|
+
expect(graph.containsVertex(vertex2)).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should add edges', () => {
|
|
22
|
+
const vertex1 = new DirectedVertex('A');
|
|
23
|
+
const vertex2 = new DirectedVertex('B');
|
|
24
|
+
const edge = new DirectedEdge('A', 'B');
|
|
25
|
+
|
|
26
|
+
graph.addVertex(vertex1);
|
|
27
|
+
graph.addVertex(vertex2);
|
|
28
|
+
graph.addEdge(edge);
|
|
29
|
+
|
|
30
|
+
expect(graph.containsEdge('A', 'B')).toBe(true);
|
|
31
|
+
expect(graph.containsEdge('B', 'A')).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should remove edges', () => {
|
|
35
|
+
const vertex1 = new DirectedVertex('A');
|
|
36
|
+
const vertex2 = new DirectedVertex('B');
|
|
37
|
+
const edge = new DirectedEdge('A', 'B');
|
|
38
|
+
|
|
39
|
+
graph.addVertex(vertex1);
|
|
40
|
+
graph.addVertex(vertex2);
|
|
41
|
+
graph.addEdge(edge);
|
|
42
|
+
|
|
43
|
+
expect(graph.removeEdge(edge)).toBe(edge);
|
|
44
|
+
expect(graph.containsEdge('A', 'B')).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Add more test cases for other methods...
|
|
48
|
+
|
|
49
|
+
it('should perform topological sort', () => {
|
|
50
|
+
// Create a graph with vertices and edges
|
|
51
|
+
const vertexA = new DirectedVertex('A');
|
|
52
|
+
const vertexB = new DirectedVertex('B');
|
|
53
|
+
const vertexC = new DirectedVertex('C');
|
|
54
|
+
const edgeAB = new DirectedEdge('A', 'B');
|
|
55
|
+
const edgeBC = new DirectedEdge('B', 'C');
|
|
56
|
+
|
|
57
|
+
graph.addVertex(vertexA);
|
|
58
|
+
graph.addVertex(vertexB);
|
|
59
|
+
graph.addVertex(vertexC);
|
|
60
|
+
graph.addEdge(edgeAB);
|
|
61
|
+
graph.addEdge(edgeBC);
|
|
62
|
+
|
|
63
|
+
// Perform topological sort
|
|
64
|
+
const topologicalOrder = graph.topologicalSort();
|
|
65
|
+
|
|
66
|
+
if (topologicalOrder) expect(topologicalOrder.map(v => v.id)).toEqual(['A', 'B', 'C']);
|
|
67
|
+
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Add more test cases for other methods...
|
|
71
|
+
});
|
|
File without changes
|
package/tsconfig.json
CHANGED
|
@@ -3,18 +3,17 @@
|
|
|
3
3
|
"declaration": true,
|
|
4
4
|
"outDir": "./dist",
|
|
5
5
|
"module": "commonjs",
|
|
6
|
-
"target": "
|
|
6
|
+
"target": "es5",
|
|
7
7
|
"lib": [
|
|
8
|
-
"
|
|
9
|
-
"dom",
|
|
10
|
-
"dom.iterable",
|
|
8
|
+
// "es2015",
|
|
11
9
|
"esnext"
|
|
12
10
|
],
|
|
13
11
|
"strict": true,
|
|
14
12
|
"esModuleInterop": true,
|
|
15
13
|
"moduleResolution": "node",
|
|
16
14
|
"declarationDir": "./dist",
|
|
17
|
-
"skipLibCheck": true
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"downlevelIteration": true,
|
|
18
17
|
|
|
19
18
|
// "allowJs": true,
|
|
20
19
|
// "allowSyntheticDefaultImports": true,
|
|
@@ -23,12 +22,16 @@
|
|
|
23
22
|
// "resolveJsonModule": true,
|
|
24
23
|
// "isolatedModules": true,
|
|
25
24
|
// "noEmit": true,
|
|
25
|
+
"typeRoots": [
|
|
26
|
+
"node_modules/@types"
|
|
27
|
+
]
|
|
26
28
|
},
|
|
29
|
+
|
|
27
30
|
"include": [
|
|
28
31
|
"src",
|
|
29
|
-
"node_modules/data-structure-typed"
|
|
30
32
|
],
|
|
31
33
|
"exclude": [
|
|
34
|
+
// "node_modules/data-structure-typed",
|
|
32
35
|
"node_modules",
|
|
33
36
|
"dist"
|
|
34
37
|
]
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export type ArgumentTypes<T extends (...args: any[]) => any> = T extends (...args: infer A) => any ? A : never;
|
|
2
|
-
export declare const THUNK_SYMBOL: unique symbol;
|
|
3
|
-
export interface Thunk<T> extends Function {
|
|
4
|
-
__THUNK__: typeof THUNK_SYMBOL;
|
|
5
|
-
(): T;
|
|
6
|
-
}
|
|
7
|
-
export type ThunkOrValue<T> = T | Thunk<T>;
|
|
8
|
-
export type UnwrapThunkDeep<T> = {
|
|
9
|
-
0: T extends Thunk<infer U> ? UnwrapThunkDeep<U> : T;
|
|
10
|
-
}[T extends ThunkOrValue<T> ? 0 : never];
|
|
11
|
-
export declare const isThunk: <T>(value: any) => value is Thunk<T>;
|
|
12
|
-
export declare const toThunk: <R>(fn: () => R) => Thunk<R>;
|
|
13
|
-
export type UnwrapPromise<T> = T extends Promise<infer U> ? Exclude<U, Promise<T>> : T;
|
|
14
|
-
export type Unbox<T> = UnwrapThunkDeep<UnwrapPromise<T>>;
|
|
15
|
-
export type Cont<A extends any[], R> = (...args: A) => Thunk<Unbox<R>>;
|
|
16
|
-
export interface Trampoline<F extends ((...args: any[]) => any)> {
|
|
17
|
-
(...args: ArgumentTypes<F>): Unbox<ReturnType<F>>;
|
|
18
|
-
cont: Cont<ArgumentTypes<F>, ReturnType<F>>;
|
|
19
|
-
}
|
|
20
|
-
export interface TrampolineAsync<F extends ((...args: any[]) => any)> {
|
|
21
|
-
(...args: ArgumentTypes<F>): Promise<Unbox<ReturnType<F>>>;
|
|
22
|
-
cont: Cont<ArgumentTypes<F>, ReturnType<F>>;
|
|
23
|
-
}
|
|
24
|
-
export declare const trampoline: <F extends (...args: any[]) => any>(fn: F) => Trampoline<F>;
|
|
25
|
-
export declare const trampolineAsync: <F extends (...args: any[]) => any>(fn: F) => TrampolineAsync<F>;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = void 0;
|
|
13
|
-
exports.THUNK_SYMBOL = Symbol('thunk');
|
|
14
|
-
const isThunk = (value) => {
|
|
15
|
-
return typeof value === 'function' && value.__THUNK__ === exports.THUNK_SYMBOL;
|
|
16
|
-
};
|
|
17
|
-
exports.isThunk = isThunk;
|
|
18
|
-
const toThunk = (fn) => {
|
|
19
|
-
const thunk = () => fn();
|
|
20
|
-
thunk.__THUNK__ = exports.THUNK_SYMBOL;
|
|
21
|
-
return thunk;
|
|
22
|
-
};
|
|
23
|
-
exports.toThunk = toThunk;
|
|
24
|
-
const trampoline = (fn) => {
|
|
25
|
-
const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
|
|
26
|
-
return Object.assign((...args) => {
|
|
27
|
-
let result = fn(...args);
|
|
28
|
-
while ((0, exports.isThunk)(result)) {
|
|
29
|
-
result = result();
|
|
30
|
-
}
|
|
31
|
-
return result;
|
|
32
|
-
}, { cont });
|
|
33
|
-
};
|
|
34
|
-
exports.trampoline = trampoline;
|
|
35
|
-
const trampolineAsync = (fn) => {
|
|
36
|
-
const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
|
|
37
|
-
return Object.assign((...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
-
let result = yield fn(...args);
|
|
39
|
-
while ((0, exports.isThunk)(result)) {
|
|
40
|
-
result = yield result();
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}), { cont });
|
|
44
|
-
};
|
|
45
|
-
exports.trampolineAsync = trampolineAsync;
|
|
46
|
-
const factorial = (0, exports.trampoline)((n, acc = 1) => {
|
|
47
|
-
return n
|
|
48
|
-
// Note: calling factorial.cont instead of factorial directly
|
|
49
|
-
? factorial.cont(n - 1, acc * n)
|
|
50
|
-
: acc;
|
|
51
|
-
});
|
|
52
|
-
// factorial(32768)
|