semantic-typescript 0.5.3 → 0.6.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.
Files changed (42) hide show
  1. package/dist/asynchronous/collector.d.ts +231 -0
  2. package/dist/asynchronous/collector.js +800 -0
  3. package/dist/asynchronous/semantic.d.ts +257 -0
  4. package/dist/asynchronous/semantic.js +1853 -0
  5. package/dist/factory.d.ts +71 -37
  6. package/dist/factory.js +443 -262
  7. package/dist/guard.d.ts +24 -14
  8. package/dist/guard.js +73 -19
  9. package/dist/hook.d.ts +6 -6
  10. package/dist/hook.js +2 -2
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.js +2 -2
  13. package/dist/optional.d.ts +2 -2
  14. package/dist/symbol.d.ts +19 -10
  15. package/dist/symbol.js +19 -10
  16. package/dist/synchronous/collector.d.ts +232 -0
  17. package/dist/{collector.js → synchronous/collector.js} +160 -151
  18. package/dist/{semantic.d.ts → synchronous/semantic.d.ts} +111 -120
  19. package/dist/{semantic.js → synchronous/semantic.js} +299 -337
  20. package/dist/utility.d.ts +7 -1
  21. package/dist/utility.js +1 -0
  22. package/package.json +1 -1
  23. package/readme.cn.md +158 -697
  24. package/readme.de.md +163 -432
  25. package/readme.es.md +163 -433
  26. package/readme.fr.md +162 -444
  27. package/readme.jp.md +162 -442
  28. package/readme.kr.md +161 -430
  29. package/readme.md +157 -1009
  30. package/readme.ru.md +161 -426
  31. package/readme.tw.md +161 -436
  32. package/dist/collector.d.ts +0 -236
  33. package/dist/main.d.ts +0 -1
  34. package/dist/main.js +0 -4
  35. package/dist/map.d.ts +0 -76
  36. package/dist/map.js +0 -245
  37. package/dist/node.d.ts +0 -182
  38. package/dist/node.js +0 -918
  39. package/dist/set.d.ts +0 -19
  40. package/dist/set.js +0 -65
  41. package/dist/tree.d.ts +0 -82
  42. package/dist/tree.js +0 -257
