data-structure-typed 1.45.0 → 1.45.2
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/.eslintrc.js +6 -6
- package/CHANGELOG.md +1 -1
- package/COMMANDS.md +6 -1
- package/README.md +18 -15
- package/benchmark/report.html +18 -15
- package/benchmark/report.json +157 -116
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- 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-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +58 -58
- package/dist/cjs/data-structures/hash/hash-map.js +73 -73
- 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.js +21 -12
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.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.js.map +1 -1
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- 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/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +58 -58
- package/dist/mjs/data-structures/hash/hash-map.js +76 -76
- package/dist/mjs/data-structures/heap/heap.js +21 -12
- package/dist/umd/data-structure-typed.js +83 -83
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +7 -7
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -3
- package/src/data-structures/binary-tree/binary-tree.ts +39 -31
- package/src/data-structures/binary-tree/bst.ts +12 -8
- package/src/data-structures/binary-tree/rb-tree.ts +17 -6
- package/src/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/data-structures/binary-tree/tree-multimap.ts +12 -9
- package/src/data-structures/graph/abstract-graph.ts +46 -31
- package/src/data-structures/graph/directed-graph.ts +10 -5
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +9 -9
- package/src/data-structures/hash/hash-map.ts +103 -103
- package/src/data-structures/hash/hash-table.ts +1 -1
- package/src/data-structures/hash/tree-map.ts +2 -1
- package/src/data-structures/hash/tree-set.ts +2 -1
- package/src/data-structures/heap/heap.ts +30 -17
- package/src/data-structures/heap/max-heap.ts +3 -3
- package/src/data-structures/heap/min-heap.ts +3 -3
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/matrix2d.ts +1 -1
- package/src/data-structures/matrix/navigator.ts +3 -3
- package/src/data-structures/matrix/vector2d.ts +2 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -3
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/queue/deque.ts +5 -4
- package/src/data-structures/queue/queue.ts +2 -2
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +1 -1
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/interfaces/graph.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +2 -2
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/tree-multimap.ts +2 -2
- package/src/types/data-structures/hash/hash-map.ts +6 -6
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +18 -4
- package/src/utils/utils.ts +6 -6
- package/test/integration/all-in-one.ts +1 -1
- package/test/integration/avl-tree.test.ts +1 -1
- package/test/integration/bst.test.ts +19 -19
- package/test/integration/heap.test.js +1 -1
- package/test/integration/index.html +7 -7
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/binary-tree.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/bst.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +9 -9
- package/test/performance/data-structures/comparation.test.ts +142 -0
- package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/performance/data-structures/hash/hash-map.test.ts +8 -8
- package/test/performance/data-structures/heap/heap.test.ts +5 -5
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +7 -7
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -4
- package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +7 -5
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +8 -8
- package/test/performance/data-structures/queue/deque.test.ts +6 -6
- package/test/performance/data-structures/queue/queue.test.ts +7 -7
- package/test/performance/data-structures/stack/stack.test.ts +8 -8
- package/test/performance/data-structures/trie/trie.test.ts +4 -4
- package/test/performance/reportor.ts +48 -20
- package/test/performance/types/reportor.ts +1 -1
- package/test/types/utils/json2html.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +12 -12
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -76
- package/test/unit/data-structures/binary-tree/bst.test.ts +44 -40
- package/test/unit/data-structures/binary-tree/overall.test.ts +17 -17
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +9 -9
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +35 -35
- package/test/unit/data-structures/graph/abstract-graph.test.ts +7 -7
- package/test/unit/data-structures/graph/directed-graph.test.ts +34 -14
- package/test/unit/data-structures/graph/map-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/overall.test.ts +1 -1
- package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
- package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
- package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
- package/test/unit/data-structures/hash/hash-map.test.ts +10 -12
- package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
- package/test/unit/data-structures/heap/heap.test.ts +73 -23
- package/test/unit/data-structures/heap/max-heap.test.ts +2 -2
- package/test/unit/data-structures/heap/min-heap.test.ts +2 -2
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +5 -5
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +5 -5
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/matrix/matrix.test.ts +5 -5
- package/test/unit/data-structures/matrix/matrix2d.test.ts +3 -3
- package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
- package/test/unit/data-structures/matrix/vector2d.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +7 -7
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +19 -19
- package/test/unit/data-structures/queue/deque.test.ts +3 -3
- package/test/unit/data-structures/queue/queue.test.ts +3 -3
- package/test/unit/data-structures/stack/stack.test.ts +1 -1
- package/test/unit/data-structures/tree/tree.test.ts +1 -1
- package/test/unit/data-structures/trie/trie.test.ts +1 -1
- package/test/utils/array.ts +1 -1
- package/test/utils/big-o.ts +4 -4
- package/test/utils/index.ts +1 -0
- package/test/utils/json2html.ts +7 -3
- package/test/utils/performanc.ts +7 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
4
|
* @class
|
|
5
5
|
*/
|
|
6
|
-
import {SinglyLinkedList} from '../linked-list';
|
|
6
|
+
import { SinglyLinkedList } from '../linked-list';
|
|
7
7
|
|
|
8
8
|
export class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
9
9
|
/**
|
|
@@ -300,7 +300,7 @@ export class Queue<E = any> {
|
|
|
300
300
|
return new Queue(this.nodes.slice(this.offset));
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
-
*[Symbol.iterator]() {
|
|
303
|
+
* [Symbol.iterator]() {
|
|
304
304
|
for (const item of this.nodes) {
|
|
305
305
|
yield item;
|
|
306
306
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {BinaryTreeNode} from '../data-structures';
|
|
2
|
-
import {BinaryTreeNodeNested, BiTreeDeleteResult, BTNCallback, BTNKey} from '../types';
|
|
1
|
+
import { BinaryTreeNode } from '../data-structures';
|
|
2
|
+
import { BinaryTreeNodeNested, BiTreeDeleteResult, BTNCallback, BTNKey } from '../types';
|
|
3
3
|
|
|
4
4
|
export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
|
|
5
5
|
createNode(key: BTNKey, value?: N['value']): N;
|
package/src/interfaces/graph.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {AVLTreeNode} from '../../../data-structures';
|
|
2
|
-
import {BSTOptions} from './bst';
|
|
1
|
+
import { AVLTreeNode } from '../../../data-structures';
|
|
2
|
+
import { BSTOptions } from './bst';
|
|
3
3
|
|
|
4
4
|
export type AVLTreeNodeNested<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
5
5
|
export type AVLTreeOptions = BSTOptions & {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {BSTNode} from '../../../data-structures';
|
|
2
|
-
import type {BinaryTreeOptions, BTNKey} from './binary-tree';
|
|
1
|
+
import { BSTNode } from '../../../data-structures';
|
|
2
|
+
import type { BinaryTreeOptions, BTNKey } from './binary-tree';
|
|
3
3
|
|
|
4
4
|
export type BSTComparator = (a: BTNKey, b: BTNKey) => number;
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {TreeMultimapNode} from '../../../data-structures';
|
|
2
|
-
import {AVLTreeOptions} from './avl-tree';
|
|
1
|
+
import { TreeMultimapNode } from '../../../data-structures';
|
|
2
|
+
import { AVLTreeOptions } from './avl-tree';
|
|
3
3
|
|
|
4
4
|
export type TreeMultimapNodeNested<T> = TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
5
5
|
|
|
@@ -7,11 +7,11 @@ export type HashMapOptions<T> = {
|
|
|
7
7
|
sizeFunction?: number | (() => number);
|
|
8
8
|
fixedLength?: number;
|
|
9
9
|
forEach: (callback: (el: T) => void) => void;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
|
|
12
12
|
export type HashMapLinkedNode<K, V> = {
|
|
13
|
-
key: K
|
|
14
|
-
value: V
|
|
15
|
-
next: HashMapLinkedNode<K, V
|
|
16
|
-
prev: HashMapLinkedNode<K, V
|
|
17
|
-
}
|
|
13
|
+
key: K;
|
|
14
|
+
value: V;
|
|
15
|
+
next: HashMapLinkedNode<K, V>;
|
|
16
|
+
prev: HashMapLinkedNode<K, V>;
|
|
17
|
+
};
|
package/src/types/utils/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type ToThunkFn = () => ReturnType<TrlFn>;
|
|
2
|
-
export type Thunk = () => ReturnType<ToThunkFn> & {__THUNK__: symbol};
|
|
2
|
+
export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: symbol };
|
|
3
3
|
export type TrlFn = (...args: any[]) => any;
|
|
4
4
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type KeyValueObject = {[key: string]: any};
|
|
1
|
+
export type KeyValueObject = { [key: string]: any };
|
|
2
2
|
|
|
3
|
-
export type KeyValueObjectWithKey = {[key: string]: any; key: string | number | symbol};
|
|
3
|
+
export type KeyValueObjectWithKey = { [key: string]: any; key: string | number | symbol };
|
|
4
4
|
|
|
5
5
|
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
6
6
|
|
|
@@ -16,6 +16,20 @@ export type ObjectWithNumberKey = {
|
|
|
16
16
|
key: number;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export type RestrictValByKey =
|
|
19
|
+
export type RestrictValByKey =
|
|
20
|
+
| NonNumberNonObjectButDefined
|
|
21
|
+
| ObjectWithoutKey
|
|
22
|
+
| ObjectWithNonNumberKey
|
|
23
|
+
| ObjectWithNumberKey;
|
|
20
24
|
|
|
21
|
-
export type DummyAny =
|
|
25
|
+
export type DummyAny =
|
|
26
|
+
| string
|
|
27
|
+
| number
|
|
28
|
+
| boolean
|
|
29
|
+
| null
|
|
30
|
+
| undefined
|
|
31
|
+
| object
|
|
32
|
+
| symbol
|
|
33
|
+
| void
|
|
34
|
+
| ((...args: []) => any)
|
|
35
|
+
| never;
|
package/src/utils/utils.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from '../types';
|
|
8
|
+
import type { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
|
|
9
9
|
|
|
10
10
|
export const uuidV4 = function () {
|
|
11
11
|
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
|
@@ -57,7 +57,7 @@ export const trampoline = (fn: TrlFn) => {
|
|
|
57
57
|
|
|
58
58
|
return result;
|
|
59
59
|
},
|
|
60
|
-
{cont}
|
|
60
|
+
{ cont }
|
|
61
61
|
);
|
|
62
62
|
};
|
|
63
63
|
|
|
@@ -74,7 +74,7 @@ export const trampolineAsync = (fn: TrlAsyncFn) => {
|
|
|
74
74
|
|
|
75
75
|
return result;
|
|
76
76
|
},
|
|
77
|
-
{cont}
|
|
77
|
+
{ cont }
|
|
78
78
|
);
|
|
79
79
|
};
|
|
80
80
|
|
|
@@ -87,13 +87,13 @@ export const getMSB = (value: number): number => {
|
|
|
87
87
|
|
|
88
88
|
export const rangeCheck = (index: number, min: number, max: number, message = 'Index out of bounds.'): void => {
|
|
89
89
|
if (index < min || index > max) throw new RangeError(message);
|
|
90
|
-
}
|
|
90
|
+
};
|
|
91
91
|
|
|
92
92
|
export const throwRangeError = (message = 'The value is off-limits.'): void => {
|
|
93
93
|
throw new RangeError(message);
|
|
94
|
-
}
|
|
94
|
+
};
|
|
95
95
|
|
|
96
96
|
export const isObjOrFunc = (input: unknown): input is Record<string, unknown> | ((...args: any[]) => any) => {
|
|
97
97
|
const inputType = typeof input;
|
|
98
98
|
return (inputType === 'object' && input !== null) || inputType === 'function';
|
|
99
|
-
}
|
|
99
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {BST, BSTNode, CP} from 'bst-typed';
|
|
1
|
+
import { BST, BSTNode, CP } from 'bst-typed';
|
|
2
2
|
|
|
3
3
|
describe('Individual package BST operations test', () => {
|
|
4
4
|
it('should perform various operations on a Binary Search Tree with numeric values', () => {
|
|
@@ -183,25 +183,25 @@ describe('Individual package BST operations test', () => {
|
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
186
|
-
const objBST = new BST<{key: number; keyA: number}>();
|
|
186
|
+
const objBST = new BST<{ key: number; keyA: number }>();
|
|
187
187
|
expect(objBST).toBeInstanceOf(BST);
|
|
188
|
-
objBST.add(11, {key: 11, keyA: 11});
|
|
189
|
-
objBST.add(3, {key: 3, keyA: 3});
|
|
188
|
+
objBST.add(11, { key: 11, keyA: 11 });
|
|
189
|
+
objBST.add(3, { key: 3, keyA: 3 });
|
|
190
190
|
const values = [
|
|
191
|
-
{key: 15, keyA: 15},
|
|
192
|
-
{key: 1, keyA: 1},
|
|
193
|
-
{key: 8, keyA: 8},
|
|
194
|
-
{key: 13, keyA: 13},
|
|
195
|
-
{key: 16, keyA: 16},
|
|
196
|
-
{key: 2, keyA: 2},
|
|
197
|
-
{key: 6, keyA: 6},
|
|
198
|
-
{key: 9, keyA: 9},
|
|
199
|
-
{key: 12, keyA: 12},
|
|
200
|
-
{key: 14, keyA: 14},
|
|
201
|
-
{key: 4, keyA: 4},
|
|
202
|
-
{key: 7, keyA: 7},
|
|
203
|
-
{key: 10, keyA: 10},
|
|
204
|
-
{key: 5, keyA: 5}
|
|
191
|
+
{ key: 15, keyA: 15 },
|
|
192
|
+
{ key: 1, keyA: 1 },
|
|
193
|
+
{ key: 8, keyA: 8 },
|
|
194
|
+
{ key: 13, keyA: 13 },
|
|
195
|
+
{ key: 16, keyA: 16 },
|
|
196
|
+
{ key: 2, keyA: 2 },
|
|
197
|
+
{ key: 6, keyA: 6 },
|
|
198
|
+
{ key: 9, keyA: 9 },
|
|
199
|
+
{ key: 12, keyA: 12 },
|
|
200
|
+
{ key: 14, keyA: 14 },
|
|
201
|
+
{ key: 4, keyA: 4 },
|
|
202
|
+
{ key: 7, keyA: 7 },
|
|
203
|
+
{ key: 10, keyA: 10 },
|
|
204
|
+
{ key: 5, keyA: 5 }
|
|
205
205
|
];
|
|
206
206
|
|
|
207
207
|
objBST.addMany(
|
|
@@ -230,7 +230,7 @@ describe('Individual package BST operations test', () => {
|
|
|
230
230
|
expect(leftMost?.key).toBe(1);
|
|
231
231
|
|
|
232
232
|
const node15 = objBST.getNode(15);
|
|
233
|
-
expect(node15?.value).toEqual({key: 15, keyA: 15});
|
|
233
|
+
expect(node15?.value).toEqual({ key: 15, keyA: 15 });
|
|
234
234
|
const minNodeBySpecificNode = node15 && objBST.getLeftMost(node15);
|
|
235
235
|
expect(minNodeBySpecificNode?.key).toBe(12);
|
|
236
236
|
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
console.error(e);
|
|
36
36
|
}
|
|
37
37
|
try {
|
|
38
|
-
const {AVLTree} = window.dataStructureTyped;
|
|
38
|
+
const { AVLTree } = window.dataStructureTyped;
|
|
39
39
|
const avlTree = new AVLTree();
|
|
40
40
|
const $avlTree = document.createElement('li');
|
|
41
41
|
const $avlTreeSpan = document.createElement('span');
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
|
-
const {BinaryTree} = dataStructureTyped;
|
|
55
|
+
const { BinaryTree } = dataStructureTyped;
|
|
56
56
|
const tree = new BinaryTree();
|
|
57
57
|
tree.add(3);
|
|
58
58
|
tree.add(12);
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
try {
|
|
79
|
-
const {OrderedMap} = sdsl;
|
|
80
|
-
const {RedBlackTree} = dataStructureTyped;
|
|
79
|
+
const { OrderedMap } = sdsl;
|
|
80
|
+
const { RedBlackTree } = dataStructureTyped;
|
|
81
81
|
const cTree = new OrderedMap();
|
|
82
82
|
const tree = new RedBlackTree();
|
|
83
83
|
const tS = performance.now();
|
|
@@ -101,9 +101,9 @@
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
try {
|
|
104
|
-
const {PriorityQueue: CPriorityQueue} = sdsl;
|
|
105
|
-
const {PriorityQueue} = dataStructureTyped;
|
|
106
|
-
const pq = new PriorityQueue({comparator: (a, b) => b - a});
|
|
104
|
+
const { PriorityQueue: CPriorityQueue } = sdsl;
|
|
105
|
+
const { PriorityQueue } = dataStructureTyped;
|
|
106
|
+
const pq = new PriorityQueue({ comparator: (a, b) => b - a });
|
|
107
107
|
|
|
108
108
|
const tS = performance.now();
|
|
109
109
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {AVLTree} from '../../../../src';
|
|
1
|
+
import { AVLTree } from '../../../../src';
|
|
2
2
|
import * as Benchmark from 'benchmark';
|
|
3
|
-
import {getRandomIntArray, magnitude} from '../../../utils';
|
|
3
|
+
import { getRandomIntArray, magnitude } from '../../../utils';
|
|
4
4
|
|
|
5
5
|
const suite = new Benchmark.Suite();
|
|
6
6
|
const avl = new AVLTree<number>();
|
|
7
|
-
const {TEN_THOUSAND} = magnitude;
|
|
7
|
+
const { TEN_THOUSAND } = magnitude;
|
|
8
8
|
const arr = getRandomIntArray(TEN_THOUSAND, 0, TEN_THOUSAND, true);
|
|
9
9
|
|
|
10
10
|
suite
|
|
@@ -33,4 +33,4 @@ suite
|
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
export {suite};
|
|
36
|
+
export { suite };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {BinaryTree} from '../../../../src';
|
|
1
|
+
import { BinaryTree } from '../../../../src';
|
|
2
2
|
import * as Benchmark from 'benchmark';
|
|
3
|
-
import {getRandomIntArray, magnitude} from '../../../utils';
|
|
3
|
+
import { getRandomIntArray, magnitude } from '../../../utils';
|
|
4
4
|
|
|
5
5
|
const suite = new Benchmark.Suite();
|
|
6
6
|
const biTree = new BinaryTree<number>();
|
|
7
|
-
const {N_LOG_N} = magnitude;
|
|
7
|
+
const { N_LOG_N } = magnitude;
|
|
8
8
|
const arr = getRandomIntArray(N_LOG_N, 0, N_LOG_N, true);
|
|
9
9
|
|
|
10
10
|
suite
|
|
@@ -42,4 +42,4 @@ suite
|
|
|
42
42
|
for (let i = 0; i < N_LOG_N; i++) biTree.morris(n => n, 'pre');
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
export {suite};
|
|
45
|
+
export { suite };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {BST} from '../../../../src';
|
|
1
|
+
import { BST } from '../../../../src';
|
|
2
2
|
import * as Benchmark from 'benchmark';
|
|
3
|
-
import {getRandomIntArray, magnitude} from '../../../utils';
|
|
3
|
+
import { getRandomIntArray, magnitude } from '../../../utils';
|
|
4
4
|
|
|
5
5
|
const suite = new Benchmark.Suite();
|
|
6
6
|
const bst = new BST<number>();
|
|
7
|
-
const {TEN_THOUSAND} = magnitude;
|
|
7
|
+
const { TEN_THOUSAND } = magnitude;
|
|
8
8
|
const arr = getRandomIntArray(TEN_THOUSAND, 0, TEN_THOUSAND, true);
|
|
9
9
|
|
|
10
10
|
suite
|
|
@@ -33,4 +33,4 @@ suite
|
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
export {suite};
|
|
36
|
+
export { suite };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {RedBlackTree} from '../../../../src';
|
|
1
|
+
import { RedBlackTree } from '../../../../src';
|
|
2
2
|
import * as Benchmark from 'benchmark';
|
|
3
|
-
import {getRandomIntArray, magnitude} from '../../../utils';
|
|
4
|
-
import {OrderedMap} from 'js-sdsl';
|
|
5
|
-
import {isCompetitor} from '../../../config';
|
|
3
|
+
import { getRandomIntArray, magnitude } from '../../../utils';
|
|
4
|
+
import { OrderedMap } from 'js-sdsl';
|
|
5
|
+
import { isCompetitor } from '../../../config';
|
|
6
6
|
|
|
7
7
|
const suite = new Benchmark.Suite();
|
|
8
8
|
const rbTree = new RedBlackTree();
|
|
9
|
-
const {HUNDRED_THOUSAND} = magnitude;
|
|
9
|
+
const { HUNDRED_THOUSAND } = magnitude;
|
|
10
10
|
const arr = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND, true);
|
|
11
|
-
const
|
|
11
|
+
const cOrderedMap = new OrderedMap<number, number>();
|
|
12
12
|
|
|
13
13
|
suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add`, () => {
|
|
14
14
|
rbTree.clear();
|
|
@@ -18,9 +18,9 @@ suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add`, () => {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
if (isCompetitor) {
|
|
21
|
-
suite.add(`${HUNDRED_THOUSAND.toLocaleString()}
|
|
21
|
+
suite.add(`${HUNDRED_THOUSAND.toLocaleString()} CPT add`, () => {
|
|
22
22
|
for (let i = 0; i < arr.length; i++) {
|
|
23
|
-
|
|
23
|
+
cOrderedMap.setElement(arr[i], arr[i]);
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
}
|
|
@@ -41,4 +41,4 @@ suite
|
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
export {suite};
|
|
44
|
+
export { suite };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { PriorityQueue as MJSPriorityQueue } from '../../../dist/cjs';
|
|
2
|
+
import { PriorityQueue as SRCPriorityQueue } from '../../../src';
|
|
3
|
+
import { PriorityQueue as CJSPriorityQueue } from '../../../dist/mjs';
|
|
4
|
+
import {
|
|
5
|
+
Deque as CDeque,
|
|
6
|
+
HashMap as CHashMap,
|
|
7
|
+
LinkList as CLinkedList,
|
|
8
|
+
OrderedMap,
|
|
9
|
+
PriorityQueue as CPriorityQueue,
|
|
10
|
+
Queue as CQueue,
|
|
11
|
+
Stack as CStack
|
|
12
|
+
} from 'js-sdsl';
|
|
13
|
+
|
|
14
|
+
import * as Benchmark from 'benchmark';
|
|
15
|
+
import { getRandomIntArray, magnitude } from '../../utils';
|
|
16
|
+
import { isCompetitor } from '../../config';
|
|
17
|
+
|
|
18
|
+
const suite = new Benchmark.Suite();
|
|
19
|
+
const { TEN_THOUSAND, HUNDRED_THOUSAND, LINEAR } = magnitude;
|
|
20
|
+
const cOrderedMap = new OrderedMap<number, number>();
|
|
21
|
+
const arrHundredThousand = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND, true);
|
|
22
|
+
|
|
23
|
+
suite.add(`SRC ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
24
|
+
|
|
25
|
+
const pq = new SRCPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
26
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
27
|
+
}).add(`CJS ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
28
|
+
|
|
29
|
+
const pq = new CJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
30
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
31
|
+
}).add(`MJS ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
32
|
+
|
|
33
|
+
const pq = new MJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
34
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (isCompetitor) {
|
|
38
|
+
suite.add(`CPT PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
39
|
+
|
|
40
|
+
const pq = new CPriorityQueue<number>();
|
|
41
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.push(i);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
suite.add(`SRC PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
46
|
+
const pq = new SRCPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
47
|
+
|
|
48
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
49
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
50
|
+
}).add(`CJS PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
51
|
+
const pq = new CJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
52
|
+
|
|
53
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
54
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
55
|
+
}).add(`MJS PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
56
|
+
const pq = new MJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
59
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if (isCompetitor) {
|
|
64
|
+
suite.add(`CPT PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
65
|
+
const pq = new CPriorityQueue<number>();
|
|
66
|
+
|
|
67
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.push(i);
|
|
68
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
69
|
+
})
|
|
70
|
+
.add(`CPT OM ${HUNDRED_THOUSAND.toLocaleString()} add`, () => {
|
|
71
|
+
for (let i = 0; i < arrHundredThousand.length; i++) {
|
|
72
|
+
cOrderedMap.setElement(arrHundredThousand[i], arrHundredThousand[i]);
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
.add(`CPT HM ${TEN_THOUSAND.toLocaleString()} set`, () => {
|
|
76
|
+
const hm = new CHashMap<number, number>();
|
|
77
|
+
|
|
78
|
+
for (let i = 0; i < TEN_THOUSAND; i++) {
|
|
79
|
+
hm.setElement(i, i);
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
.add(`CPT HM ${TEN_THOUSAND.toLocaleString()} set & get`, () => {
|
|
83
|
+
const hm = new CHashMap<number, number>();
|
|
84
|
+
|
|
85
|
+
for (let i = 0; i < TEN_THOUSAND; i++) {
|
|
86
|
+
hm.setElement(i, i);
|
|
87
|
+
}
|
|
88
|
+
for (let i = 0; i < TEN_THOUSAND; i++) {
|
|
89
|
+
hm.getElementByKey(i);
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
.add(`CPT LL ${LINEAR.toLocaleString()} unshift`, () => {
|
|
93
|
+
const list = new CLinkedList<number>();
|
|
94
|
+
|
|
95
|
+
for (let i = 0; i < LINEAR; i++) {
|
|
96
|
+
list.pushFront(i);
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
.add(`CPT PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
100
|
+
const pq = new CPriorityQueue<number>();
|
|
101
|
+
|
|
102
|
+
for (let i = 0; i < TEN_THOUSAND; i++) {
|
|
103
|
+
pq.push(i);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
for (let i = 0; i < TEN_THOUSAND; i++) {
|
|
107
|
+
pq.pop();
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
.add(`CPT DQ ${LINEAR.toLocaleString()} push`, () => {
|
|
111
|
+
const deque = new CDeque<number>();
|
|
112
|
+
for (let i = 0; i < LINEAR; i++) {
|
|
113
|
+
deque.pushBack(i);
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
.add(`CPT Q ${LINEAR.toLocaleString()} push`, () => {
|
|
117
|
+
const queue = new CQueue<number>();
|
|
118
|
+
|
|
119
|
+
for (let i = 0; i < LINEAR; i++) {
|
|
120
|
+
queue.push(i);
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.add(`CPT ST ${LINEAR.toLocaleString()} push`, () => {
|
|
124
|
+
const queue = new CStack<number>();
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i < LINEAR; i++) {
|
|
127
|
+
queue.push(i);
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
.add(`CPT ST ${LINEAR.toLocaleString()} push & pop`, () => {
|
|
131
|
+
const queue = new CStack<number>();
|
|
132
|
+
|
|
133
|
+
for (let i = 0; i < LINEAR; i++) {
|
|
134
|
+
queue.push(i);
|
|
135
|
+
}
|
|
136
|
+
for (let i = 0; i < LINEAR; i++) {
|
|
137
|
+
queue.pop();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { suite };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {DirectedGraph} from '../../../../src';
|
|
1
|
+
import { DirectedGraph } from '../../../../src';
|
|
2
2
|
import * as Benchmark from 'benchmark';
|
|
3
|
-
import {getRandomIndex, getRandomWords, magnitude} from '../../../utils';
|
|
3
|
+
import { getRandomIndex, getRandomWords, magnitude } from '../../../utils';
|
|
4
4
|
|
|
5
5
|
const suite = new Benchmark.Suite();
|
|
6
|
-
const {THOUSAND} = magnitude;
|
|
6
|
+
const { THOUSAND } = magnitude;
|
|
7
7
|
const graph = new DirectedGraph<number, number>();
|
|
8
8
|
const vertexes = getRandomWords(THOUSAND);
|
|
9
9
|
|
|
@@ -46,4 +46,4 @@ suite
|
|
|
46
46
|
// }
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
export {suite};
|
|
49
|
+
export { suite };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {HashMap} from '../../../../src';
|
|
2
|
-
import {HashMap as CHashMap} from 'js-sdsl';
|
|
1
|
+
import { HashMap } from '../../../../src';
|
|
2
|
+
import { HashMap as CHashMap } from 'js-sdsl';
|
|
3
3
|
import * as Benchmark from 'benchmark';
|
|
4
|
-
import {magnitude} from '../../../utils';
|
|
5
|
-
import {isCompetitor} from '../../../config';
|
|
4
|
+
import { magnitude } from '../../../utils';
|
|
5
|
+
import { isCompetitor } from '../../../config';
|
|
6
6
|
|
|
7
7
|
const suite = new Benchmark.Suite();
|
|
8
|
-
const {TEN_THOUSAND} = magnitude;
|
|
8
|
+
const { TEN_THOUSAND } = magnitude;
|
|
9
9
|
|
|
10
10
|
suite.add(`${TEN_THOUSAND.toLocaleString()} set`, () => {
|
|
11
11
|
const hm = new HashMap<number, number>();
|
|
@@ -15,7 +15,7 @@ suite.add(`${TEN_THOUSAND.toLocaleString()} set`, () => {
|
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
if (isCompetitor) {
|
|
18
|
-
suite.add(`${TEN_THOUSAND.toLocaleString()}
|
|
18
|
+
suite.add(`${TEN_THOUSAND.toLocaleString()} CPT set`, () => {
|
|
19
19
|
const hm = new CHashMap<number, number>();
|
|
20
20
|
|
|
21
21
|
for (let i = 0; i < TEN_THOUSAND; i++) {
|
|
@@ -34,7 +34,7 @@ suite.add(`${TEN_THOUSAND.toLocaleString()} set & get`, () => {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
if (isCompetitor) {
|
|
37
|
-
suite.add(`${TEN_THOUSAND.toLocaleString()}
|
|
37
|
+
suite.add(`${TEN_THOUSAND.toLocaleString()} CPT set & get`, () => {
|
|
38
38
|
const hm = new CHashMap<number, number>();
|
|
39
39
|
|
|
40
40
|
for (let i = 0; i < TEN_THOUSAND; i++) {
|
|
@@ -45,4 +45,4 @@ if (isCompetitor) {
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
export {suite};
|
|
48
|
+
export { suite };
|