atomic-fns 1.2.0 → 2.0.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/README.md +397 -91
- package/dist/array/index.d.ts +9 -0
- package/dist/array/index.js +9 -0
- package/dist/array/list.d.ts +99 -0
- package/dist/array/list.js +133 -0
- package/dist/array/sets.d.ts +130 -0
- package/dist/array/sets.js +213 -0
- package/dist/async/index.d.ts +6 -0
- package/dist/async/index.js +6 -0
- package/dist/async/retry.d.ts +38 -0
- package/dist/async/retry.js +56 -0
- package/dist/async/sleep.d.ts +42 -0
- package/dist/async/sleep.js +76 -0
- package/dist/collections/bisect.d.ts +103 -0
- package/dist/collections/bisect.js +157 -0
- package/dist/collections/deque.d.ts +67 -97
- package/dist/collections/deque.js +197 -256
- package/dist/collections/entries.d.ts +89 -0
- package/dist/collections/entries.js +131 -0
- package/dist/collections/frozen-set.d.ts +42 -0
- package/dist/collections/frozen-set.js +64 -0
- package/dist/collections/group.d.ts +141 -0
- package/dist/collections/group.js +241 -0
- package/dist/collections/heap.d.ts +64 -0
- package/dist/collections/heap.js +205 -0
- package/dist/collections/index.d.ts +15 -623
- package/dist/collections/index.js +14 -844
- package/dist/collections/internal/arrayKeys.d.ts +19 -0
- package/dist/collections/internal/arrayKeys.js +83 -0
- package/dist/collections/internal/invariants.d.ts +4 -0
- package/dist/collections/internal/invariants.js +12 -0
- package/dist/collections/internal/iterable.d.ts +25 -0
- package/dist/collections/internal/iterable.js +62 -0
- package/dist/collections/iterate.d.ts +162 -0
- package/dist/collections/iterate.js +188 -0
- package/dist/collections/lru-cache.d.ts +58 -0
- package/dist/collections/lru-cache.js +164 -0
- package/dist/collections/order.d.ts +19 -0
- package/dist/collections/order.js +38 -0
- package/dist/collections/shape.d.ts +32 -0
- package/dist/collections/shape.js +86 -0
- package/dist/collections/sorted-map.d.ts +171 -0
- package/dist/collections/sorted-map.js +845 -0
- package/dist/collections/sorted-set.d.ts +103 -0
- package/dist/collections/sorted-set.js +147 -0
- package/dist/collections/splay-tree.d.ts +82 -0
- package/dist/collections/splay-tree.js +354 -0
- package/dist/collections/trie.d.ts +58 -0
- package/dist/collections/trie.js +196 -0
- package/dist/decimal/currency.d.ts +211 -0
- package/dist/decimal/currency.js +321 -0
- package/dist/decimal/decimal.d.ts +299 -0
- package/dist/decimal/decimal.js +660 -0
- package/dist/decimal/index.d.ts +11 -148
- package/dist/decimal/index.js +10 -410
- package/dist/decimal/internal/bits.d.ts +2 -0
- package/dist/decimal/internal/bits.js +7 -0
- package/dist/decimal/internal/echo.d.ts +4 -0
- package/dist/decimal/internal/echo.js +6 -0
- package/dist/decimal/internal/isqrt.d.ts +9 -0
- package/dist/decimal/internal/isqrt.js +34 -0
- package/dist/decimal/internal/locale.d.ts +7 -0
- package/dist/decimal/internal/locale.js +24 -0
- package/dist/decimal/internal/minor-units.d.ts +2 -0
- package/dist/decimal/internal/minor-units.js +33 -0
- package/dist/decimal/internal/pow10.d.ts +24 -0
- package/dist/decimal/internal/pow10.js +96 -0
- package/dist/encoding/base64.d.ts +39 -0
- package/dist/encoding/base64.js +53 -0
- package/dist/encoding/hex.d.ts +23 -0
- package/dist/encoding/hex.js +34 -0
- package/dist/encoding/index.d.ts +6 -0
- package/dist/encoding/index.js +6 -0
- package/dist/function/debounce.d.ts +68 -0
- package/dist/function/debounce.js +203 -0
- package/dist/function/index.d.ts +6 -0
- package/dist/function/index.js +6 -0
- package/dist/function/shared.d.ts +2 -0
- package/dist/function/shared.js +5 -0
- package/dist/function/wrap.d.ts +130 -0
- package/dist/function/wrap.js +113 -0
- package/dist/hash/digest.d.ts +18 -0
- package/dist/hash/digest.js +26 -0
- package/dist/hash/hash.d.ts +22 -0
- package/dist/hash/hash.js +252 -0
- package/dist/hash/hashString.d.ts +13 -0
- package/dist/hash/hashString.js +53 -0
- package/dist/hash/index.d.ts +8 -0
- package/dist/hash/index.js +8 -0
- package/dist/hash/stableStringify.d.ts +19 -0
- package/dist/hash/stableStringify.js +102 -0
- package/dist/id/index.d.ts +7 -0
- package/dist/id/index.js +7 -0
- package/dist/id/nanoid.d.ts +16 -0
- package/dist/id/nanoid.js +65 -0
- package/dist/id/uniqueId.d.ts +14 -0
- package/dist/id/uniqueId.js +20 -0
- package/dist/id/uuid.d.ts +25 -0
- package/dist/id/uuid.js +64 -0
- package/dist/index.d.ts +15 -8
- package/dist/index.js +15 -8
- package/dist/internal/bytes.d.ts +11 -0
- package/dist/internal/bytes.js +33 -0
- package/dist/internal/codec.d.ts +11 -0
- package/dist/internal/codec.js +84 -0
- package/dist/internal/compare.d.ts +10 -0
- package/dist/internal/compare.js +26 -0
- package/dist/internal/crypto.d.ts +5 -0
- package/dist/internal/crypto.js +11 -0
- package/dist/internal/keys.d.ts +12 -0
- package/dist/internal/keys.js +23 -0
- package/dist/internal/kind.d.ts +44 -0
- package/dist/internal/kind.js +139 -0
- package/dist/internal/sparse.d.ts +51 -0
- package/dist/internal/sparse.js +104 -0
- package/dist/internal/text.d.ts +7 -0
- package/dist/internal/text.js +15 -0
- package/dist/internal/timer.d.ts +10 -0
- package/dist/internal/timer.js +17 -0
- package/dist/internal/truncate.d.ts +10 -0
- package/dist/internal/truncate.js +22 -0
- package/dist/internal/walk.d.ts +47 -0
- package/dist/internal/walk.js +100 -0
- package/dist/is/index.d.ts +8 -0
- package/dist/is/index.js +8 -0
- package/dist/is/isArrayLike.d.ts +18 -0
- package/dist/is/isArrayLike.js +25 -0
- package/dist/is/isError.d.ts +13 -0
- package/dist/is/isError.js +18 -0
- package/dist/is/isNil.d.ts +12 -0
- package/dist/is/isNil.js +14 -0
- package/dist/is/isPlainObject.d.ts +15 -0
- package/dist/is/isPlainObject.js +34 -0
- package/dist/number/index.d.ts +7 -0
- package/dist/number/index.js +7 -0
- package/dist/number/round.d.ts +86 -0
- package/dist/number/round.js +130 -0
- package/dist/number/stats.d.ts +52 -0
- package/dist/number/stats.js +115 -0
- package/dist/object/cloneDeep.d.ts +28 -0
- package/dist/object/cloneDeep.js +200 -0
- package/dist/object/index.d.ts +14 -0
- package/dist/object/index.js +13 -0
- package/dist/object/isEqual.d.ts +64 -0
- package/dist/object/isEqual.js +289 -0
- package/dist/object/matches.d.ts +40 -0
- package/dist/object/matches.js +284 -0
- package/dist/object/merge.d.ts +66 -0
- package/dist/object/merge.js +272 -0
- package/dist/object/parsePath.d.ts +22 -0
- package/dist/object/parsePath.js +111 -0
- package/dist/object/path.d.ts +85 -0
- package/dist/object/path.js +208 -0
- package/dist/object/pick.d.ts +91 -0
- package/dist/object/pick.js +180 -0
- package/dist/object/reshape.d.ts +73 -0
- package/dist/object/reshape.js +144 -0
- package/dist/random/index.d.ts +96 -32
- package/dist/random/index.js +215 -53
- package/dist/string/case.d.ts +71 -0
- package/dist/string/case.js +152 -0
- package/dist/string/fold.d.ts +35 -0
- package/dist/string/fold.js +100 -0
- package/dist/string/index.d.ts +6 -187
- package/dist/string/index.js +6 -224
- package/dist/string/truncate.d.ts +25 -0
- package/dist/string/truncate.js +44 -0
- package/dist/string/words.d.ts +27 -0
- package/dist/string/words.js +241 -0
- package/package.json +99 -51
- package/dist/collections/BTree.d.ts +0 -230
- package/dist/collections/BTree.js +0 -1143
- package/dist/collections/Heap.d.ts +0 -69
- package/dist/collections/Heap.js +0 -181
- package/dist/collections/LRUCache.d.ts +0 -83
- package/dist/collections/LRUCache.js +0 -139
- package/dist/collections/SortedMap.d.ts +0 -92
- package/dist/collections/SortedMap.js +0 -131
- package/dist/collections/SortedSet.d.ts +0 -69
- package/dist/collections/SortedSet.js +0 -99
- package/dist/collections/SortedTree.d.ts +0 -103
- package/dist/collections/SortedTree.js +0 -142
- package/dist/collections/SplayTree.d.ts +0 -107
- package/dist/collections/SplayTree.js +0 -351
- package/dist/collections/Trie.d.ts +0 -42
- package/dist/collections/Trie.js +0 -104
- package/dist/collections/abc.d.ts +0 -152
- package/dist/collections/abc.js +0 -39
- package/dist/collections/frozenset.d.ts +0 -19
- package/dist/collections/frozenset.js +0 -33
- package/dist/functools/index.d.ts +0 -106
- package/dist/functools/index.js +0 -203
- package/dist/globals/index.d.ts +0 -268
- package/dist/globals/index.js +0 -447
- package/dist/i18n/currency.d.ts +0 -27
- package/dist/i18n/currency.js +0 -100
- package/dist/i18n/date/index.d.ts +0 -210
- package/dist/i18n/date/index.js +0 -552
- package/dist/i18n/date/utils.d.ts +0 -64
- package/dist/i18n/date/utils.js +0 -192
- package/dist/i18n/duration.d.ts +0 -113
- package/dist/i18n/duration.js +0 -398
- package/dist/i18n/format.d.ts +0 -34
- package/dist/i18n/format.js +0 -378
- package/dist/i18n/index.d.ts +0 -9
- package/dist/i18n/index.js +0 -8
- package/dist/itertools/index.d.ts +0 -251
- package/dist/itertools/index.js +0 -434
- package/dist/math/index.d.ts +0 -79
- package/dist/math/index.js +0 -81
- package/dist/mod.d.ts +0 -1
- package/dist/mod.js +0 -1
- package/dist/operators/index.d.ts +0 -148
- package/dist/operators/index.js +0 -325
- package/dist/types.d.ts +0 -19
- package/dist/types.js +0 -1
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Collection } from './abc.js';
|
|
2
|
-
/**
|
|
3
|
-
* A `SortedSet` is a set that holds values in order. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as values.
|
|
4
|
-
* @see {@link Comparable}
|
|
5
|
-
* @see {@link Ordered}
|
|
6
|
-
* @template K, V
|
|
7
|
-
*/
|
|
8
|
-
export declare class SortedSet<T> extends Collection {
|
|
9
|
-
private readonly store;
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new `SortedSet` object.
|
|
12
|
-
* @param {Iterable<T>} [iterable] Initialize the set with entries.
|
|
13
|
-
* @param {Comparer} [compareFn] The `compare` function to sort keys.
|
|
14
|
-
*/
|
|
15
|
-
constructor(iterable?: Iterable<T>, compareFn?: any);
|
|
16
|
-
/**
|
|
17
|
-
* Inserts a new value in order in the `Set`, if the value doesn't exist.
|
|
18
|
-
* @param {T} value
|
|
19
|
-
* @returns {this} Returns the Set object.
|
|
20
|
-
*/
|
|
21
|
-
add(value: T): this;
|
|
22
|
-
/**
|
|
23
|
-
* Returns the smallest value in the set.
|
|
24
|
-
* @returns {?T}
|
|
25
|
-
*/
|
|
26
|
-
min(): T | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* Returns the largest value in the set.
|
|
29
|
-
* @returns {?T}
|
|
30
|
-
*/
|
|
31
|
-
max(): T | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Removes the value from the set and returns `true` if the value was found and removed.
|
|
34
|
-
* @param {T} value
|
|
35
|
-
* @returns {boolean} `true` if the value was found and removed.
|
|
36
|
-
*/
|
|
37
|
-
delete(value: T): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Removes all values in the set.
|
|
40
|
-
*/
|
|
41
|
-
clear(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Returns the total number of elements in the set.
|
|
44
|
-
* @returns {number}
|
|
45
|
-
*/
|
|
46
|
-
get size(): number;
|
|
47
|
-
/**
|
|
48
|
-
* Check if there are no values in the set.
|
|
49
|
-
* @returns {boolean} `true` if is empty.
|
|
50
|
-
*/
|
|
51
|
-
empty(): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Returns `true` if the `value` exists.
|
|
54
|
-
* @param {T} value
|
|
55
|
-
* @returns {boolean} `true` if value is found, otherwise `false`.
|
|
56
|
-
*/
|
|
57
|
-
contains(value: T): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Returns `true` if the `value` exists.
|
|
60
|
-
* @param {T} value
|
|
61
|
-
* @returns {boolean} `true` if value is found, otherwise `false`.
|
|
62
|
-
*/
|
|
63
|
-
has(value: T): boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Returns a new iterator of all values **in-order**.
|
|
66
|
-
* @returns {Iterable<T>}
|
|
67
|
-
*/
|
|
68
|
-
values(): Iterable<T>;
|
|
69
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Collection } from './abc.js';
|
|
2
|
-
import { SplayTree } from './SplayTree.js';
|
|
3
|
-
/**
|
|
4
|
-
* A `SortedSet` is a set that holds values in order. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as values.
|
|
5
|
-
* @see {@link Comparable}
|
|
6
|
-
* @see {@link Ordered}
|
|
7
|
-
* @template K, V
|
|
8
|
-
*/
|
|
9
|
-
export class SortedSet extends Collection {
|
|
10
|
-
store;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new `SortedSet` object.
|
|
13
|
-
* @param {Iterable<T>} [iterable] Initialize the set with entries.
|
|
14
|
-
* @param {Comparer} [compareFn] The `compare` function to sort keys.
|
|
15
|
-
*/
|
|
16
|
-
constructor(iterable, compareFn) {
|
|
17
|
-
super();
|
|
18
|
-
this.store = new SplayTree(compareFn);
|
|
19
|
-
if (iterable) {
|
|
20
|
-
for (const key of iterable) {
|
|
21
|
-
this.store.add(key);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Inserts a new value in order in the `Set`, if the value doesn't exist.
|
|
27
|
-
* @param {T} value
|
|
28
|
-
* @returns {this} Returns the Set object.
|
|
29
|
-
*/
|
|
30
|
-
add(value) {
|
|
31
|
-
this.store.add(value);
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Returns the smallest value in the set.
|
|
36
|
-
* @returns {?T}
|
|
37
|
-
*/
|
|
38
|
-
min() {
|
|
39
|
-
return this.store.min();
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Returns the largest value in the set.
|
|
43
|
-
* @returns {?T}
|
|
44
|
-
*/
|
|
45
|
-
max() {
|
|
46
|
-
return this.store.max();
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Removes the value from the set and returns `true` if the value was found and removed.
|
|
50
|
-
* @param {T} value
|
|
51
|
-
* @returns {boolean} `true` if the value was found and removed.
|
|
52
|
-
*/
|
|
53
|
-
delete(value) {
|
|
54
|
-
return this.store.remove(value) !== undefined;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Removes all values in the set.
|
|
58
|
-
*/
|
|
59
|
-
clear() {
|
|
60
|
-
return this.store.clear();
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Returns the total number of elements in the set.
|
|
64
|
-
* @returns {number}
|
|
65
|
-
*/
|
|
66
|
-
get size() {
|
|
67
|
-
return this.store.size;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Check if there are no values in the set.
|
|
71
|
-
* @returns {boolean} `true` if is empty.
|
|
72
|
-
*/
|
|
73
|
-
empty() {
|
|
74
|
-
return this.store.empty();
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Returns `true` if the `value` exists.
|
|
78
|
-
* @param {T} value
|
|
79
|
-
* @returns {boolean} `true` if value is found, otherwise `false`.
|
|
80
|
-
*/
|
|
81
|
-
contains(value) {
|
|
82
|
-
return this.store.contains(value);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Returns `true` if the `value` exists.
|
|
86
|
-
* @param {T} value
|
|
87
|
-
* @returns {boolean} `true` if value is found, otherwise `false`.
|
|
88
|
-
*/
|
|
89
|
-
has(value) {
|
|
90
|
-
return this.store.contains(value);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Returns a new iterator of all values **in-order**.
|
|
94
|
-
* @returns {Iterable<T>}
|
|
95
|
-
*/
|
|
96
|
-
values() {
|
|
97
|
-
return this.store.keys();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import type { Comparer } from '../operators/index.js';
|
|
2
|
-
import { Mapping } from './abc.js';
|
|
3
|
-
/**
|
|
4
|
-
* A `SortedTree` is a map that holds key value pairs ordered by keys. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as keys or values.
|
|
5
|
-
* @see {@link Comparable}
|
|
6
|
-
* @see {@link Ordered}
|
|
7
|
-
* @template K, V
|
|
8
|
-
*/
|
|
9
|
-
export declare class SortedTree<K, V> extends Mapping<K, V> {
|
|
10
|
-
private readonly store;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new `SortedTree` object.
|
|
13
|
-
* @param {Iterable<[K, V]>} [iterable] Initialize the tree with entries.
|
|
14
|
-
* @param {Comparer} [compareFn] The `compare` function to sort keys.
|
|
15
|
-
*/
|
|
16
|
-
constructor(iterable?: Iterable<[K, V]>, compareFn?: Comparer);
|
|
17
|
-
/**
|
|
18
|
-
* Adds a new `key` with a `null` value, if the `key` doesn't exist.
|
|
19
|
-
* @param {K} key
|
|
20
|
-
* @returns {this} Returns the Tree object.
|
|
21
|
-
*/
|
|
22
|
-
add(key: K): this;
|
|
23
|
-
/**
|
|
24
|
-
* Returns the value associated with the `key` or `undefined`.
|
|
25
|
-
* @param {K} key
|
|
26
|
-
* @returns {?V} The key value or `undefined`.
|
|
27
|
-
*/
|
|
28
|
-
get(key: K): V | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Sets the value for the given `key`.
|
|
31
|
-
* @param {K} key
|
|
32
|
-
* @param {V} value
|
|
33
|
-
* @returns {this} Returns the Tree object.
|
|
34
|
-
*/
|
|
35
|
-
set(key: K, value: V): this;
|
|
36
|
-
/**
|
|
37
|
-
* Returns the smallest key in the tree.
|
|
38
|
-
* @returns {?K}
|
|
39
|
-
*/
|
|
40
|
-
min(): K | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* Returns the largest key in the tree.
|
|
43
|
-
* @returns {?K}
|
|
44
|
-
*/
|
|
45
|
-
max(): K | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* Returns `true` if the `key` existed in the tree and was removed.
|
|
48
|
-
* @param {K} key
|
|
49
|
-
* @returns {boolean} `true` if key was removed, otherwise `false`.
|
|
50
|
-
*/
|
|
51
|
-
delete(key: K): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Removes all key/value pairs in the tree.
|
|
54
|
-
*/
|
|
55
|
-
clear(): void;
|
|
56
|
-
/**
|
|
57
|
-
* Freezes the tree which prevents adding, updating or removing any keys.
|
|
58
|
-
* @returns {this}
|
|
59
|
-
*/
|
|
60
|
-
freeze(): this;
|
|
61
|
-
/**
|
|
62
|
-
* Returns a new iterator of `[K, V]` pairs in reverse order of keys.
|
|
63
|
-
* @returns {IterableIterator<[K, V]>}
|
|
64
|
-
*/
|
|
65
|
-
reversed(): IterableIterator<[K, V]>;
|
|
66
|
-
/**
|
|
67
|
-
* Returns the total key/value pairs in the tree.
|
|
68
|
-
* @returns {number}
|
|
69
|
-
*/
|
|
70
|
-
get size(): number;
|
|
71
|
-
/**
|
|
72
|
-
* Check if there are no key/value pairs in the tree.
|
|
73
|
-
* @returns {boolean} `true` if is empty.
|
|
74
|
-
*/
|
|
75
|
-
empty(): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Returns `true` if the `key` exists in the tree.
|
|
78
|
-
* @param {K} key
|
|
79
|
-
* @returns {boolean} `true` if key is found, otherwise `false`.
|
|
80
|
-
*/
|
|
81
|
-
contains(key: K): boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Returns `true` if the `key` exists in the tree.
|
|
84
|
-
* @param {K} key
|
|
85
|
-
* @returns {boolean} `true` if key is found, otherwise `false`.
|
|
86
|
-
*/
|
|
87
|
-
has(key: K): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Returns a new iterator of all **ordered** keys in the tree.
|
|
90
|
-
* @returns {IterableIterator<K>}
|
|
91
|
-
*/
|
|
92
|
-
keys(): IterableIterator<K>;
|
|
93
|
-
/**
|
|
94
|
-
* Returns a new iterator of all values **ordered** by their keys.
|
|
95
|
-
* @returns {IterableIterator<V>}
|
|
96
|
-
*/
|
|
97
|
-
values(): IterableIterator<V>;
|
|
98
|
-
/**
|
|
99
|
-
* Returns a new iterator of all key value pairs **ordered** by their keys.
|
|
100
|
-
* @returns {IterableIterator<[K, V]>}
|
|
101
|
-
*/
|
|
102
|
-
entries(): IterableIterator<[K, V]>;
|
|
103
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { Mapping } from './abc.js';
|
|
2
|
-
import { BTree } from './BTree.js';
|
|
3
|
-
/**
|
|
4
|
-
* A `SortedTree` is a map that holds key value pairs ordered by keys. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as keys or values.
|
|
5
|
-
* @see {@link Comparable}
|
|
6
|
-
* @see {@link Ordered}
|
|
7
|
-
* @template K, V
|
|
8
|
-
*/
|
|
9
|
-
export class SortedTree extends Mapping {
|
|
10
|
-
store;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new `SortedTree` object.
|
|
13
|
-
* @param {Iterable<[K, V]>} [iterable] Initialize the tree with entries.
|
|
14
|
-
* @param {Comparer} [compareFn] The `compare` function to sort keys.
|
|
15
|
-
*/
|
|
16
|
-
constructor(iterable, compareFn) {
|
|
17
|
-
super();
|
|
18
|
-
this.store = new BTree(iterable, compareFn);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Adds a new `key` with a `null` value, if the `key` doesn't exist.
|
|
22
|
-
* @param {K} key
|
|
23
|
-
* @returns {this} Returns the Tree object.
|
|
24
|
-
*/
|
|
25
|
-
add(key) {
|
|
26
|
-
if (!this.store.contains(key))
|
|
27
|
-
this.store.set(key, null);
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Returns the value associated with the `key` or `undefined`.
|
|
32
|
-
* @param {K} key
|
|
33
|
-
* @returns {?V} The key value or `undefined`.
|
|
34
|
-
*/
|
|
35
|
-
get(key) {
|
|
36
|
-
return this.store.get(key);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Sets the value for the given `key`.
|
|
40
|
-
* @param {K} key
|
|
41
|
-
* @param {V} value
|
|
42
|
-
* @returns {this} Returns the Tree object.
|
|
43
|
-
*/
|
|
44
|
-
set(key, value) {
|
|
45
|
-
this.store.set(key, value);
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Returns the smallest key in the tree.
|
|
50
|
-
* @returns {?K}
|
|
51
|
-
*/
|
|
52
|
-
min() {
|
|
53
|
-
return this.store.minKey();
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Returns the largest key in the tree.
|
|
57
|
-
* @returns {?K}
|
|
58
|
-
*/
|
|
59
|
-
max() {
|
|
60
|
-
return this.store.maxKey();
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Returns `true` if the `key` existed in the tree and was removed.
|
|
64
|
-
* @param {K} key
|
|
65
|
-
* @returns {boolean} `true` if key was removed, otherwise `false`.
|
|
66
|
-
*/
|
|
67
|
-
delete(key) {
|
|
68
|
-
return this.store.remove(key);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Removes all key/value pairs in the tree.
|
|
72
|
-
*/
|
|
73
|
-
clear() {
|
|
74
|
-
return this.store.clear();
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Freezes the tree which prevents adding, updating or removing any keys.
|
|
78
|
-
* @returns {this}
|
|
79
|
-
*/
|
|
80
|
-
freeze() {
|
|
81
|
-
this.store.freeze();
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Returns a new iterator of `[K, V]` pairs in reverse order of keys.
|
|
86
|
-
* @returns {IterableIterator<[K, V]>}
|
|
87
|
-
*/
|
|
88
|
-
reversed() {
|
|
89
|
-
return this.store.reversed();
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Returns the total key/value pairs in the tree.
|
|
93
|
-
* @returns {number}
|
|
94
|
-
*/
|
|
95
|
-
get size() {
|
|
96
|
-
return this.store.size;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Check if there are no key/value pairs in the tree.
|
|
100
|
-
* @returns {boolean} `true` if is empty.
|
|
101
|
-
*/
|
|
102
|
-
empty() {
|
|
103
|
-
return this.store.empty();
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Returns `true` if the `key` exists in the tree.
|
|
107
|
-
* @param {K} key
|
|
108
|
-
* @returns {boolean} `true` if key is found, otherwise `false`.
|
|
109
|
-
*/
|
|
110
|
-
contains(key) {
|
|
111
|
-
return this.store.contains(key);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Returns `true` if the `key` exists in the tree.
|
|
115
|
-
* @param {K} key
|
|
116
|
-
* @returns {boolean} `true` if key is found, otherwise `false`.
|
|
117
|
-
*/
|
|
118
|
-
has(key) {
|
|
119
|
-
return this.store.contains(key);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Returns a new iterator of all **ordered** keys in the tree.
|
|
123
|
-
* @returns {IterableIterator<K>}
|
|
124
|
-
*/
|
|
125
|
-
keys() {
|
|
126
|
-
return this.store.keys();
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Returns a new iterator of all values **ordered** by their keys.
|
|
130
|
-
* @returns {IterableIterator<V>}
|
|
131
|
-
*/
|
|
132
|
-
values() {
|
|
133
|
-
return this.store.values();
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Returns a new iterator of all key value pairs **ordered** by their keys.
|
|
137
|
-
* @returns {IterableIterator<[K, V]>}
|
|
138
|
-
*/
|
|
139
|
-
entries() {
|
|
140
|
-
return this.store.entries();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { type Comparer } from '../operators/index.js';
|
|
2
|
-
import { Mapping } from './abc.js';
|
|
3
|
-
/**
|
|
4
|
-
* Base SplayTree node class.
|
|
5
|
-
* @private
|
|
6
|
-
*/
|
|
7
|
-
declare class Node<K = any, V = any> {
|
|
8
|
-
key: K;
|
|
9
|
-
value: V;
|
|
10
|
-
left?: Node<K, V>;
|
|
11
|
-
right?: Node<K, V>;
|
|
12
|
-
constructor(key: K, value: V);
|
|
13
|
-
get height(): number;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* A splay tree is a *self-balancing binary* search tree with the additional property that recently accessed elements are quick to access again.
|
|
17
|
-
* Insertion, look-up and removal in O(log n) *amortized* time.
|
|
18
|
-
* For many patterns of non-random operations splay trees can take better than logarithmic time, without requiring advance knowledge of the pattern.
|
|
19
|
-
* @see {@link https://en.wikipedia.org/wiki/Splay_tree Splay tree}
|
|
20
|
-
* @see {@link https://web.archive.org/web/20220930173835/http://www14.in.tum.de/personen/albers/papers/ipl02.pdf Randomized Splay Trees}
|
|
21
|
-
* @template K, V
|
|
22
|
-
*/
|
|
23
|
-
export declare class SplayTree<K, V = any> extends Mapping<K, V> {
|
|
24
|
-
protected root?: Node<K, V>;
|
|
25
|
-
protected cmp: Comparer;
|
|
26
|
-
protected randSplay: number;
|
|
27
|
-
protected count: number;
|
|
28
|
-
/**
|
|
29
|
-
* Create a new randomized Splay Tree
|
|
30
|
-
* @param compareFn
|
|
31
|
-
* @param p When an element is accessed, with probability `p` splay the tree. With probability `1 - p`, leave the tree as it is.
|
|
32
|
-
*/
|
|
33
|
-
constructor(compareFn?: any, p?: number);
|
|
34
|
-
top(): K | undefined;
|
|
35
|
-
get size(): number;
|
|
36
|
-
empty(): boolean;
|
|
37
|
-
get height(): number;
|
|
38
|
-
/**
|
|
39
|
-
* Returns the value for `key` or `undefined` if the key is not found.
|
|
40
|
-
* @param key The key to find.
|
|
41
|
-
* @returns {?V} The value for the key or `undefined`.
|
|
42
|
-
*/
|
|
43
|
-
get(key: K): V | undefined;
|
|
44
|
-
private findNode;
|
|
45
|
-
/**
|
|
46
|
-
* Inserts the `key` and `value` in the tree, or updates the value if the `key` exists.
|
|
47
|
-
* @param {K} key A key which can be any comparable value
|
|
48
|
-
* @param {V} value A value associated with the key
|
|
49
|
-
* @returns
|
|
50
|
-
*/
|
|
51
|
-
set(key: K, value: V): void;
|
|
52
|
-
private insert;
|
|
53
|
-
/**
|
|
54
|
-
* Removes a specified key if it exists in the tree. The removed value is returned or `undefined` if not found.
|
|
55
|
-
* @param {K} key The key to remove.
|
|
56
|
-
* @returns {?V} The removed value associated with `key`.
|
|
57
|
-
*/
|
|
58
|
-
remove(key: K): V | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* Returns the minimum key in the tree or subtree.
|
|
61
|
-
* @returns The minimum key.
|
|
62
|
-
*/
|
|
63
|
-
min(root?: Node<K, V>): K | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* Returns the maximum key in the tree or subtree.
|
|
66
|
-
* @returns The maximum key.
|
|
67
|
-
*/
|
|
68
|
-
max(root?: Node<K, V>): K | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* Returns the largest key that is less than a given key.
|
|
71
|
-
* @param key The given key
|
|
72
|
-
* @returns {?K} The largest key found or `undefined`.
|
|
73
|
-
*/
|
|
74
|
-
lowerBound(key: any): K | undefined;
|
|
75
|
-
/**
|
|
76
|
-
* This is the simplified top-down splaying method proposed by Sleator and Tarjan in {@link https://doi.org/10.1145%2F3828.3835 Self-Adjusting Binary Search Trees}.
|
|
77
|
-
* @param key
|
|
78
|
-
* @see {@link https://doi.org/10.1145%2F3828.3835 Self-Adjusting Binary Search Trees}
|
|
79
|
-
*/
|
|
80
|
-
splay(key: any): void;
|
|
81
|
-
add(key: K): void;
|
|
82
|
-
/**
|
|
83
|
-
* Returns `true` if the given key is in the tree.
|
|
84
|
-
* @param {K} key The key to find.
|
|
85
|
-
* @returns `true` if found.
|
|
86
|
-
*/
|
|
87
|
-
contains(key: K): boolean;
|
|
88
|
-
/** Alias of remove but returns `true` if the key was found instead of the deleted value. */
|
|
89
|
-
delete(key: K): boolean;
|
|
90
|
-
clear(): void;
|
|
91
|
-
/**
|
|
92
|
-
* Returns an ordered iterable of all the keys in the tree.
|
|
93
|
-
* @returns {Iterable<K>} An iterable of keys in-order.
|
|
94
|
-
*/
|
|
95
|
-
keys(): Iterable<K>;
|
|
96
|
-
/**
|
|
97
|
-
* Returns an ordered iterable of all the keys and values in the tree.
|
|
98
|
-
* @returns {Iterable<[K,V]>} A iterable of `[key, value]` pairs sorted by key.
|
|
99
|
-
*/
|
|
100
|
-
entries(): Iterable<[K, V]>;
|
|
101
|
-
/**
|
|
102
|
-
* Returns an ordered iterable of all the values in the tree.
|
|
103
|
-
* @returns {Iterable<V>} An iterable of values sorted by key.
|
|
104
|
-
*/
|
|
105
|
-
values(): Iterable<V>;
|
|
106
|
-
}
|
|
107
|
-
export {};
|