@@ -1,236 +0,0 @@
1
- import { Collectable } from "./semantic";
2
- import { Optional } from "./optional";
3
- import type { Semantic } from "./semantic";
4
- import { type BiFunctional, type BiPredicate, type Functional, type Predicate, type Supplier, type TriFunctional, type Generator, type TriPredicate, type Consumer, type BiConsumer, type Comparator } from "./utility";
5
- export declare class Collector<E, A, R> {
6
- protected identity: Supplier<A>;
7
- protected interrupt: Predicate<E> | BiPredicate<E, bigint> | TriPredicate<E, bigint, A>;
8
- protected accumulator: BiFunctional<A, E, A> | TriFunctional<A, E, bigint, A>;
9
- protected finisher: Functional<A, R>;
10
- protected readonly Collector: symbol;
11
- protected constructor(identity: Supplier<A>, interrupt: Predicate<E>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>);
12
- protected constructor(identity: Supplier<A>, interrupt: BiPredicate<E, bigint>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>);
13
- protected constructor(identity: Supplier<A>, interrupt: Predicate<E>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>);
14
- protected constructor(identity: Supplier<A>, interrupt: BiPredicate<E, bigint>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>);
15
- collect(generator: Generator<E>): R;
16
- collect(iterable: Iterable<E>): R;
17
- collect(semantic: Semantic<E>): R;
18
- collect(collectable: Collectable<E>): R;
19
- collect(start: number, end: number): R;
20
- collect(start: bigint, end: bigint): R;
21
- static full<E, A, R>(identity: Supplier<A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
22
- static full<E, A, R>(identity: Supplier<A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
23
- static shortable<E, A, R>(identity: Supplier<A>, interrupt: Predicate<E>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
24
- static shortable<E, A, R>(identity: Supplier<A>, interrupt: Predicate<E>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
25
- static shortable<E, A, R>(identity: Supplier<A>, interrupt: BiPredicate<E, bigint>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
26
- static shortable<E, A, R>(identity: Supplier<A>, interrupt: BiPredicate<E, bigint>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
27
- static shortable<E, A, R>(identity: Supplier<A>, interrupt: TriPredicate<E, bigint, A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
28
- static shortable<E, A, R>(identity: Supplier<A>, interrupt: TriPredicate<E, bigint, A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
29
- }
30
- interface UseAnyMatch {
31
- <E>(predicate: Predicate<E>): Collector<E, boolean, boolean>;
32
- <E>(predicate: BiPredicate<E, bigint>): Collector<E, boolean, boolean>;
33
- }
34
- export declare let useAnyMatch: UseAnyMatch;
35
- interface UseAllMatch {
36
- <E>(predicate: Predicate<E>): Collector<E, boolean, boolean>;
37
- <E>(predicate: BiPredicate<E, bigint>): Collector<E, boolean, boolean>;
38
- }
39
- export declare let useAllMatch: UseAllMatch;
40
- interface UseCollect {
41
- <E, A, R>(identity: Supplier<A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
42
- <E, A, R>(identity: Supplier<A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
43
- <E, A, R>(identity: Supplier<A>, accumulator: BiFunctional<A, E, A> | TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
44
- <E, A, R>(identity: Supplier<A>, interrupt: Predicate<E>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
45
- <E, A, R>(identity: Supplier<A>, interrupt: Predicate<E>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
46
- <E, A, R>(identity: Supplier<A>, interrupt: BiPredicate<E, bigint>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
47
- <E, A, R>(identity: Supplier<A>, interrupt: BiPredicate<E, bigint>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
48
- <E, A, R>(identity: Supplier<A>, interrupt: TriPredicate<E, bigint, A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
49
- <E, A, R>(identity: Supplier<A>, interrupt: TriPredicate<E, bigint, A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
50
- }
51
- export declare let useCollect: UseCollect;
52
- export declare let useCount: <E = unknown>() => Collector<E, bigint, bigint>;
53
- interface UseError {
54
- <E = unknown>(): Collector<E, string, string>;
55
- <E = unknown>(accumulator: BiFunctional<string, E, string>): Collector<E, string, string>;
56
- <E = unknown>(accumulator: TriFunctional<string, E, bigint, string>): Collector<E, string, string>;
57
- <E = unknown>(prefix: string, accumulator: BiFunctional<string, E, string>, suffix: string): Collector<E, string, string>;
58
- <E = unknown>(prefix: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): Collector<E, string, string>;
59
- }
60
- export declare let useError: UseError;
61
- interface UseFindAt {
62
- <E>(index: number): Collector<E, Array<E>, Optional<E>>;
63
- <E>(index: bigint): Collector<E, Array<E>, Optional<E>>;
64
- }
65
- export declare let useFindAt: UseFindAt;
66
- export declare let useFindFirst: <E>() => Collector<E, Optional<E>, Optional<E>>;
67
- export declare let useFindAny: <E>() => Collector<E, Optional<E>, Optional<E>>;
68
- export declare let useFindLast: <E>() => Collector<E, Optional<E>, Optional<E>>;
69
- interface UseFindMaximum {
70
- <E>(): Collector<E, Optional<E>, Optional<E>>;
71
- <E>(comparator: Comparator<E>): Collector<E, Optional<E>, Optional<E>>;
72
- }
73
- export declare let useFindMaximum: UseFindMaximum;
74
- interface UseFindMinimum {
75
- <E>(): Collector<E, Optional<E>, Optional<E>>;
76
- <E>(comparator: Comparator<E>): Collector<E, Optional<E>, Optional<E>>;
77
- }
78
- export declare let useFindMinimum: UseFindMinimum;
79
- interface UseForEach {
80
- <E>(action: Consumer<E>): Collector<E, bigint, bigint>;
81
- <E>(action: BiConsumer<E, bigint>): Collector<E, bigint, bigint>;
82
- }
83
- export declare let useForEach: UseForEach;
84
- interface UseNonMatch {
85
- <E>(predicate: Predicate<E>): Collector<E, boolean, boolean>;
86
- <E>(predicate: BiPredicate<E, bigint>): Collector<E, boolean, boolean>;
87
- }
88
- export declare let useNoneMatch: UseNonMatch;
89
- interface UseGroup {
90
- <E, K>(classifier: Functional<E, K>): Collector<E, Map<K, E[]>, Map<K, E[]>>;
91
- <E, K>(classifier: BiFunctional<E, bigint, K>): Collector<E, Map<K, E[]>, Map<K, E[]>>;
92
- }
93
- export declare let useGroup: UseGroup;
94
- interface UseGroupBy {
95
- <E, K>(keyExtractor: Functional<E, K>): Collector<E, Map<K, E[]>, Map<K, E[]>>;
96
- <E, K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Collector<E, Map<K, V[]>, Map<K, V[]>>;
97
- <E, K, V>(keyExtractor: BiFunctional<E, bigint, K>, valueExtractor: BiFunctional<E, bigint, V>): Collector<E, Map<K, V[]>, Map<K, V[]>>;
98
- }
99
- export declare let useGroupBy: UseGroupBy;
100
- interface UseJoin {
101
- <E = unknown>(): Collector<E, string, string>;
102
- <E = unknown>(delimiter: string): Collector<E, string, string>;
103
- <E = unknown>(prefix: string, delimiter: string, suffix: string): Collector<E, string, string>;
104
- <E = unknown>(prefiex: string, accumulator: BiFunctional<string, E, string>, suffix: string): Collector<E, string, string>;
105
- <E = unknown>(prefiex: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): Collector<E, string, string>;
106
- }
107
- export declare let useJoin: UseJoin;
108
- interface UseLog {
109
- <E = unknown>(): Collector<E, string, string>;
110
- <E = unknown>(accumulator: BiFunctional<string, E, string>): Collector<E, string, string>;
111
- <E = unknown>(accumulator: TriFunctional<string, E, bigint, string>): Collector<E, string, string>;
112
- <E = unknown>(prefix: string, accumulator: BiFunctional<string, E, string>, suffix: string): Collector<E, string, string>;
113
- <E = unknown>(prefix: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): Collector<E, string, string>;
114
- }
115
- export declare let useLog: UseLog;
116
- export declare let usePartition: <E>(count: bigint) => Collector<E, Array<Array<E>>, Array<Array<E>>>;
117
- interface UsePartitionBy {
118
- <E>(classifier: Functional<E, bigint>): Collector<E, Array<E[]>, Array<E[]>>;
119
- <E>(classifier: BiFunctional<E, bigint, bigint>): Collector<E, Array<E[]>, Array<E[]>>;
120
- }
121
- export declare let usePartitionBy: UsePartitionBy;
122
- interface UseReduce {
123
- <E>(accumulator: BiFunctional<E, E, E>): Collector<E, Optional<E>, Optional<E>>;
124
- <E>(accumulator: TriFunctional<E, E, bigint, E>): Collector<E, Optional<E>, Optional<E>>;
125
- <E>(identity: E, accumulator: BiFunctional<E, E, E>): Collector<E, E, E>;
126
- <E>(identity: E, accumulator: TriFunctional<E, E, bigint, E>): Collector<E, E, E>;
127
- <E, R>(identity: R, accumulator: BiFunctional<R, E, R>, finisher: Functional<R, R>): Collector<E, R, R>;
128
- <E, R>(identity: R, accumulator: TriFunctional<R, E, bigint, R>, finisher: Functional<R, R>): Collector<E, R, R>;
129
- }
130
- export declare let useReduce: UseReduce;
131
- export declare let useToArray: <E>() => Collector<E, E[], E[]>;
132
- interface UseToMap {
133
- <E, K>(keyExtractor: Functional<E, K>): Collector<E, Map<K, E>, Map<K, E>>;
134
- <E, K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Collector<E, Map<K, V>, Map<K, V>>;
135
- <E, K, V>(keyExtractor: BiFunctional<E, bigint, K>, valueExtractor: BiFunctional<E, bigint, V>): Collector<E, Map<K, V>, Map<K, V>>;
136
- }
137
- export declare let useToMap: UseToMap;
138
- export declare let useToSet: <E>() => Collector<E, Set<E>, Set<E>>;
139
- interface UseWrite {
140
- <E, S = string>(stream: WritableStream<S>): Collector<E, Promise<WritableStream<S>>, Promise<WritableStream<S>>>;
141
- <E, S = string>(stream: WritableStream<S>, accumulator: BiFunctional<WritableStream<S>, E, WritableStream<S>>): Collector<E, Promise<WritableStream<S>>, Promise<WritableStream<S>>>;
142
- <E, S = string>(stream: WritableStream<S>, accumulator: TriFunctional<WritableStream<S>, E, bigint, WritableStream<S>>): Collector<E, Promise<WritableStream<S>>, Promise<WritableStream<S>>>;
143
- }
144
- export declare let useWrite: UseWrite;
145
- interface UseNumericSummate {
146
- <E>(): Collector<E, number, number>;
147
- <E>(mapper: Functional<E, number>): Collector<E, number, number>;
148
- }
149
- export declare let useNumericSummate: UseNumericSummate;
150
- interface UseBigIntSummate {
151
- <E>(): Collector<E, bigint, bigint>;
152
- <E>(mapper: Functional<E, bigint>): Collector<E, bigint, bigint>;
153
- }
154
- export declare let useBigIntSummate: UseBigIntSummate;
155
- interface UseNumericAverage {
156
- <E>(): Collector<E, NumericAverageAccumulator, number>;
157
- <E>(mapper: Functional<E, number>): Collector<E, NumericAverageAccumulator, number>;
158
- }
159
- interface NumericAverageAccumulator {
160
- summate: number;
161
- count: number;
162
- }
163
- export declare let useNumericAverage: UseNumericAverage;
164
- interface UseBigIntAverage {
165
- <E>(): Collector<E, BigIntAverageAccumulator, bigint>;
166
- <E>(mapper: Functional<E, bigint>): Collector<E, BigIntAverageAccumulator, bigint>;
167
- }
168
- interface BigIntAverageAccumulator {
169
- summate: bigint;
170
- count: bigint;
171
- }
172
- export declare let useBigIntAverage: UseBigIntAverage;
173
- export declare let useFrequency: <E>() => Collector<E, Map<E, bigint>, Map<E, bigint>>;
174
- interface UseNumericMode {
175
- <E>(): Collector<E, Map<number, bigint>, number>;
176
- <E>(mapper: Functional<E, number>): Collector<E, Map<number, bigint>, number>;
177
- }
178
- export declare let useNumericMode: UseNumericMode;
179
- interface UseBigIntMode {
180
- <E>(): Collector<E, Map<bigint, bigint>, bigint>;
181
- <E>(mapper: Functional<E, bigint>): Collector<E, Map<bigint, bigint>, bigint>;
182
- }
183
- export declare let useBigIntMode: UseBigIntMode;
184
- interface UseNumericVariance {
185
- <E>(): Collector<E, VarianceAccumulator, number>;
186
- <E>(mapper: Functional<E, number>): Collector<E, VarianceAccumulator, number>;
187
- }
188
- interface VarianceAccumulator {
189
- summate: number;
190
- summateOfSquares: number;
191
- count: number;
192
- }
193
- export declare let useNumericVariance: UseNumericVariance;
194
- interface UseBigIntVariance {
195
- <E>(): Collector<E, BigIntVarianceAccumulator, bigint>;
196
- <E>(mapper: Functional<E, bigint>): Collector<E, BigIntVarianceAccumulator, bigint>;
197
- }
198
- interface BigIntVarianceAccumulator {
199
- summate: bigint;
200
- summateOfSquares: bigint;
201
- count: bigint;
202
- }
203
- export declare let useBigIntVariance: UseBigIntVariance;
204
- interface UseNumericStandardDeviation {
205
- <E>(): Collector<E, StandardDeviationAccumulator, number>;
206
- <E>(mapper: Functional<E, number>): Collector<E, StandardDeviationAccumulator, number>;
207
- }
208
- interface StandardDeviationAccumulator {
209
- summate: number;
210
- summateOfSquares: number;
211
- count: number;
212
- }
213
- export declare let useNumericStandardDeviation: UseNumericStandardDeviation;
214
- interface UseBigIntStandardDeviation {
215
- <E>(): Collector<E, BigIntStandardDeviationAccumulator, bigint>;
216
- <E>(mapper: Functional<E, bigint>): Collector<E, BigIntStandardDeviationAccumulator, bigint>;
217
- }
218
- interface BigIntStandardDeviationAccumulator {
219
- summate: bigint;
220
- summateOfSquares: bigint;
221
- count: bigint;
222
- }
223
- export declare let useBigIntStandardDeviation: UseBigIntStandardDeviation;
224
- interface UseNumericMedian {
225
- <E>(): Collector<E, number[], number>;
226
- <E>(mapper: Functional<E, number>): Collector<E, number[], number>;
227
- }
228
- export declare let useNumericMedian: UseNumericMedian;
229
- interface UseBigIntMedian {
230
- <E>(): Collector<E, bigint[], bigint>;
231
- <E>(mapper: Functional<E, bigint>): Collector<E, bigint[], bigint>;
232
- }
233
- export declare let useBigIntMedian: UseBigIntMedian;
234
- export declare let useToGeneratorFunction: <E>() => Collector<E, Array<E>, globalThis.Generator<E, void, undefined>>;
235
- export declare let useToAsyncGeneratorFunction: <E>() => Collector<E, Array<E>, globalThis.AsyncGenerator<E, void, undefined>>;
236
- export {};
package/dist/main.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/main.js DELETED
@@ -1,4 +0,0 @@
1
- import { useWindow } from 'semantic-typescript';
2
- useWindow("click").toEvent().forEach((event, index) => {
3
- console.log(event.type + `第${index}次触发`);
4
- });
package/dist/map.d.ts DELETED
@@ -1,76 +0,0 @@
1
- import { type BiConsumer, type BiFunctional, type Comparator, type MaybeInvalid, type MaybeUndefined, type Supplier, type TriConsumer } from "./utility";
2
- export interface Entry<K, V> {
3
- key: K;
4
- value: V;
5
- }
6
- export interface SemanticMap<K, V> extends globalThis.Map<K, V> {
7
- clear(): void;
8
- compute(key: K, remapping: BiFunctional<K, MaybeInvalid<V>, MaybeInvalid<V>>): MaybeInvalid<V>;
9
- computeIfAbsent(key: K, remapping: Supplier<V>): V;
10
- computeIfPresent(key: K, remapping: BiFunctional<K, V, MaybeInvalid<V>>): MaybeInvalid<V>;
11
- delete(key: K): boolean;
12
- entries(): MapIterator<[K, V]>;
13
- forEach(consumer: BiConsumer<V, K>): void;
14
- forEach(consumer: TriConsumer<V, K, Map<K, V>>): void;
15
- get(key: K): MaybeUndefined<V>;
16
- get(key: K, defaultValue: V): V;
17
- has(key: K): boolean;
18
- replace(key: K, value: V): MaybeInvalid<V>;
19
- replace(key: K, oldValue: V, newValue: V): boolean;
20
- replaceAll(operator: BiFunctional<K, V, MaybeInvalid<V>>): void;
21
- set(key: K, value: V): this;
22
- size: number;
23
- values(): IterableIterator<V>;
24
- }
25
- export declare abstract class AbstractSemanticMap<K, V> implements SemanticMap<K, V> {
26
- protected internal: bigint;
27
- size: number;
28
- protected readonly SemanticMap: symbol;
29
- constructor();
30
- abstract clear(): void;
31
- compute(key: K, remapping: BiFunctional<K, MaybeInvalid<V>, MaybeInvalid<V>>): MaybeInvalid<V>;
32
- computeIfAbsent(key: K, remapping: Supplier<V>): V;
33
- computeIfPresent(key: K, remapping: BiFunctional<K, V, MaybeInvalid<V>>): MaybeInvalid<V>;
34
- abstract delete(key: K): boolean;
35
- abstract entries(): MapIterator<[K, V]>;
36
- forEach(consumer: BiConsumer<V, K>): void;
37
- forEach(consumer: TriConsumer<V, K, Map<K, V>>): void;
38
- abstract get(key: K): MaybeUndefined<V>;
39
- abstract get(key: K, defaultValue: V): V;
40
- abstract keys(): MapIterator<K>;
41
- has(key: K): boolean;
42
- replace(key: K, value: V): MaybeInvalid<V>;
43
- replace(key: K, oldValue: V, newValue: V): boolean;
44
- replaceAll(operator: BiFunctional<K, V, MaybeInvalid<V>>): void;
45
- abstract set(key: K, value: V): this;
46
- [Symbol.iterator](): IterableIterator<[K, V]>;
47
- [Symbol.toStringTag]: string;
48
- abstract values(): IterableIterator<V>;
49
- }
50
- export declare class HashMap<K, V> extends AbstractSemanticMap<K, V> {
51
- protected buckets: Map<bigint, Array<Entry<K, V>>>;
52
- protected threashold: number;
53
- protected comparator: Comparator<K>;
54
- protected capacity: number;
55
- protected readonly HashMap: symbol;
56
- constructor();
57
- constructor(comparator: Comparator<K>);
58
- constructor(threashold: number, initialCapacity: number);
59
- constructor(comparator: Comparator<K>, threashold: number, capacity: number);
60
- clear(): void;
61
- delete(key: K): boolean;
62
- entries(): MapIterator<[K, V]>;
63
- has(key: K): boolean;
64
- protected hash(key: K): bigint;
65
- protected findEntry(key: K, hash: bigint): MaybeInvalid<Entry<K, V>>;
66
- get(key: K): MaybeUndefined<V>;
67
- get(key: K, defaultValue: V): V;
68
- keys(): MapIterator<K>;
69
- protected rehash(): void;
70
- set(key: K, value: V): this;
71
- values(): IterableIterator<V>;
72
- }
73
- export declare class TreeMap<K, V> {
74
- key: K;
75
- value: V;
76
- }
package/dist/map.js DELETED
@@ -1,245 +0,0 @@
1
- import { isFunction, isNumber } from "./guard";
2
- import { useHash } from "./hash";
3
- import { useCompare } from "./hook";
4
- import { SemanticMapSymbol } from "./symbol";
5
- import { invalidate, validate } from "./utility";
6
- ;
7
- ;
8
- export class AbstractSemanticMap {
9
- internal = 0n;
10
- size = 0;
11
- SemanticMap = SemanticMapSymbol;
12
- constructor() {
13
- Object.defineProperty(this, "SemanticMap", {
14
- value: SemanticMapSymbol,
15
- enumerable: false,
16
- writable: false,
17
- configurable: false
18
- });
19
- }
20
- compute(key, remapping) {
21
- let value = this.get(key);
22
- return remapping(key, value);
23
- }
24
- computeIfAbsent(key, remapping) {
25
- let value = this.get(key);
26
- if (invalidate(value)) {
27
- return remapping();
28
- }
29
- return value;
30
- }
31
- computeIfPresent(key, remapping) {
32
- let value = this.get(key);
33
- if (validate(value)) {
34
- return remapping(key, value);
35
- }
36
- return value;
37
- }
38
- forEach(consumer) {
39
- for (let entry of this.entries()) {
40
- consumer(entry[1], entry[0], this);
41
- }
42
- }
43
- has(key) {
44
- return this.get(key) !== undefined;
45
- }
46
- replace(argument1, argument2, argument3) {
47
- if (validate(argument1) && validate(argument2) && validate(argument3)) {
48
- let key = argument1;
49
- let oldValue = argument2;
50
- let newValue = argument3;
51
- if (this.get(key) === oldValue) {
52
- this.set(key, newValue);
53
- return true;
54
- }
55
- return this.get(key);
56
- }
57
- if (validate(argument1) && validate(argument2) && invalidate(argument3)) {
58
- let key = argument1;
59
- let value = argument2;
60
- if (this.get(key) === value) {
61
- this.delete(key);
62
- return true;
63
- }
64
- return this.get(key);
65
- }
66
- }
67
- replaceAll(operator) {
68
- for (let entry of this.entries()) {
69
- let key = entry[0];
70
- let value = entry[1];
71
- let newValue = operator(key, value);
72
- if (validate(newValue)) {
73
- this.set(key, newValue);
74
- }
75
- else {
76
- this.delete(key);
77
- }
78
- }
79
- }
80
- [Symbol.iterator]() {
81
- return this.entries();
82
- }
83
- [Symbol.toStringTag] = "SemanticMap";
84
- }
85
- ;
86
- export class HashMap extends AbstractSemanticMap {
87
- buckets = new Map();
88
- threashold;
89
- comparator;
90
- capacity;
91
- HashMap = SemanticMapSymbol;
92
- constructor(argument1, argument2, argument3) {
93
- super();
94
- if (isFunction(argument1) && isNumber(argument2) && isNumber(argument3)) {
95
- this.comparator = argument1;
96
- this.threashold = argument2;
97
- this.capacity = argument3;
98
- }
99
- else if (isFunction(argument1) && isNumber(argument2) && invalidate(argument3)) {
100
- this.comparator = argument1;
101
- this.threashold = argument2;
102
- this.capacity = 16;
103
- }
104
- else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
105
- this.comparator = argument1;
106
- this.threashold = 0.75;
107
- this.capacity = 16;
108
- }
109
- else {
110
- this.comparator = useCompare;
111
- this.threashold = 0.75;
112
- this.capacity = 16;
113
- }
114
- this.buckets = new Map();
115
- Object.defineProperty(this, "size", {
116
- get: () => this.internal,
117
- set: (value) => this.internal = isNumber(value) ? BigInt(value) : 0n,
118
- enumerable: true,
119
- configurable: false
120
- });
121
- Object.defineProperty(this, "HashMap", {
122
- value: SemanticMapSymbol,
123
- enumerable: false,
124
- writable: false,
125
- configurable: false
126
- });
127
- }
128
- clear() {
129
- this.buckets.clear();
130
- this.size = 0;
131
- }
132
- delete(key) {
133
- let hashCode = this.hash(key);
134
- let bucket = this.buckets.get(hashCode) || [];
135
- if (bucket.length > 0) {
136
- for (let index = 0; index < bucket.length; index++) {
137
- let entry = bucket[index];
138
- if (this.comparator(entry.key, key) === 0) {
139
- bucket.splice(index, 1);
140
- this.size--;
141
- if (bucket.length === 0) {
142
- this.buckets.delete(hashCode);
143
- }
144
- return true;
145
- }
146
- }
147
- }
148
- this.buckets.delete(hashCode);
149
- return false;
150
- }
151
- *entries() {
152
- for (let bucket of this.buckets.values()) {
153
- for (let entry of bucket) {
154
- yield [entry.key, entry.value];
155
- }
156
- }
157
- }
158
- has(key) {
159
- let hashCode = this.hash(key);
160
- return validate(this.findEntry(key, hashCode));
161
- }
162
- hash(key) {
163
- return useHash(key);
164
- }
165
- ;
166
- findEntry(key, hash) {
167
- let candidates = (this.buckets.get(hash) || []);
168
- for (let candidate of candidates) {
169
- if (this.comparator(candidate.key, key) === 0) {
170
- return candidate;
171
- }
172
- }
173
- return (void 0);
174
- }
175
- get(argument1, argument2) {
176
- if (validate(argument1) && validate(argument2)) {
177
- let key = argument1;
178
- let defaultValue = argument2;
179
- let hashCode = this.hash(key);
180
- let entry = this.findEntry(key, hashCode);
181
- if (validate(entry)) {
182
- return entry.value;
183
- }
184
- return defaultValue;
185
- }
186
- let key = argument1;
187
- let hashCode = this.hash(key);
188
- let entry = this.findEntry(key, hashCode);
189
- if (validate(entry)) {
190
- return entry.value;
191
- }
192
- return (void 0);
193
- }
194
- *keys() {
195
- for (let bucket of this.buckets.values()) {
196
- for (let entry of bucket) {
197
- yield entry.key;
198
- }
199
- }
200
- }
201
- rehash() {
202
- let oldBuckets = this.buckets;
203
- this.buckets = new Map();
204
- this.size = 0;
205
- for (let bucket of oldBuckets.values()) {
206
- for (let entry of bucket) {
207
- let hashCode = this.hash(entry.key);
208
- let bucket = this.buckets.get(hashCode) || [];
209
- bucket.push(entry);
210
- this.size++;
211
- }
212
- }
213
- }
214
- set(key, value) {
215
- let hashCode = this.hash(key);
216
- let bucket = this.buckets.get(hashCode) || [];
217
- let found = this.findEntry(key, hashCode);
218
- if (validate(found)) {
219
- found.value = value;
220
- }
221
- else {
222
- bucket.push({
223
- key: key,
224
- value: value
225
- });
226
- this.size++;
227
- if (this.size > this.capacity * this.threashold) {
228
- this.rehash();
229
- }
230
- }
231
- return this;
232
- }
233
- *values() {
234
- for (let bucket of this.buckets.values()) {
235
- for (let entry of bucket) {
236
- yield entry.value;
237
- }
238
- }
239
- }
240
- }
241
- ;
242
- export class TreeMap {
243
- key = (void 0);
244
- value = (void 0);
245
- }