tree-set-typed 2.3.0
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 +61 -0
- package/.prettierignore +6 -0
- package/.prettierrc.js +16 -0
- package/LICENSE +21 -0
- package/README.md +482 -0
- package/coverage/clover.xml +13 -0
- package/coverage/coverage-final.json +96 -0
- package/coverage/coverage-summary.json +60 -0
- package/coverage/lcov-report/base.css +403 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +119 -0
- package/coverage/lcov-report/index.ts.html +109 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +206 -0
- package/coverage/lcov.info +14 -0
- package/dist/cjs/index.cjs +12 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs-legacy/index.cjs +12 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm-legacy/index.mjs +3 -0
- package/dist/esm-legacy/index.mjs.map +1 -0
- package/dist/types/common/index.d.ts +12 -0
- package/dist/types/constants/index.d.ts +4 -0
- package/dist/types/data-structures/base/index.d.ts +2 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +219 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +150 -0
- package/dist/types/data-structures/base/linear-base.d.ts +335 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +236 -0
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +197 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +440 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +807 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +645 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +10 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +312 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -0
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +243 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +333 -0
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +332 -0
- package/dist/types/data-structures/graph/index.d.ts +4 -0
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +347 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +428 -0
- package/dist/types/data-structures/hash/index.d.ts +1 -0
- package/dist/types/data-structures/heap/heap.d.ts +552 -0
- package/dist/types/data-structures/heap/index.d.ts +3 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -0
- package/dist/types/data-structures/index.d.ts +12 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +437 -0
- package/dist/types/data-structures/linked-list/index.d.ts +3 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +567 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -0
- package/dist/types/data-structures/matrix/index.d.ts +2 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -0
- package/dist/types/data-structures/matrix/navigator.d.ts +55 -0
- package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -0
- package/dist/types/data-structures/queue/deque.d.ts +459 -0
- package/dist/types/data-structures/queue/index.d.ts +2 -0
- package/dist/types/data-structures/queue/queue.d.ts +364 -0
- package/dist/types/data-structures/stack/index.d.ts +1 -0
- package/dist/types/data-structures/stack/stack.d.ts +324 -0
- package/dist/types/data-structures/tree/index.d.ts +1 -0
- package/dist/types/data-structures/tree/tree.d.ts +62 -0
- package/dist/types/data-structures/trie/index.d.ts +1 -0
- package/dist/types/data-structures/trie/trie.d.ts +412 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/interfaces/binary-tree.d.ts +60 -0
- package/dist/types/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/types/interfaces/graph.d.ts +21 -0
- package/dist/types/interfaces/heap.d.ts +1 -0
- package/dist/types/interfaces/index.d.ts +8 -0
- package/dist/types/interfaces/navigator.d.ts +1 -0
- package/dist/types/interfaces/priority-queue.d.ts +1 -0
- package/dist/types/interfaces/segment-tree.d.ts +1 -0
- package/dist/types/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/types/types/common.d.ts +15 -0
- package/dist/types/types/data-structures/base/base.d.ts +13 -0
- package/dist/types/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
- package/dist/types/types/data-structures/binary-tree/index.d.ts +9 -0
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
- package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/index.d.ts +3 -0
- package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
- package/dist/types/types/data-structures/hash/index.d.ts +2 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
- package/dist/types/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/types/data-structures/index.d.ts +12 -0
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/index.d.ts +3 -0
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
- package/dist/types/types/data-structures/matrix/index.d.ts +2 -0
- package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
- package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/types/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
- package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
- package/dist/types/types/data-structures/queue/index.d.ts +2 -0
- package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
- package/dist/types/types/data-structures/stack/index.d.ts +1 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
- package/dist/types/types/data-structures/tree/index.d.ts +1 -0
- package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/types/data-structures/trie/index.d.ts +1 -0
- package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/utils/index.d.ts +2 -0
- package/dist/types/types/utils/utils.d.ts +22 -0
- package/dist/types/types/utils/validate-type.d.ts +19 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/number.d.ts +14 -0
- package/dist/types/utils/utils.d.ts +209 -0
- package/dist/umd/red-black-tree-typed.js +14578 -0
- package/dist/umd/red-black-tree-typed.js.map +1 -0
- package/dist/umd/red-black-tree-typed.min.js +44 -0
- package/dist/umd/red-black-tree-typed.min.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +92 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1383 -0
- package/docs/classes/AVLTree.html +2046 -0
- package/docs/classes/AVLTreeNode.html +263 -0
- package/docs/index.html +523 -0
- package/docs/modules.html +45 -0
- package/jest.config.js +8 -0
- package/package.json +113 -0
- package/src/common/index.ts +23 -0
- package/src/constants/index.ts +4 -0
- package/src/data-structures/base/index.ts +2 -0
- package/src/data-structures/base/iterable-element-base.ts +352 -0
- package/src/data-structures/base/iterable-entry-base.ts +246 -0
- package/src/data-structures/base/linear-base.ts +643 -0
- package/src/data-structures/binary-tree/avl-tree-counter.ts +539 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +438 -0
- package/src/data-structures/binary-tree/avl-tree.ts +840 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +331 -0
- package/src/data-structures/binary-tree/binary-tree.ts +2492 -0
- package/src/data-structures/binary-tree/bst.ts +2024 -0
- package/src/data-structures/binary-tree/index.ts +10 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +767 -0
- package/src/data-structures/binary-tree/segment-tree.ts +324 -0
- package/src/data-structures/binary-tree/tree-counter.ts +575 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +549 -0
- package/src/data-structures/graph/abstract-graph.ts +1081 -0
- package/src/data-structures/graph/directed-graph.ts +715 -0
- package/src/data-structures/graph/index.ts +4 -0
- package/src/data-structures/graph/map-graph.ts +132 -0
- package/src/data-structures/graph/undirected-graph.ts +626 -0
- package/src/data-structures/hash/hash-map.ts +813 -0
- package/src/data-structures/hash/index.ts +1 -0
- package/src/data-structures/heap/heap.ts +1020 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +47 -0
- package/src/data-structures/heap/min-heap.ts +36 -0
- package/src/data-structures/index.ts +12 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +876 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +1050 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +173 -0
- package/src/data-structures/matrix/index.ts +2 -0
- package/src/data-structures/matrix/matrix.ts +491 -0
- package/src/data-structures/matrix/navigator.ts +124 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +42 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +29 -0
- package/src/data-structures/priority-queue/priority-queue.ts +19 -0
- package/src/data-structures/queue/deque.ts +1001 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +592 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +469 -0
- package/src/data-structures/tree/index.ts +1 -0
- package/src/data-structures/tree/tree.ts +115 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +756 -0
- package/src/index.ts +24 -0
- package/src/interfaces/binary-tree.ts +252 -0
- package/src/interfaces/doubly-linked-list.ts +1 -0
- package/src/interfaces/graph.ts +44 -0
- package/src/interfaces/heap.ts +1 -0
- package/src/interfaces/index.ts +8 -0
- package/src/interfaces/navigator.ts +1 -0
- package/src/interfaces/priority-queue.ts +1 -0
- package/src/interfaces/segment-tree.ts +1 -0
- package/src/interfaces/singly-linked-list.ts +1 -0
- package/src/types/common.ts +25 -0
- package/src/types/data-structures/base/base.ts +34 -0
- package/src/types/data-structures/base/index.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -0
- package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
- package/src/types/data-structures/binary-tree/bst.ts +19 -0
- package/src/types/data-structures/binary-tree/index.ts +9 -0
- package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -0
- package/src/types/data-structures/graph/abstract-graph.ts +18 -0
- package/src/types/data-structures/graph/directed-graph.ts +2 -0
- package/src/types/data-structures/graph/index.ts +3 -0
- package/src/types/data-structures/graph/map-graph.ts +1 -0
- package/src/types/data-structures/graph/undirected-graph.ts +1 -0
- package/src/types/data-structures/hash/hash-map.ts +19 -0
- package/src/types/data-structures/hash/index.ts +3 -0
- package/src/types/data-structures/heap/heap.ts +6 -0
- package/src/types/data-structures/heap/index.ts +1 -0
- package/src/types/data-structures/heap/max-heap.ts +1 -0
- package/src/types/data-structures/heap/min-heap.ts +1 -0
- package/src/types/data-structures/index.ts +12 -0
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -0
- package/src/types/data-structures/linked-list/index.ts +3 -0
- package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
- package/src/types/data-structures/matrix/index.ts +2 -0
- package/src/types/data-structures/matrix/matrix.ts +7 -0
- package/src/types/data-structures/matrix/navigator.ts +14 -0
- package/src/types/data-structures/priority-queue/index.ts +3 -0
- package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +3 -0
- package/src/types/data-structures/queue/deque.ts +5 -0
- package/src/types/data-structures/queue/index.ts +2 -0
- package/src/types/data-structures/queue/queue.ts +5 -0
- package/src/types/data-structures/stack/index.ts +1 -0
- package/src/types/data-structures/stack/stack.ts +3 -0
- package/src/types/data-structures/tree/index.ts +1 -0
- package/src/types/data-structures/tree/tree.ts +1 -0
- package/src/types/data-structures/trie/index.ts +1 -0
- package/src/types/data-structures/trie/trie.ts +3 -0
- package/src/types/index.ts +3 -0
- package/src/types/utils/index.ts +2 -0
- package/src/types/utils/utils.ts +33 -0
- package/src/types/utils/validate-type.ts +35 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/number.ts +22 -0
- package/src/utils/utils.ts +350 -0
- package/test/index.test.ts +111 -0
- package/tsconfig.base.json +23 -0
- package/tsconfig.json +12 -0
- package/tsconfig.test.json +8 -0
- package/tsconfig.types.json +15 -0
- package/tsup.config.js +28 -0
- package/tsup.node.config.js +71 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module tree-set-typed
|
|
4
|
+
*
|
|
5
|
+
* TreeSet - A sorted set implementation based on Red-Black Tree
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { TreeSet } from 'tree-set-typed';
|
|
10
|
+
*
|
|
11
|
+
* const set = new TreeSet<number>();
|
|
12
|
+
* set.add(5);
|
|
13
|
+
* set.add(3);
|
|
14
|
+
* set.add(7);
|
|
15
|
+
*
|
|
16
|
+
* console.log([...set]); // [3, 5, 7] - always sorted
|
|
17
|
+
* console.log(set.has(5)); // true
|
|
18
|
+
* console.log(set.first()); // 3
|
|
19
|
+
* console.log(set.last()); // 7
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export { TreeSet } from 'data-structure-typed';
|
|
24
|
+
export type { TreeSetOptions } from 'data-structure-typed';
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { BinaryTreeNode } from '../data-structures';
|
|
2
|
+
import type {
|
|
3
|
+
BinaryTreeDeleteResult,
|
|
4
|
+
BinaryTreeOptions,
|
|
5
|
+
BTNRep,
|
|
6
|
+
DFSOrderPattern,
|
|
7
|
+
EntryCallback,
|
|
8
|
+
IterationType,
|
|
9
|
+
NodeCallback,
|
|
10
|
+
NodePredicate,
|
|
11
|
+
OptNodeOrNull,
|
|
12
|
+
ReduceEntryCallback,
|
|
13
|
+
ToEntryFn
|
|
14
|
+
} from '../types';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Public, implementation-agnostic binary tree API.
|
|
18
|
+
* K = key, V = value, R = raw/record used with toEntryFn (optional).
|
|
19
|
+
* Transforming methods like `map` use method-level generics MK/MV/MR.
|
|
20
|
+
*/
|
|
21
|
+
export interface IBinaryTree<K = any, V = any, R = any> {
|
|
22
|
+
// ---- state ----
|
|
23
|
+
readonly size: number;
|
|
24
|
+
readonly root: BinaryTreeNode<K, V> | null | undefined;
|
|
25
|
+
readonly isMapMode: boolean;
|
|
26
|
+
// NOTE: iterationType is mutable on the class; remove readonly here to match
|
|
27
|
+
iterationType: IterationType;
|
|
28
|
+
// Extra public state/getters implemented by BinaryTree (useful to callers)
|
|
29
|
+
readonly NIL: BinaryTreeNode<K, V>;
|
|
30
|
+
readonly store: Map<K, V | undefined>;
|
|
31
|
+
readonly toEntryFn?: ToEntryFn<K, V, R>;
|
|
32
|
+
readonly isDuplicate: boolean;
|
|
33
|
+
|
|
34
|
+
// ---- construction / mutation ----
|
|
35
|
+
createNode(key: K, value?: BinaryTreeNode<K, V>['value']): BinaryTreeNode<K, V>;
|
|
36
|
+
|
|
37
|
+
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): IBinaryTree<K, V, R>;
|
|
38
|
+
|
|
39
|
+
add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
|
|
40
|
+
|
|
41
|
+
set(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
|
|
42
|
+
|
|
43
|
+
// Accept raw R as well (when toEntryFn is configured)
|
|
44
|
+
addMany(
|
|
45
|
+
keysNodesEntriesOrRaws: Iterable<
|
|
46
|
+
K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
|
|
47
|
+
>,
|
|
48
|
+
values?: Iterable<V | undefined>
|
|
49
|
+
): boolean[];
|
|
50
|
+
|
|
51
|
+
// Accept BTNRep, predicate, or raw R for deletion
|
|
52
|
+
delete(
|
|
53
|
+
keyNodeEntryRawOrPredicate: R | BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>
|
|
54
|
+
): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
55
|
+
|
|
56
|
+
clear(): void;
|
|
57
|
+
|
|
58
|
+
isEmpty(): boolean;
|
|
59
|
+
|
|
60
|
+
// ---- query / read ----
|
|
61
|
+
|
|
62
|
+
// Widen `get` to support entry and optional traversal context (matches impl)
|
|
63
|
+
get(
|
|
64
|
+
keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
65
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
66
|
+
iterationType?: IterationType
|
|
67
|
+
): V | undefined;
|
|
68
|
+
|
|
69
|
+
// `has` also supports node/entry/predicate and optional traversal context
|
|
70
|
+
has(
|
|
71
|
+
keyNodeEntryOrPredicate?:
|
|
72
|
+
| K
|
|
73
|
+
| BinaryTreeNode<K, V>
|
|
74
|
+
| [K | null | undefined, V | undefined]
|
|
75
|
+
| null
|
|
76
|
+
| undefined
|
|
77
|
+
| NodePredicate<BinaryTreeNode<K, V> | null>,
|
|
78
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
79
|
+
iterationType?: IterationType
|
|
80
|
+
): boolean;
|
|
81
|
+
|
|
82
|
+
hasValue(value: V): boolean;
|
|
83
|
+
|
|
84
|
+
find(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): [K, V | undefined] | undefined;
|
|
85
|
+
|
|
86
|
+
// ---- iteration ----
|
|
87
|
+
[Symbol.iterator](): IterableIterator<[K, V | undefined]>;
|
|
88
|
+
|
|
89
|
+
entries(): IterableIterator<[K, V | undefined]>;
|
|
90
|
+
|
|
91
|
+
keys(): IterableIterator<K>;
|
|
92
|
+
|
|
93
|
+
values(): IterableIterator<V | undefined>;
|
|
94
|
+
|
|
95
|
+
forEach(callbackfn: EntryCallback<K, V | undefined, void>, thisArg?: unknown): void;
|
|
96
|
+
|
|
97
|
+
every(callbackfn: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): boolean;
|
|
98
|
+
|
|
99
|
+
some(callbackfn: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): boolean;
|
|
100
|
+
|
|
101
|
+
reduce<U>(reducer: ReduceEntryCallback<K, V | undefined, U>, initialValue: U): U;
|
|
102
|
+
|
|
103
|
+
// ---- node access / extremes ----
|
|
104
|
+
getNode(
|
|
105
|
+
keyNodeEntryOrPredicate:
|
|
106
|
+
| K
|
|
107
|
+
| BinaryTreeNode<K, V>
|
|
108
|
+
| [K | null | undefined, V | undefined]
|
|
109
|
+
| null
|
|
110
|
+
| undefined
|
|
111
|
+
| NodePredicate<BinaryTreeNode<K, V> | null>,
|
|
112
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
113
|
+
iterationType?: IterationType
|
|
114
|
+
): OptNodeOrNull<BinaryTreeNode<K, V>>;
|
|
115
|
+
|
|
116
|
+
getLeftMost<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(
|
|
117
|
+
callback?: C,
|
|
118
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
119
|
+
iterationType?: IterationType
|
|
120
|
+
): ReturnType<C>;
|
|
121
|
+
|
|
122
|
+
getRightMost<C extends NodeCallback<BinaryTreeNode<K, V> | undefined>>(
|
|
123
|
+
callback?: C,
|
|
124
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
125
|
+
iterationType?: IterationType
|
|
126
|
+
): ReturnType<C>;
|
|
127
|
+
|
|
128
|
+
// ---- traversal ----
|
|
129
|
+
dfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(
|
|
130
|
+
callback?: C,
|
|
131
|
+
pattern?: DFSOrderPattern,
|
|
132
|
+
onlyOne?: boolean,
|
|
133
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
134
|
+
iterationType?: IterationType
|
|
135
|
+
): ReturnType<C>[];
|
|
136
|
+
|
|
137
|
+
dfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
|
|
138
|
+
callback?: C,
|
|
139
|
+
pattern?: DFSOrderPattern,
|
|
140
|
+
onlyOne?: boolean,
|
|
141
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
142
|
+
iterationType?: IterationType,
|
|
143
|
+
includeNull?: boolean
|
|
144
|
+
): ReturnType<C>[];
|
|
145
|
+
|
|
146
|
+
bfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(
|
|
147
|
+
callback?: C,
|
|
148
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
149
|
+
iterationType?: IterationType,
|
|
150
|
+
includeNull?: false
|
|
151
|
+
): ReturnType<C>[];
|
|
152
|
+
|
|
153
|
+
bfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
|
|
154
|
+
callback?: C,
|
|
155
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
156
|
+
iterationType?: IterationType,
|
|
157
|
+
includeNull?: true
|
|
158
|
+
): ReturnType<C>[];
|
|
159
|
+
|
|
160
|
+
morris<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
|
|
161
|
+
callback?: C,
|
|
162
|
+
pattern?: DFSOrderPattern,
|
|
163
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
|
|
164
|
+
): ReturnType<C>[];
|
|
165
|
+
|
|
166
|
+
leaves<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
|
|
167
|
+
callback?: C,
|
|
168
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
169
|
+
iterationType?: IterationType
|
|
170
|
+
): ReturnType<C>[];
|
|
171
|
+
|
|
172
|
+
listLevels<C extends NodeCallback<BinaryTreeNode<K, V>>>(
|
|
173
|
+
callback?: C,
|
|
174
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
175
|
+
iterationType?: IterationType,
|
|
176
|
+
includeNull?: false
|
|
177
|
+
): ReturnType<C>[][];
|
|
178
|
+
|
|
179
|
+
listLevels<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
|
|
180
|
+
callback?: C,
|
|
181
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
182
|
+
iterationType?: IterationType,
|
|
183
|
+
includeNull?: true
|
|
184
|
+
): ReturnType<C>[][];
|
|
185
|
+
|
|
186
|
+
getPathToRoot<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(
|
|
187
|
+
beginNode: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
188
|
+
callback?: C,
|
|
189
|
+
isReverse?: boolean
|
|
190
|
+
): ReturnType<C>[];
|
|
191
|
+
|
|
192
|
+
// ---- metrics & validation ----
|
|
193
|
+
getDepth(
|
|
194
|
+
dist: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
195
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
|
|
196
|
+
): number;
|
|
197
|
+
|
|
198
|
+
getHeight(
|
|
199
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
200
|
+
iterationType?: IterationType
|
|
201
|
+
): number;
|
|
202
|
+
|
|
203
|
+
getMinHeight(
|
|
204
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
205
|
+
iterationType?: IterationType
|
|
206
|
+
): number;
|
|
207
|
+
|
|
208
|
+
isPerfectlyBalanced(
|
|
209
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
|
|
210
|
+
): boolean;
|
|
211
|
+
|
|
212
|
+
isBST(
|
|
213
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
214
|
+
iterationType?: IterationType
|
|
215
|
+
): boolean;
|
|
216
|
+
|
|
217
|
+
// ---- search helpers ----
|
|
218
|
+
search<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
|
|
219
|
+
keyNodeEntryOrPredicate:
|
|
220
|
+
| K
|
|
221
|
+
| BinaryTreeNode<K, V>
|
|
222
|
+
| [K | null | undefined, V | undefined]
|
|
223
|
+
| null
|
|
224
|
+
| undefined
|
|
225
|
+
| NodePredicate<BinaryTreeNode<K, V> | null>,
|
|
226
|
+
onlyOne?: boolean,
|
|
227
|
+
callback?: C,
|
|
228
|
+
startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
229
|
+
iterationType?: IterationType
|
|
230
|
+
): ReturnType<C>[];
|
|
231
|
+
|
|
232
|
+
// ---- immutable transforms ----
|
|
233
|
+
clone(): this;
|
|
234
|
+
|
|
235
|
+
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this;
|
|
236
|
+
|
|
237
|
+
map<MK = K, MV = V, MR = any>(
|
|
238
|
+
callback: EntryCallback<K, V | undefined, [MK, MV]>,
|
|
239
|
+
options?: Partial<BinaryTreeOptions<MK, MV, MR>>,
|
|
240
|
+
thisArg?: unknown
|
|
241
|
+
): IBinaryTree<MK, MV, MR>;
|
|
242
|
+
|
|
243
|
+
// ---- bulk / interop ----
|
|
244
|
+
merge(anotherTree: IBinaryTree<K, V, R>): void;
|
|
245
|
+
|
|
246
|
+
refill(
|
|
247
|
+
keysNodesEntriesOrRaws: Iterable<
|
|
248
|
+
K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
|
|
249
|
+
>,
|
|
250
|
+
values?: Iterable<V | undefined>
|
|
251
|
+
): void;
|
|
252
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { VertexKey } from '../types';
|
|
2
|
+
|
|
3
|
+
export interface IGraph<V, E, VO, EO> {
|
|
4
|
+
// Vertex factories
|
|
5
|
+
createVertex(key: VertexKey, value?: V): VO;
|
|
6
|
+
|
|
7
|
+
// Edge factories
|
|
8
|
+
createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
|
|
9
|
+
|
|
10
|
+
// Core vertex ops
|
|
11
|
+
getVertex(vertexKey: VertexKey): VO | undefined;
|
|
12
|
+
|
|
13
|
+
hasVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
14
|
+
|
|
15
|
+
addVertex(vertex: VO): boolean;
|
|
16
|
+
|
|
17
|
+
addVertex(key: VertexKey, value?: V): boolean;
|
|
18
|
+
|
|
19
|
+
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
20
|
+
|
|
21
|
+
// Core edge ops
|
|
22
|
+
deleteEdge(edge: EO): EO | undefined;
|
|
23
|
+
|
|
24
|
+
getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
|
|
25
|
+
|
|
26
|
+
degreeOf(vertexOrKey: VO | VertexKey): number;
|
|
27
|
+
|
|
28
|
+
edgeSet(): EO[];
|
|
29
|
+
|
|
30
|
+
edgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
31
|
+
|
|
32
|
+
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
33
|
+
|
|
34
|
+
getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
35
|
+
|
|
36
|
+
// Container-like ops
|
|
37
|
+
isEmpty(): boolean;
|
|
38
|
+
|
|
39
|
+
clear(): void;
|
|
40
|
+
|
|
41
|
+
clone(): this;
|
|
42
|
+
|
|
43
|
+
filter(...args: any[]): this;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type CP = 1 | -1 | 0;
|
|
2
|
+
|
|
3
|
+
export type IterationType = 'ITERATIVE' | 'RECURSIVE';
|
|
4
|
+
|
|
5
|
+
export type FamilyPosition = 'ROOT' | 'LEFT' | 'RIGHT' | 'ROOT_LEFT' | 'ROOT_RIGHT' | 'ISOLATED' | 'MAL_NODE';
|
|
6
|
+
|
|
7
|
+
export type Comparator<K> = (a: K, b: K) => number;
|
|
8
|
+
|
|
9
|
+
export type DFSOrderPattern = 'PRE' | 'IN' | 'POST';
|
|
10
|
+
|
|
11
|
+
export type NodeDisplayLayout = [string[], number, number, number];
|
|
12
|
+
|
|
13
|
+
export interface IterableWithSize<T> extends Iterable<T> {
|
|
14
|
+
size: number | ((...args: any[]) => number);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IterableWithLength<T> extends Iterable<T> {
|
|
18
|
+
length: number | ((...args: any[]) => number);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type OptValue<V> = V | undefined;
|
|
22
|
+
|
|
23
|
+
export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLength<T>;
|
|
24
|
+
|
|
25
|
+
export type CRUD = 'CREATED' | 'READ' | 'UPDATED' | 'DELETED';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
|
|
2
|
+
import { LinearBase } from '../../../data-structures/base/linear-base';
|
|
3
|
+
|
|
4
|
+
export type EntryCallback<K, V, R> = (value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
|
|
5
|
+
export type ElementCallback<E, R, RT> = (element: E, index: number, original: IterableElementBase<E, R>) => RT;
|
|
6
|
+
export type ReduceEntryCallback<K, V, R> = (
|
|
7
|
+
accumulator: R,
|
|
8
|
+
value: V,
|
|
9
|
+
key: K,
|
|
10
|
+
index: number,
|
|
11
|
+
original: IterableEntryBase<K, V>
|
|
12
|
+
) => R;
|
|
13
|
+
|
|
14
|
+
export type ReduceElementCallback<E, R, U = E> = (
|
|
15
|
+
accumulator: U,
|
|
16
|
+
value: E,
|
|
17
|
+
index: number,
|
|
18
|
+
self: IterableElementBase<E, R>
|
|
19
|
+
) => U;
|
|
20
|
+
|
|
21
|
+
export type ReduceLinearCallback<E, RT = E> = (
|
|
22
|
+
accumulator: RT,
|
|
23
|
+
element: E,
|
|
24
|
+
index: number,
|
|
25
|
+
original: LinearBase<E>
|
|
26
|
+
) => RT;
|
|
27
|
+
|
|
28
|
+
export type IterableElementBaseOptions<E, R> = {
|
|
29
|
+
toElementFn?: (rawElement: R) => E;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type LinearBaseOptions<E, R> = IterableElementBaseOptions<E, R> & {
|
|
33
|
+
maxLen?: number;
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './base';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IterationType, OptValue } from '../../common';
|
|
2
|
+
import { DFSOperation } from '../../../common';
|
|
3
|
+
|
|
4
|
+
export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
|
|
5
|
+
|
|
6
|
+
export type BinaryTreeOptions<K, V, R> = {
|
|
7
|
+
iterationType?: IterationType;
|
|
8
|
+
toEntryFn?: ToEntryFn<K, V, R>;
|
|
9
|
+
isMapMode?: boolean;
|
|
10
|
+
isDuplicate?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type BinaryTreePrintOptions = { isShowUndefined?: boolean; isShowNull?: boolean; isShowRedBlackNIL?: boolean };
|
|
14
|
+
|
|
15
|
+
export type OptNodeOrNull<NODE> = NODE | null | undefined;
|
|
16
|
+
|
|
17
|
+
export type BTNOptKeyOrNull<K> = K | null | undefined;
|
|
18
|
+
|
|
19
|
+
export type BTNEntry<K, V> = [BTNOptKeyOrNull<K>, OptValue<V>];
|
|
20
|
+
|
|
21
|
+
export type BTNOptKeyNodeOrNull<K, NODE> = BTNOptKeyOrNull<K> | NODE;
|
|
22
|
+
|
|
23
|
+
export type BTNRep<K, V, NODE> = BTNEntry<K, V> | BTNOptKeyNodeOrNull<K, NODE>;
|
|
24
|
+
|
|
25
|
+
export type BinaryTreeDeleteResult<NODE> = { deleted: OptNodeOrNull<NODE>; needBalanced: OptNodeOrNull<NODE> };
|
|
26
|
+
|
|
27
|
+
export type NodeCallback<NODE, D = any> = (node: NODE) => D;
|
|
28
|
+
|
|
29
|
+
export type NodePredicate<NODE> = (node: NODE) => boolean;
|
|
30
|
+
|
|
31
|
+
export type DFSStackItem<NODE> = { opt: DFSOperation; node: OptNodeOrNull<NODE> }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BinaryTreeOptions } from './binary-tree';
|
|
2
|
+
import type { Comparator, OptValue } from '../../common';
|
|
3
|
+
|
|
4
|
+
type BSTBaseOptions<K, V, R> = Omit<BinaryTreeOptions<K, V, R>, 'isDuplicate'>;
|
|
5
|
+
|
|
6
|
+
export type BSTOptions<K, V, R> = BSTBaseOptions<K, V, R> & {
|
|
7
|
+
comparator?: Comparator<K>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type BSTNOptKey<K> = K | undefined;
|
|
11
|
+
|
|
12
|
+
export type OptNode<NODE> = NODE | undefined;
|
|
13
|
+
|
|
14
|
+
export type BSTNEntry<K, V> = [BSTNOptKey<K>, OptValue<V>];
|
|
15
|
+
|
|
16
|
+
export type BSTNOptKeyOrNode<K, NODE> = BSTNOptKey<K> | NODE;
|
|
17
|
+
|
|
18
|
+
export type BSTNRep<K, V, NODE> = BSTNEntry<K, V> | BSTNOptKeyOrNode<K, NODE>;
|
|
19
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './binary-tree';
|
|
2
|
+
export * from './bst';
|
|
3
|
+
export * from './avl-tree';
|
|
4
|
+
export * from './segment-tree';
|
|
5
|
+
export * from './avl-tree-multi-map';
|
|
6
|
+
export * from './red-black-tree';
|
|
7
|
+
export * from './tree-multi-map';
|
|
8
|
+
export * from './tree-counter';
|
|
9
|
+
export * from './avl-tree-counter';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SegmentTreeNodeVal = number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type VertexKey = string | number;
|
|
2
|
+
|
|
3
|
+
export type DijkstraResult<V> =
|
|
4
|
+
| {
|
|
5
|
+
distMap: Map<V, number>;
|
|
6
|
+
distPaths?: Map<V, V[]>;
|
|
7
|
+
preMap: Map<V, V | undefined>;
|
|
8
|
+
seen: Set<V>;
|
|
9
|
+
paths: V[][];
|
|
10
|
+
minDist: number;
|
|
11
|
+
minPath: V[];
|
|
12
|
+
}
|
|
13
|
+
| undefined;
|
|
14
|
+
|
|
15
|
+
export type GraphOptions<V = any> = {
|
|
16
|
+
vertexValueInitializer?: (key: VertexKey) => V;
|
|
17
|
+
defaultEdgeWeight?: number;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MapGraphCoordinate = [number, number];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type HashMapLinkedNode<K, V> = {
|
|
2
|
+
key: K;
|
|
3
|
+
value: V;
|
|
4
|
+
next: HashMapLinkedNode<K, V>;
|
|
5
|
+
prev: HashMapLinkedNode<K, V>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type LinkedHashMapOptions<K, V, R> = {
|
|
9
|
+
hashFn?: (key: K) => string;
|
|
10
|
+
objHashFn?: (key: K) => object;
|
|
11
|
+
toEntryFn?: (rawElement: R) => [K, V];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type HashMapOptions<K, V, R> = {
|
|
15
|
+
hashFn?: (key: K) => string;
|
|
16
|
+
toEntryFn?: (rawElement: R) => [K, V];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type HashMapStoreItem<K, V> = { key: K; value: V };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './heap';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './binary-tree';
|
|
2
|
+
export * from './graph';
|
|
3
|
+
export * from './linked-list';
|
|
4
|
+
export * from './heap';
|
|
5
|
+
export * from './matrix';
|
|
6
|
+
export * from './hash';
|
|
7
|
+
export * from './priority-queue';
|
|
8
|
+
export * from './queue';
|
|
9
|
+
export * from './stack';
|
|
10
|
+
export * from './tree';
|
|
11
|
+
export * from './trie';
|
|
12
|
+
export * from './base';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SkipLinkedListOptions = { maxLevel?: number; probability?: number };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Direction = 'up' | 'right' | 'down' | 'left';
|
|
2
|
+
|
|
3
|
+
export type Turning = { [key in Direction]: Direction };
|
|
4
|
+
|
|
5
|
+
export type NavigatorParams<T = any> = {
|
|
6
|
+
matrix: T[][];
|
|
7
|
+
turning: Turning;
|
|
8
|
+
onMove: (cur: [number, number]) => void;
|
|
9
|
+
init: {
|
|
10
|
+
cur: [number, number];
|
|
11
|
+
charDir: Direction;
|
|
12
|
+
VISITED: T;
|
|
13
|
+
};
|
|
14
|
+
};
|