semantic-typescript 0.4.1 → 0.5.3
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/dist/collector.d.ts +3 -9
- package/dist/collector.js +3 -22
- package/dist/factory.d.ts +72 -14
- package/dist/factory.js +441 -71
- package/dist/guard.d.ts +6 -10
- package/dist/guard.js +21 -20
- package/dist/hash.d.ts +1 -2
- package/dist/hash.js +9 -15
- package/dist/hook.d.ts +5 -1
- package/dist/hook.js +72 -19
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -6
- package/dist/main.d.ts +1 -0
- package/dist/main.js +4 -0
- package/dist/map.d.ts +4 -0
- package/dist/map.js +4 -6
- package/dist/node.d.ts +182 -0
- package/dist/node.js +918 -0
- package/dist/optional.d.ts +6 -3
- package/dist/optional.js +30 -8
- package/dist/semantic.d.ts +204 -4
- package/dist/semantic.js +1135 -13
- package/dist/set.js +1 -0
- package/dist/symbol.d.ts +1 -8
- package/dist/symbol.js +1 -8
- package/dist/tree.d.ts +82 -0
- package/dist/tree.js +257 -0
- package/dist/utility.d.ts +1 -1
- package/package.json +1 -1
- package/readme.md +492 -282
- package/dist/collectable.d.ts +0 -96
- package/dist/collectable.js +0 -554
- package/dist/statistics.d.ts +0 -97
- package/dist/statistics.js +0 -483
- package/dist/window.d.ts +0 -12
- package/dist/window.js +0 -72
package/dist/set.js
CHANGED
package/dist/symbol.d.ts
CHANGED
|
@@ -7,12 +7,5 @@ export declare let WindowCollectableSymbol: symbol;
|
|
|
7
7
|
export declare let StatisticsSymbol: symbol;
|
|
8
8
|
export declare let NumericStatisticsSymbol: symbol;
|
|
9
9
|
export declare let BigIntStatisticsSymbol: symbol;
|
|
10
|
+
export declare let AsyncCollectableSymbol: symbol;
|
|
10
11
|
export declare let UnorderedCollectableSymbol: symbol;
|
|
11
|
-
export declare let SemanticMapSymbol: symbol;
|
|
12
|
-
export declare let HashMapSymbol: symbol;
|
|
13
|
-
export declare let HashSetSymbol: symbol;
|
|
14
|
-
export declare let TreeMapSymbol: symbol;
|
|
15
|
-
export declare let TreeSetSymbol: symbol;
|
|
16
|
-
export declare let BinaryNodeSymbol: symbol;
|
|
17
|
-
export declare let ReadBlackNodeSymbol: symbol;
|
|
18
|
-
export declare let HashableSymbol: symbol;
|
package/dist/symbol.js
CHANGED
|
@@ -7,12 +7,5 @@ export let WindowCollectableSymbol = Symbol.for("WindowCollectable");
|
|
|
7
7
|
export let StatisticsSymbol = Symbol.for("Statistics");
|
|
8
8
|
export let NumericStatisticsSymbol = Symbol.for("NumericStatistics");
|
|
9
9
|
export let BigIntStatisticsSymbol = Symbol.for("BigIntStatistics");
|
|
10
|
+
export let AsyncCollectableSymbol = Symbol.for("AsyncCollectable");
|
|
10
11
|
export let UnorderedCollectableSymbol = Symbol.for("UnorderedCollectable");
|
|
11
|
-
export let SemanticMapSymbol = Symbol.for("SemanticMap");
|
|
12
|
-
export let HashMapSymbol = Symbol.for("HashMap");
|
|
13
|
-
export let HashSetSymbol = Symbol.for("HashSet");
|
|
14
|
-
export let TreeMapSymbol = Symbol.for("TreeMap");
|
|
15
|
-
export let TreeSetSymbol = Symbol.for("TreeSet");
|
|
16
|
-
export let BinaryNodeSymbol = Symbol.for("BinaryNode");
|
|
17
|
-
export let ReadBlackNodeSymbol = Symbol.for("BlackAndRedNode");
|
|
18
|
-
export let HashableSymbol = Symbol.for("hashable");
|
package/dist/tree.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { BinaryNode, RedBlackNode, type Node } from './node';
|
|
2
|
+
import { Optional } from './optional';
|
|
3
|
+
import { type Comparator } from './utility';
|
|
4
|
+
export interface Tree<E, N extends Node<E, N>, T extends Tree<E, N, T>> extends Iterable<E> {
|
|
5
|
+
root(): Optional<N>;
|
|
6
|
+
isEmpty(): boolean;
|
|
7
|
+
size(): bigint;
|
|
8
|
+
height(): bigint;
|
|
9
|
+
depth(): bigint;
|
|
10
|
+
width(): bigint;
|
|
11
|
+
level(): bigint;
|
|
12
|
+
add(value: E): void;
|
|
13
|
+
remove(value: E): void;
|
|
14
|
+
contains(value: E): boolean;
|
|
15
|
+
find(value: E): Optional<N>;
|
|
16
|
+
preorder(): Generator<E>;
|
|
17
|
+
inorder(): Generator<E>;
|
|
18
|
+
postorder(): Generator<E>;
|
|
19
|
+
breadth(): Generator<E>;
|
|
20
|
+
toArray(): Array<E>;
|
|
21
|
+
toSet(): Set<E>;
|
|
22
|
+
sub(node: N): T;
|
|
23
|
+
prune(node: Node<E, N>): T;
|
|
24
|
+
merge(other: T): T;
|
|
25
|
+
[Symbol.iterator](): Iterator<E>;
|
|
26
|
+
}
|
|
27
|
+
export declare abstract class AbstractTree<E, N extends Node<E, N>, T extends Tree<E, N, T>> implements Tree<E, N, T> {
|
|
28
|
+
protected readonly Tree: symbol;
|
|
29
|
+
protected internal: bigint;
|
|
30
|
+
constructor();
|
|
31
|
+
abstract root(): Optional<N>;
|
|
32
|
+
isEmpty(): boolean;
|
|
33
|
+
size(): bigint;
|
|
34
|
+
abstract add(value: E): void;
|
|
35
|
+
abstract remove(value: E): void;
|
|
36
|
+
contains(value: E): boolean;
|
|
37
|
+
abstract find(value: E): Optional<N>;
|
|
38
|
+
abstract preorder(): Generator<E>;
|
|
39
|
+
abstract inorder(): Generator<E>;
|
|
40
|
+
abstract postorder(): Generator<E>;
|
|
41
|
+
abstract breadth(): Generator<E>;
|
|
42
|
+
toArray(): Array<E>;
|
|
43
|
+
toSet(): Set<E>;
|
|
44
|
+
abstract sub(node: N): T;
|
|
45
|
+
abstract prune(node: Node<E, N>): T;
|
|
46
|
+
abstract merge(other: T): T;
|
|
47
|
+
height(): bigint;
|
|
48
|
+
width(): bigint;
|
|
49
|
+
depth(): bigint;
|
|
50
|
+
level(): bigint;
|
|
51
|
+
abstract [Symbol.iterator](): Iterator<E>;
|
|
52
|
+
}
|
|
53
|
+
export declare abstract class BinaryTree<E, N extends BinaryNode<E, N>, T extends BinaryTree<E, N, T>> extends AbstractTree<E, N, T> {
|
|
54
|
+
protected readonly BinaryTree: symbol;
|
|
55
|
+
protected first: Optional<N>;
|
|
56
|
+
constructor();
|
|
57
|
+
constructor(root: Optional<N>);
|
|
58
|
+
root(): Optional<N>;
|
|
59
|
+
find(value: E): Optional<N>;
|
|
60
|
+
preorder(): Generator<E>;
|
|
61
|
+
inorder(): Generator<E>;
|
|
62
|
+
postorder(): Generator<E>;
|
|
63
|
+
isBalanced(): boolean;
|
|
64
|
+
isComplete(): boolean;
|
|
65
|
+
isFull(): boolean;
|
|
66
|
+
isPerfect(): boolean;
|
|
67
|
+
[Symbol.iterator](): Iterator<E>;
|
|
68
|
+
}
|
|
69
|
+
export declare class RedBlackTree<E> extends BinaryTree<E, RedBlackNode<E>, RedBlackTree<E>> {
|
|
70
|
+
protected readonly RedBlackTree: symbol;
|
|
71
|
+
protected comparator: Comparator<E>;
|
|
72
|
+
constructor();
|
|
73
|
+
constructor(root: Optional<RedBlackNode<E>>);
|
|
74
|
+
constructor(comparator: Comparator<E>);
|
|
75
|
+
constructor(root: Optional<RedBlackNode<E>>, comparator: Comparator<E>);
|
|
76
|
+
add(value: E): void;
|
|
77
|
+
remove(value: E): void;
|
|
78
|
+
breadth(): Generator<E>;
|
|
79
|
+
sub(node: RedBlackNode<E>): RedBlackTree<E>;
|
|
80
|
+
prune(node: Node<E, RedBlackNode<E>>): RedBlackTree<E>;
|
|
81
|
+
merge(other: RedBlackTree<E>): RedBlackTree<E>;
|
|
82
|
+
}
|
package/dist/tree.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { isFunction, isRedBlackNode } from './guard';
|
|
2
|
+
import { useCompare } from './hook';
|
|
3
|
+
import { BinaryNode, RedBlackNode } from './node';
|
|
4
|
+
import { Optional } from './optional';
|
|
5
|
+
import { BinaryTreeSymbol, TreeSymbol } from './symbol';
|
|
6
|
+
import { validate } from './utility';
|
|
7
|
+
export class AbstractTree {
|
|
8
|
+
Tree = TreeSymbol;
|
|
9
|
+
internal = 0n;
|
|
10
|
+
constructor() {
|
|
11
|
+
}
|
|
12
|
+
isEmpty() {
|
|
13
|
+
return this.root().isEmpty();
|
|
14
|
+
}
|
|
15
|
+
size() {
|
|
16
|
+
return this.internal;
|
|
17
|
+
}
|
|
18
|
+
contains(value) {
|
|
19
|
+
return this.find(value).isPresent();
|
|
20
|
+
}
|
|
21
|
+
toArray() {
|
|
22
|
+
return Array.from(this.preorder());
|
|
23
|
+
}
|
|
24
|
+
toSet() {
|
|
25
|
+
return new Set(this.preorder());
|
|
26
|
+
}
|
|
27
|
+
height() {
|
|
28
|
+
let root = this.root();
|
|
29
|
+
if (root.isPresent()) {
|
|
30
|
+
return root.get().height();
|
|
31
|
+
}
|
|
32
|
+
return 0n;
|
|
33
|
+
}
|
|
34
|
+
width() {
|
|
35
|
+
let root = this.root();
|
|
36
|
+
if (root.isPresent()) {
|
|
37
|
+
return root.get().width();
|
|
38
|
+
}
|
|
39
|
+
return 0n;
|
|
40
|
+
}
|
|
41
|
+
depth() {
|
|
42
|
+
let root = this.root();
|
|
43
|
+
if (root.isPresent()) {
|
|
44
|
+
return root.get().depth();
|
|
45
|
+
}
|
|
46
|
+
return 0n;
|
|
47
|
+
}
|
|
48
|
+
level() {
|
|
49
|
+
let root = this.root();
|
|
50
|
+
if (root.isPresent()) {
|
|
51
|
+
return root.get().level();
|
|
52
|
+
}
|
|
53
|
+
return 0n;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
;
|
|
57
|
+
export class BinaryTree extends AbstractTree {
|
|
58
|
+
BinaryTree = BinaryTreeSymbol;
|
|
59
|
+
first;
|
|
60
|
+
constructor(root = Optional.empty()) {
|
|
61
|
+
super();
|
|
62
|
+
this.first = root;
|
|
63
|
+
}
|
|
64
|
+
root() {
|
|
65
|
+
return this.first;
|
|
66
|
+
}
|
|
67
|
+
find(value) {
|
|
68
|
+
let root = this.root();
|
|
69
|
+
if (root.isPresent()) {
|
|
70
|
+
for (let node of root.get().preorder()) {
|
|
71
|
+
if (node.getElement() === value || Object.is(node.getElement(), value)) {
|
|
72
|
+
return Optional.of(node);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return Optional.empty();
|
|
77
|
+
}
|
|
78
|
+
*preorder() {
|
|
79
|
+
let root = this.root();
|
|
80
|
+
if (root.isPresent()) {
|
|
81
|
+
for (let node of root.get().preorder()) {
|
|
82
|
+
let element = node.getElement();
|
|
83
|
+
if (validate(element) && element.isPresent()) {
|
|
84
|
+
yield element.get();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
*inorder() {
|
|
90
|
+
let root = this.root();
|
|
91
|
+
if (root.isPresent()) {
|
|
92
|
+
for (let node of root.get().inorder()) {
|
|
93
|
+
let element = node.getElement();
|
|
94
|
+
if (validate(element) && element.isPresent()) {
|
|
95
|
+
yield element.get();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
*postorder() {
|
|
101
|
+
let root = this.root();
|
|
102
|
+
if (root.isPresent()) {
|
|
103
|
+
for (let node of root.get().postorder()) {
|
|
104
|
+
let element = node.getElement();
|
|
105
|
+
if (validate(element) && element.isPresent()) {
|
|
106
|
+
yield element.get();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
isBalanced() {
|
|
112
|
+
let root = this.root();
|
|
113
|
+
if (root.isPresent()) {
|
|
114
|
+
return root.get().isBanlanced();
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
isComplete() {
|
|
119
|
+
let root = this.root();
|
|
120
|
+
if (root.isPresent()) {
|
|
121
|
+
return root.get().isComplete();
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
isFull() {
|
|
126
|
+
let root = this.root();
|
|
127
|
+
if (root.isPresent()) {
|
|
128
|
+
return root.get().isFull();
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
isPerfect() {
|
|
133
|
+
let root = this.root();
|
|
134
|
+
if (root.isPresent()) {
|
|
135
|
+
return root.get().isPerfect();
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
*[Symbol.iterator]() {
|
|
140
|
+
yield* this.preorder();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
;
|
|
144
|
+
export class RedBlackTree extends BinaryTree {
|
|
145
|
+
RedBlackTree = Symbol("RedBlackTree");
|
|
146
|
+
comparator;
|
|
147
|
+
constructor(argument1, argument2) {
|
|
148
|
+
if (isFunction(argument1)) {
|
|
149
|
+
super();
|
|
150
|
+
this.comparator = argument1;
|
|
151
|
+
}
|
|
152
|
+
else if (isRedBlackNode(argument1)) {
|
|
153
|
+
super(argument1);
|
|
154
|
+
if (isFunction(argument2)) {
|
|
155
|
+
this.comparator = argument2;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.comparator = useCompare;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
throw new TypeError("Invalid arguments.");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
add(value) {
|
|
166
|
+
let node = new RedBlackNode(value);
|
|
167
|
+
if (this.first.isEmpty()) {
|
|
168
|
+
this.first = Optional.of(node);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.first.get().compareAndLink(node);
|
|
172
|
+
}
|
|
173
|
+
this.internal++;
|
|
174
|
+
}
|
|
175
|
+
remove(value) {
|
|
176
|
+
let node = this.find(value);
|
|
177
|
+
if (node.isPresent()) {
|
|
178
|
+
node.get().detach();
|
|
179
|
+
node.get().fix();
|
|
180
|
+
this.internal--;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
*breadth() {
|
|
184
|
+
let root = this.root();
|
|
185
|
+
if (root.isPresent()) {
|
|
186
|
+
let queue = [root.get()];
|
|
187
|
+
while (queue.length > 0) {
|
|
188
|
+
let node = queue.shift();
|
|
189
|
+
let element = node.getElement();
|
|
190
|
+
if (validate(element) && element.isPresent()) {
|
|
191
|
+
yield element.get();
|
|
192
|
+
}
|
|
193
|
+
if (validate(node.getLeft()) && node.getRight().isPresent()) {
|
|
194
|
+
queue.push(node.getLeft().get());
|
|
195
|
+
}
|
|
196
|
+
if (validate(node.getLeft()) && node.getLeft().isPresent()) {
|
|
197
|
+
queue.push(node.getLeft().get());
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
sub(node) {
|
|
203
|
+
return new RedBlackTree(Optional.of(node));
|
|
204
|
+
}
|
|
205
|
+
prune(node) {
|
|
206
|
+
let tree = new RedBlackTree();
|
|
207
|
+
let queue = [node];
|
|
208
|
+
while (queue.length > 0) {
|
|
209
|
+
let node = queue.shift();
|
|
210
|
+
let element = node.getElement();
|
|
211
|
+
if (validate(element) && element.isPresent()) {
|
|
212
|
+
tree.add(element.get());
|
|
213
|
+
}
|
|
214
|
+
if (validate(node.getLeft()) && node.getLeft().isPresent()) {
|
|
215
|
+
queue.push(node.getLeft().get());
|
|
216
|
+
}
|
|
217
|
+
if (validate(node.getRight()) && node.getRight().isPresent()) {
|
|
218
|
+
queue.push(node.getRight().get());
|
|
219
|
+
}
|
|
220
|
+
return tree;
|
|
221
|
+
}
|
|
222
|
+
return tree;
|
|
223
|
+
}
|
|
224
|
+
merge(other) {
|
|
225
|
+
let tree = new RedBlackTree();
|
|
226
|
+
let queue = [this.root().get()];
|
|
227
|
+
while (queue.length > 0) {
|
|
228
|
+
let node = queue.shift();
|
|
229
|
+
let element = node.getElement();
|
|
230
|
+
if (validate(element) && element.isPresent()) {
|
|
231
|
+
tree.add(element.get());
|
|
232
|
+
}
|
|
233
|
+
if (validate(node.getLeft()) && node.getLeft().isPresent()) {
|
|
234
|
+
queue.push(node.getLeft().get());
|
|
235
|
+
}
|
|
236
|
+
if (validate(node.getRight()) && node.getRight().isPresent()) {
|
|
237
|
+
queue.push(node.getRight().get());
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
queue = [other.root().get()];
|
|
241
|
+
while (queue.length > 0) {
|
|
242
|
+
let node = queue.shift();
|
|
243
|
+
let element = node.getElement();
|
|
244
|
+
if (validate(element) && element.isPresent()) {
|
|
245
|
+
tree.add(element.get());
|
|
246
|
+
}
|
|
247
|
+
if (validate(node.getLeft()) && node.getLeft().isPresent()) {
|
|
248
|
+
queue.push(node.getLeft().get());
|
|
249
|
+
}
|
|
250
|
+
if (validate(node.getRight()) && node.getRight().isPresent()) {
|
|
251
|
+
queue.push(node.getRight().get());
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return tree;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
;
|
package/dist/utility.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type Invalid<T> = T extends null | undefined ? T : never;
|
|
2
|
-
export type Valid<T> = T extends null | undefined ? never : T;
|
|
2
|
+
export type Valid<T> = T extends (null | undefined) ? never : T;
|
|
3
3
|
export type MaybeInvalid<T> = T | null | undefined;
|
|
4
4
|
export type MaybeUndefined<T> = T | undefined;
|
|
5
5
|
export type MaybeNull<T> = T | null;
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "https://github.com/eloyhere"
|
|
7
7
|
},
|
|
8
8
|
"description": "A modern type-safe stream processing library inspired by JavaScript Generator, Java Stream, and MySQL Index. Supports lazy evaluation, async streams, statistics, and IO-like operations.",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.5.3",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"readme": "readme.md",
|
|
12
12
|
"main": "dist/index.js",
|