semantic-typescript 0.4.1 → 0.5.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/collectable.d.ts +108 -2
- package/dist/collectable.js +585 -16
- package/dist/collector.d.ts +3 -0
- package/dist/collector.js +3 -3
- package/dist/factory.d.ts +14 -0
- package/dist/factory.js +159 -1
- package/dist/guard.d.ts +14 -5
- package/dist/guard.js +68 -7
- package/dist/hash.d.ts +1 -2
- package/dist/hash.js +9 -15
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -5
- package/dist/map.d.ts +4 -0
- package/dist/map.js +6 -0
- package/dist/node.d.ts +182 -0
- package/dist/node.js +918 -0
- package/dist/optional.d.ts +3 -0
- package/dist/optional.js +18 -0
- package/dist/semantic.d.ts +1 -3
- package/dist/semantic.js +2 -4
- package/dist/set.js +1 -0
- package/dist/statistics.js +7 -7
- package/dist/symbol.d.ts +8 -2
- package/dist/symbol.js +8 -2
- package/dist/tree.d.ts +82 -0
- package/dist/tree.js +257 -0
- package/package.json +1 -1
package/dist/optional.d.ts
CHANGED
|
@@ -12,6 +12,9 @@ export declare class Optional<T> {
|
|
|
12
12
|
isEmpty(): boolean;
|
|
13
13
|
isPresent(): boolean;
|
|
14
14
|
map<R>(mapper: Functional<T, R>): Optional<R>;
|
|
15
|
+
flat(mapper: Functional<T, Optional<T>>): Optional<T>;
|
|
16
|
+
flatMap<R>(mapper: Functional<T, Optional<R>>): Optional<R>;
|
|
17
|
+
orElse(other: MaybeInvalid<T>): MaybeInvalid<T>;
|
|
15
18
|
semantic(): Semantic<T>;
|
|
16
19
|
static empty<T>(): Optional<T>;
|
|
17
20
|
static of<T>(value: MaybeInvalid<T>): Optional<T>;
|
package/dist/optional.js
CHANGED
|
@@ -62,6 +62,24 @@ export class Optional {
|
|
|
62
62
|
}
|
|
63
63
|
return new Optional(null);
|
|
64
64
|
}
|
|
65
|
+
flat(mapper) {
|
|
66
|
+
if (this.isPresent() && isFunction(mapper)) {
|
|
67
|
+
return mapper(this.value);
|
|
68
|
+
}
|
|
69
|
+
return new Optional(null);
|
|
70
|
+
}
|
|
71
|
+
flatMap(mapper) {
|
|
72
|
+
if (this.isPresent() && isFunction(mapper)) {
|
|
73
|
+
return mapper(this.value);
|
|
74
|
+
}
|
|
75
|
+
return new Optional(null);
|
|
76
|
+
}
|
|
77
|
+
orElse(other) {
|
|
78
|
+
if (this.isPresent()) {
|
|
79
|
+
return this.value;
|
|
80
|
+
}
|
|
81
|
+
return other;
|
|
82
|
+
}
|
|
65
83
|
semantic() {
|
|
66
84
|
if (this.isPresent()) {
|
|
67
85
|
return generate(() => {
|
package/dist/semantic.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Collectable, OrderedCollectable, UnorderedCollectable } from "./collectable";
|
|
2
|
-
import { BigIntStatistics, NumericStatistics } from "./statistics";
|
|
1
|
+
import { BigIntStatistics, Collectable, NumericStatistics, OrderedCollectable, UnorderedCollectable, WindowCollectable } from "./collectable";
|
|
3
2
|
import { type Predicate } from "./utility";
|
|
4
3
|
import type { Generator, Functional, BiFunctional, Consumer, BiConsumer, Comparator, BiPredicate } from "./utility";
|
|
5
|
-
import { WindowCollectable } from "./window";
|
|
6
4
|
export declare class Semantic<E> {
|
|
7
5
|
protected generator: Generator<E>;
|
|
8
6
|
protected readonly Semantic: Symbol;
|
package/dist/semantic.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { Collectable, OrderedCollectable, UnorderedCollectable } from "./collectable";
|
|
1
|
+
import { BigIntStatistics, Collectable, NumericStatistics, OrderedCollectable, UnorderedCollectable, WindowCollectable } from "./collectable";
|
|
2
2
|
import { isBigInt, isCollectable, isFunction, isIterable, isNumber, isSemantic } from "./guard";
|
|
3
3
|
import { useHash } from "./hash";
|
|
4
4
|
import { useCompare } from "./hook";
|
|
5
|
-
import { BigIntStatistics, NumericStatistics } from "./statistics";
|
|
6
5
|
import { SemanticSymbol } from "./symbol";
|
|
7
6
|
import { validate } from "./utility";
|
|
8
|
-
import { WindowCollectable } from "./window";
|
|
9
7
|
export class Semantic {
|
|
10
8
|
generator;
|
|
11
9
|
Semantic = SemanticSymbol;
|
|
@@ -300,7 +298,7 @@ export class Semantic {
|
|
|
300
298
|
return new Semantic((accept, interrupt) => {
|
|
301
299
|
try {
|
|
302
300
|
this.generator((element, index) => {
|
|
303
|
-
accept(element, useHash(
|
|
301
|
+
accept(element, useHash(element, index));
|
|
304
302
|
}, interrupt);
|
|
305
303
|
}
|
|
306
304
|
catch (error) {
|
package/dist/set.js
CHANGED
package/dist/statistics.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OrderedCollectable } from "./collectable";
|
|
2
|
-
import { Collector, useBigIntAverage, useBigIntMedian, useBigIntMode, useBigIntSummate, useBigIntVariance, useFrequency, useNumericAverage, useNumericMedian, useNumericMode, useNumericStandardDeviation, useNumericSummate, useNumericVariance,
|
|
2
|
+
import { Collector, useBigIntAverage, useBigIntMedian, useBigIntMode, useBigIntSummate, useBigIntVariance, useFrequency, useNumericAverage, useNumericMedian, useNumericMode, useNumericStandardDeviation, useNumericSummate, useNumericVariance, useToAsyncGeneratorFunction, useToGeneratorFunction } from "./collector";
|
|
3
3
|
import { isFunction } from "./guard";
|
|
4
4
|
import { useCompare, useToBigInt, useToNumber } from "./hook";
|
|
5
5
|
import { StatisticsSymbol, NumericStatisticsSymbol, BigIntStatisticsSymbol } from "./symbol";
|
|
@@ -19,7 +19,7 @@ export class Statistics extends OrderedCollectable {
|
|
|
19
19
|
}
|
|
20
20
|
*[Symbol.iterator]() {
|
|
21
21
|
try {
|
|
22
|
-
let collector =
|
|
22
|
+
let collector = useToGeneratorFunction();
|
|
23
23
|
yield* collector.collect(this.source());
|
|
24
24
|
}
|
|
25
25
|
catch (error) {
|
|
@@ -28,7 +28,7 @@ export class Statistics extends OrderedCollectable {
|
|
|
28
28
|
}
|
|
29
29
|
async *[Symbol.asyncIterator]() {
|
|
30
30
|
try {
|
|
31
|
-
let collector =
|
|
31
|
+
let collector = useToAsyncGeneratorFunction();
|
|
32
32
|
yield* collector.collect(this.source());
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
@@ -62,7 +62,7 @@ export class NumericStatistics extends Statistics {
|
|
|
62
62
|
}
|
|
63
63
|
*[Symbol.iterator]() {
|
|
64
64
|
try {
|
|
65
|
-
let collector =
|
|
65
|
+
let collector = useToGeneratorFunction();
|
|
66
66
|
yield* collector.collect(this.source());
|
|
67
67
|
}
|
|
68
68
|
catch (error) {
|
|
@@ -71,7 +71,7 @@ export class NumericStatistics extends Statistics {
|
|
|
71
71
|
}
|
|
72
72
|
async *[Symbol.asyncIterator]() {
|
|
73
73
|
try {
|
|
74
|
-
let collector =
|
|
74
|
+
let collector = useToAsyncGeneratorFunction();
|
|
75
75
|
yield* collector.collect(this.source());
|
|
76
76
|
}
|
|
77
77
|
catch (error) {
|
|
@@ -281,7 +281,7 @@ export class BigIntStatistics extends Statistics {
|
|
|
281
281
|
}
|
|
282
282
|
*[Symbol.iterator]() {
|
|
283
283
|
try {
|
|
284
|
-
let collector =
|
|
284
|
+
let collector = useToGeneratorFunction();
|
|
285
285
|
yield* collector.collect(this.source());
|
|
286
286
|
}
|
|
287
287
|
catch (error) {
|
|
@@ -290,7 +290,7 @@ export class BigIntStatistics extends Statistics {
|
|
|
290
290
|
}
|
|
291
291
|
async *[Symbol.asyncIterator]() {
|
|
292
292
|
try {
|
|
293
|
-
let collector =
|
|
293
|
+
let collector = useToAsyncGeneratorFunction();
|
|
294
294
|
yield* collector.collect(this.source());
|
|
295
295
|
}
|
|
296
296
|
catch (error) {
|
package/dist/symbol.d.ts
CHANGED
|
@@ -13,6 +13,12 @@ export declare let HashMapSymbol: symbol;
|
|
|
13
13
|
export declare let HashSetSymbol: symbol;
|
|
14
14
|
export declare let TreeMapSymbol: symbol;
|
|
15
15
|
export declare let TreeSetSymbol: symbol;
|
|
16
|
+
export declare let NodeSymbol: symbol;
|
|
17
|
+
export declare let LinearNodeSymbol: symbol;
|
|
16
18
|
export declare let BinaryNodeSymbol: symbol;
|
|
17
|
-
export declare let
|
|
18
|
-
export declare let
|
|
19
|
+
export declare let RedBlackNodeSymbol: symbol;
|
|
20
|
+
export declare let AverageLevelNodeSymbol: symbol;
|
|
21
|
+
export declare let TreeSymbol: symbol;
|
|
22
|
+
export declare let BinaryTreeSymbol: symbol;
|
|
23
|
+
export declare let RedBlackTreeSymbol: symbol;
|
|
24
|
+
export declare let AVLTreeSymbol: symbol;
|
package/dist/symbol.js
CHANGED
|
@@ -13,6 +13,12 @@ export let HashMapSymbol = Symbol.for("HashMap");
|
|
|
13
13
|
export let HashSetSymbol = Symbol.for("HashSet");
|
|
14
14
|
export let TreeMapSymbol = Symbol.for("TreeMap");
|
|
15
15
|
export let TreeSetSymbol = Symbol.for("TreeSet");
|
|
16
|
+
export let NodeSymbol = Symbol.for("Node");
|
|
17
|
+
export let LinearNodeSymbol = Symbol.for("LinearNode");
|
|
16
18
|
export let BinaryNodeSymbol = Symbol.for("BinaryNode");
|
|
17
|
-
export let
|
|
18
|
-
export let
|
|
19
|
+
export let RedBlackNodeSymbol = Symbol.for("RedBlackNode");
|
|
20
|
+
export let AverageLevelNodeSymbol = Symbol.for("AverageLevelNode");
|
|
21
|
+
export let TreeSymbol = Symbol.for("Tree");
|
|
22
|
+
export let BinaryTreeSymbol = Symbol.for("BinaryTree");
|
|
23
|
+
export let RedBlackTreeSymbol = Symbol.for("RedBlackTree");
|
|
24
|
+
export let AVLTreeSymbol = Symbol.for("AVLTree");
|
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/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.0",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"readme": "readme.md",
|
|
12
12
|
"main": "dist/index.js",
|