data-structure-typed 0.8.6
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/.idea/data-structure-typed.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +2 -0
- package/dist/data-structures/binary-tree/aa-tree.js +6 -0
- package/dist/data-structures/binary-tree/avl-tree.js +231 -0
- package/dist/data-structures/binary-tree/b-tree.js +6 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +31 -0
- package/dist/data-structures/binary-tree/binary-tree.js +992 -0
- package/dist/data-structures/binary-tree/bst.js +431 -0
- package/dist/data-structures/binary-tree/index.js +20 -0
- package/dist/data-structures/binary-tree/rb-tree.js +6 -0
- package/dist/data-structures/binary-tree/segment-tree.js +151 -0
- package/dist/data-structures/binary-tree/splay-tree.js +6 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +16 -0
- package/dist/data-structures/binary-tree/two-three-tree.js +6 -0
- package/dist/data-structures/graph/abstract-graph.js +648 -0
- package/dist/data-structures/graph/directed-graph.js +268 -0
- package/dist/data-structures/graph/index.js +19 -0
- package/dist/data-structures/graph/undirected-graph.js +142 -0
- package/dist/data-structures/hash/coordinate-map.js +24 -0
- package/dist/data-structures/hash/coordinate-set.js +21 -0
- package/dist/data-structures/hash/hash-table.js +2 -0
- package/dist/data-structures/hash/index.js +17 -0
- package/dist/data-structures/hash/pair.js +2 -0
- package/dist/data-structures/hash/tree-map.js +2 -0
- package/dist/data-structures/hash/tree-set.js +2 -0
- package/dist/data-structures/heap/heap.js +114 -0
- package/dist/data-structures/heap/index.js +19 -0
- package/dist/data-structures/heap/max-heap.js +22 -0
- package/dist/data-structures/heap/min-heap.js +22 -0
- package/dist/data-structures/index.js +25 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +259 -0
- package/dist/data-structures/linked-list/index.js +18 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +660 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +2 -0
- package/dist/data-structures/matrix/index.js +19 -0
- package/dist/data-structures/matrix/matrix.js +14 -0
- package/dist/data-structures/matrix/matrix2d.js +119 -0
- package/dist/data-structures/matrix/navigator.js +78 -0
- package/dist/data-structures/matrix/vector2d.js +161 -0
- package/dist/data-structures/priority-queue/index.js +19 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +15 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +15 -0
- package/dist/data-structures/priority-queue/priority-queue.js +174 -0
- package/dist/data-structures/queue/deque.js +132 -0
- package/dist/data-structures/queue/index.js +17 -0
- package/dist/data-structures/queue/queue.js +113 -0
- package/dist/data-structures/stack/index.js +17 -0
- package/dist/data-structures/stack/stack.js +97 -0
- package/dist/data-structures/trampoline.js +52 -0
- package/dist/data-structures/trie/index.js +17 -0
- package/dist/data-structures/trie/trie.js +141 -0
- package/dist/index.js +17 -0
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +21 -0
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +140 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +32 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +4 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +33 -0
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +11 -0
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +2 -0
- package/dist/types/data-structures/graph/abstract-graph.d.ts +126 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +51 -0
- package/dist/types/data-structures/graph/index.d.ts +3 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +24 -0
- package/dist/types/data-structures/hash/coordinate-map.d.ts +8 -0
- package/dist/types/data-structures/hash/coordinate-set.d.ts +7 -0
- package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
- package/dist/types/data-structures/hash/index.d.ts +1 -0
- package/dist/types/data-structures/hash/pair.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
- package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
- package/dist/types/data-structures/heap/heap.d.ts +72 -0
- package/dist/types/data-structures/heap/index.d.ts +3 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +14 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +14 -0
- package/dist/types/data-structures/index.d.ts +9 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +59 -0
- package/dist/types/data-structures/linked-list/index.d.ts +2 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +358 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
- package/dist/types/data-structures/matrix/index.d.ts +3 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +9 -0
- package/dist/types/data-structures/matrix/matrix2d.d.ts +25 -0
- package/dist/types/data-structures/matrix/navigator.d.ts +31 -0
- package/dist/types/data-structures/matrix/vector2d.d.ts +74 -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 +4 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +4 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +36 -0
- package/dist/types/data-structures/queue/deque.d.ts +37 -0
- package/dist/types/data-structures/queue/index.d.ts +1 -0
- package/dist/types/data-structures/queue/queue.d.ts +76 -0
- package/dist/types/data-structures/stack/index.d.ts +1 -0
- package/dist/types/data-structures/stack/stack.d.ts +69 -0
- package/dist/types/data-structures/trampoline.d.ts +25 -0
- package/dist/types/data-structures/trie/index.d.ts +1 -0
- package/dist/types/data-structures/trie/trie.d.ts +28 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +17 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/utils.d.ts +46 -0
- package/dist/types/utils.d.ts +122 -0
- package/dist/types/utils.js +53 -0
- package/dist/utils.js +569 -0
- package/package.json +75 -0
- package/src/data-structures/binary-tree/aa-tree.ts +3 -0
- package/src/data-structures/binary-tree/avl-tree.ts +232 -0
- package/src/data-structures/binary-tree/b-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +33 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1088 -0
- package/src/data-structures/binary-tree/bst.ts +404 -0
- package/src/data-structures/binary-tree/index.ts +4 -0
- package/src/data-structures/binary-tree/rb-tree.ts +3 -0
- package/src/data-structures/binary-tree/segment-tree.ts +164 -0
- package/src/data-structures/binary-tree/splay-tree.ts +3 -0
- package/src/data-structures/binary-tree/tree-multiset.ts +21 -0
- package/src/data-structures/binary-tree/two-three-tree.ts +3 -0
- package/src/data-structures/graph/abstract-graph.ts +789 -0
- package/src/data-structures/graph/directed-graph.ts +322 -0
- package/src/data-structures/graph/index.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +154 -0
- package/src/data-structures/hash/coordinate-map.ts +24 -0
- package/src/data-structures/hash/coordinate-set.ts +20 -0
- package/src/data-structures/hash/hash-table.ts +1 -0
- package/src/data-structures/hash/index.ts +1 -0
- package/src/data-structures/hash/pair.ts +1 -0
- package/src/data-structures/hash/tree-map.ts +1 -0
- package/src/data-structures/hash/tree-set.ts +1 -0
- package/src/data-structures/heap/heap.ts +136 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +22 -0
- package/src/data-structures/heap/min-heap.ts +24 -0
- package/src/data-structures/index.ts +10 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +258 -0
- package/src/data-structures/linked-list/index.ts +2 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +750 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -0
- package/src/data-structures/matrix/index.ts +3 -0
- package/src/data-structures/matrix/matrix.ts +13 -0
- package/src/data-structures/matrix/matrix2d.ts +125 -0
- package/src/data-structures/matrix/navigator.ts +99 -0
- package/src/data-structures/matrix/vector2d.ts +189 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +12 -0
- package/src/data-structures/priority-queue/priority-queue.ts +208 -0
- package/src/data-structures/queue/deque.ts +139 -0
- package/src/data-structures/queue/index.ts +1 -0
- package/src/data-structures/queue/queue.ts +123 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +104 -0
- package/src/data-structures/trampoline.ts +91 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +153 -0
- package/src/index.ts +1 -0
- package/src/types/index.ts +1 -0
- package/src/types/patches/index.d.ts +0 -0
- package/src/types/utils.ts +158 -0
- package/src/utils.ts +605 -0
- package/tsconfig.json +52 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
export type AnyFunction<A extends any[] = any[], R = any> = (...args: A) => R;
|
|
2
|
+
export type Primitive =
|
|
3
|
+
| number
|
|
4
|
+
| string
|
|
5
|
+
| boolean
|
|
6
|
+
| symbol
|
|
7
|
+
| undefined
|
|
8
|
+
| null
|
|
9
|
+
| void
|
|
10
|
+
| AnyFunction
|
|
11
|
+
| Date;
|
|
12
|
+
|
|
13
|
+
export type Cast<T, TComplex> = { [M in keyof TComplex]: T };
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export type DeepLeavesWrap<T, TComplex> =
|
|
17
|
+
T extends string ? Cast<string, TComplex>
|
|
18
|
+
: T extends number ? Cast<number, TComplex>
|
|
19
|
+
: T extends boolean ? Cast<boolean, TComplex>
|
|
20
|
+
: T extends undefined ? Cast<undefined, TComplex>
|
|
21
|
+
: T extends null ? Cast<null, TComplex>
|
|
22
|
+
: T extends void ? Cast<void, TComplex>
|
|
23
|
+
: T extends symbol ? Cast<symbol, TComplex>
|
|
24
|
+
: T extends AnyFunction ? Cast<AnyFunction, TComplex>
|
|
25
|
+
: T extends Date ? Cast<Date, TComplex>
|
|
26
|
+
: {
|
|
27
|
+
[K in keyof T]:
|
|
28
|
+
T[K] extends (infer U)[] ? DeepLeavesWrap<U, TComplex>[]
|
|
29
|
+
: DeepLeavesWrap<T[K], TComplex>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
type Json = null | string | number | boolean | Json [] | { [name: string]: Json }
|
|
34
|
+
|
|
35
|
+
export type JSONSerializable = {
|
|
36
|
+
[key: string]: any
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type JSONValue = string | number | boolean | undefined | JSONObject;
|
|
40
|
+
|
|
41
|
+
export interface JSONObject {
|
|
42
|
+
[key: string]: JSONValue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type TypeName<T> = T extends string
|
|
46
|
+
? 'string'
|
|
47
|
+
: T extends number
|
|
48
|
+
? 'number'
|
|
49
|
+
: T extends boolean
|
|
50
|
+
? 'boolean'
|
|
51
|
+
: T extends undefined
|
|
52
|
+
? 'undefined'
|
|
53
|
+
: T extends AnyFunction
|
|
54
|
+
? 'function'
|
|
55
|
+
: 'object';
|
|
56
|
+
|
|
57
|
+
export type JsonKeys<T> = keyof {
|
|
58
|
+
[P in keyof T]: number
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const arr = ['1', 2, 4, 5, 6] as const;
|
|
62
|
+
type Range = typeof arr[number];
|
|
63
|
+
const a: Range = 2;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A function that emits a side effect and does not return anything.
|
|
68
|
+
*/
|
|
69
|
+
export type Procedure = (...args: any[]) => void;
|
|
70
|
+
|
|
71
|
+
export type DebounceOptions = {
|
|
72
|
+
isImmediate?: boolean;
|
|
73
|
+
maxWait?: number;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export interface DebouncedFunction<F extends Procedure> {
|
|
77
|
+
(this: ThisParameterType<F>, ...args: Parameters<F>): void;
|
|
78
|
+
|
|
79
|
+
cancel: () => void;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type MonthKey =
|
|
83
|
+
'January' |
|
|
84
|
+
'February' |
|
|
85
|
+
'March' |
|
|
86
|
+
'April' |
|
|
87
|
+
'May' |
|
|
88
|
+
'June' |
|
|
89
|
+
'July' |
|
|
90
|
+
'August' |
|
|
91
|
+
'September' |
|
|
92
|
+
'October' |
|
|
93
|
+
'November' |
|
|
94
|
+
'December';
|
|
95
|
+
|
|
96
|
+
export type Month = { [key in MonthKey]: string }
|
|
97
|
+
|
|
98
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
99
|
+
|
|
100
|
+
export class TreeNode<T> {
|
|
101
|
+
id: string;
|
|
102
|
+
name?: string | undefined;
|
|
103
|
+
value?: T | undefined;
|
|
104
|
+
children?: TreeNode<T>[] | undefined;
|
|
105
|
+
|
|
106
|
+
constructor(id: string, name?: string, value?: T, children?: TreeNode<T>[]) {
|
|
107
|
+
this.id = id;
|
|
108
|
+
this.name = name || '';
|
|
109
|
+
this.value = value || undefined;
|
|
110
|
+
this.children = children || [];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// TODO get set
|
|
114
|
+
// get name (): string | undefined {
|
|
115
|
+
// return this.name;
|
|
116
|
+
// }
|
|
117
|
+
//
|
|
118
|
+
// set name (name: string | undefined) {
|
|
119
|
+
// this.name = name;
|
|
120
|
+
// }
|
|
121
|
+
|
|
122
|
+
addChildren(children: TreeNode<T> | TreeNode<T> []) {
|
|
123
|
+
if (!this.children) {
|
|
124
|
+
this.children = [];
|
|
125
|
+
}
|
|
126
|
+
if (children instanceof Array) {
|
|
127
|
+
this.children = this.children.concat(children);
|
|
128
|
+
} else {
|
|
129
|
+
this.children.push(children);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
getHeight() {
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
135
|
+
const beginRoot = this;
|
|
136
|
+
let maxDepth = 1;
|
|
137
|
+
if (beginRoot) {
|
|
138
|
+
const bfs = (node: TreeNode<T>, level: number) => {
|
|
139
|
+
if (level > maxDepth) {
|
|
140
|
+
maxDepth = level;
|
|
141
|
+
}
|
|
142
|
+
const {children} = node;
|
|
143
|
+
if (children) {
|
|
144
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
145
|
+
bfs(children[i], level + 1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
bfs(beginRoot, 1);
|
|
150
|
+
}
|
|
151
|
+
return maxDepth;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export type OrderType = 'InOrder' | 'PreOrder' | 'PostOrder'
|
|
157
|
+
|
|
158
|
+
|