semantic-typescript 0.5.3 → 0.7.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/dist/asynchronous/collector.d.ts +235 -0
- package/dist/asynchronous/collector.js +811 -0
- package/dist/asynchronous/semantic.d.ts +257 -0
- package/dist/asynchronous/semantic.js +1863 -0
- package/dist/factory.d.ts +79 -37
- package/dist/factory.js +534 -277
- package/dist/guard.d.ts +24 -14
- package/dist/guard.js +73 -19
- package/dist/hook.d.ts +11 -6
- package/dist/hook.js +22 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/main.js +6 -4
- package/dist/optional.d.ts +2 -2
- package/dist/symbol.d.ts +19 -10
- package/dist/symbol.js +19 -10
- package/dist/synchronous/collector.d.ts +236 -0
- package/dist/{collector.js → synchronous/collector.js} +217 -193
- package/dist/{semantic.d.ts → synchronous/semantic.d.ts} +125 -130
- package/dist/{semantic.js → synchronous/semantic.js} +465 -574
- package/dist/utility.d.ts +7 -1
- package/dist/utility.js +1 -0
- package/package.json +3 -2
- package/readme.cn.md +213 -753
- package/readme.de.md +171 -441
- package/readme.es.md +171 -436
- package/readme.fr.md +170 -443
- package/readme.jp.md +177 -439
- package/readme.kr.md +177 -433
- package/readme.md +213 -1066
- package/readme.ru.md +174 -420
- package/readme.tw.md +175 -441
- package/dist/collector.d.ts +0 -236
- package/dist/map.d.ts +0 -76
- package/dist/map.js +0 -245
- package/dist/node.d.ts +0 -182
- package/dist/node.js +0 -918
- package/dist/set.d.ts +0 -19
- package/dist/set.js +0 -65
- package/dist/tree.d.ts +0 -82
- package/dist/tree.js +0 -257
package/dist/set.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HashMap } from "./map";
|
|
2
|
-
import type { BiConsumer, Consumer, TriConsumer } from "./utility";
|
|
3
|
-
export declare class HashSet<E> implements Set<E> {
|
|
4
|
-
protected map: HashMap<E, boolean>;
|
|
5
|
-
size: number;
|
|
6
|
-
constructor();
|
|
7
|
-
add(value: E): this;
|
|
8
|
-
clear(): void;
|
|
9
|
-
delete(value: E): boolean;
|
|
10
|
-
entries(): SetIterator<[E, E]>;
|
|
11
|
-
forEach(consumer: Consumer<E>): void;
|
|
12
|
-
forEach(consumer: BiConsumer<E, E>): void;
|
|
13
|
-
forEach(consumer: TriConsumer<E, E, Set<E>>): void;
|
|
14
|
-
has(value: E): boolean;
|
|
15
|
-
keys(): IterableIterator<E>;
|
|
16
|
-
values(): IterableIterator<E>;
|
|
17
|
-
[Symbol.iterator](): IterableIterator<E>;
|
|
18
|
-
[Symbol.toStringTag]: string;
|
|
19
|
-
}
|
package/dist/set.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { HashMap } from "./map";
|
|
2
|
-
export class HashSet {
|
|
3
|
-
map = new HashMap();
|
|
4
|
-
size = 0;
|
|
5
|
-
constructor() {
|
|
6
|
-
Object.defineProperty(this, "size", {
|
|
7
|
-
get: () => this.map.size,
|
|
8
|
-
set: (value) => {
|
|
9
|
-
this.map.size = value;
|
|
10
|
-
},
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true
|
|
13
|
-
});
|
|
14
|
-
Object.freeze(this);
|
|
15
|
-
}
|
|
16
|
-
add(value) {
|
|
17
|
-
this.map.set(value, true);
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
clear() {
|
|
21
|
-
this.map.clear();
|
|
22
|
-
}
|
|
23
|
-
delete(value) {
|
|
24
|
-
return this.map.delete(value);
|
|
25
|
-
}
|
|
26
|
-
*entries() {
|
|
27
|
-
for (let [key, value] of this.map.entries()) {
|
|
28
|
-
if (value) {
|
|
29
|
-
yield [key, key];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
forEach(consumer) {
|
|
34
|
-
for (let [key, value] of this.map.entries()) {
|
|
35
|
-
if (value) {
|
|
36
|
-
consumer(key, key);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
has(value) {
|
|
41
|
-
return this.map.has(value);
|
|
42
|
-
}
|
|
43
|
-
*keys() {
|
|
44
|
-
for (let [key, value] of this.map.entries()) {
|
|
45
|
-
if (value) {
|
|
46
|
-
yield key;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
*values() {
|
|
51
|
-
for (let [key, value] of this.map.entries()) {
|
|
52
|
-
if (value) {
|
|
53
|
-
yield key;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
[Symbol.iterator]() {
|
|
58
|
-
return this.values();
|
|
59
|
-
}
|
|
60
|
-
[Symbol.toStringTag] = "HashSet";
|
|
61
|
-
}
|
|
62
|
-
;
|
|
63
|
-
Object.freeze(HashSet);
|
|
64
|
-
Object.freeze(HashSet.prototype);
|
|
65
|
-
Object.freeze(Object.getPrototypeOf(HashSet));
|
package/dist/tree.d.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
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
|
-
;
|