atomic-fns 0.3.1 → 0.3.3-beta

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 (84) hide show
  1. package/.esdoc.json +2 -2
  2. package/README.md +62 -13
  3. package/core/collections/BTree.d.ts +229 -0
  4. package/core/collections/BTree.js +1165 -0
  5. package/core/collections/BTree.ts +1340 -0
  6. package/core/collections/Heap.d.ts +69 -0
  7. package/core/collections/Heap.js +181 -0
  8. package/core/collections/Heap.ts +189 -0
  9. package/core/collections/LRUCache.d.ts +152 -0
  10. package/core/collections/LRUCache.js +409 -0
  11. package/core/collections/LRUCache.ts +486 -0
  12. package/core/collections/SortedMap.d.ts +92 -0
  13. package/core/collections/SortedMap.js +130 -0
  14. package/core/collections/SortedMap.ts +146 -0
  15. package/core/collections/SortedSet.d.ts +69 -0
  16. package/core/collections/SortedSet.js +99 -0
  17. package/core/collections/SortedSet.ts +110 -0
  18. package/core/collections/SortedTree.d.ts +103 -0
  19. package/core/collections/SortedTree.js +141 -0
  20. package/core/collections/SortedTree.ts +160 -0
  21. package/core/collections/SplayTree.d.ts +105 -0
  22. package/core/collections/SplayTree.js +338 -0
  23. package/core/collections/SplayTree.ts +354 -0
  24. package/core/collections/abc.d.ts +152 -0
  25. package/core/collections/abc.js +39 -0
  26. package/core/collections/abc.ts +176 -0
  27. package/core/collections/deque.d.ts +110 -0
  28. package/core/collections/deque.js +285 -0
  29. package/core/collections/deque.ts +329 -0
  30. package/core/collections/frozenset.d.ts +19 -0
  31. package/core/collections/frozenset.js +33 -0
  32. package/core/collections/frozenset.ts +37 -0
  33. package/{src → core}/collections/index.d.ts +43 -162
  34. package/{src → core}/collections/index.js +59 -165
  35. package/{src → core}/collections/index.ts +64 -226
  36. package/core/collections/test.html +10 -0
  37. package/core/collections/typedArrays.d.ts +31 -0
  38. package/core/collections/typedArrays.js +143 -0
  39. package/core/collections/typedArrays.ts +163 -0
  40. package/{src → core}/functools/index.d.ts +2 -2
  41. package/{src → core}/functools/index.js +2 -2
  42. package/{src → core}/functools/index.ts +2 -2
  43. package/{src → core}/globals/index.d.ts +2 -7
  44. package/{src → core}/globals/index.js +5 -2
  45. package/{src → core}/globals/index.ts +6 -9
  46. package/{src → core}/index.d.ts +0 -1
  47. package/{src → core}/index.js +0 -1
  48. package/{src → core}/index.ts +0 -1
  49. package/{src → core}/itertools/index.d.ts +9 -7
  50. package/{src → core}/itertools/index.js +25 -9
  51. package/{src → core}/itertools/index.ts +39 -16
  52. package/{src → core}/math/index.d.ts +0 -0
  53. package/{src → core}/math/index.js +0 -0
  54. package/{src → core}/math/index.ts +0 -0
  55. package/core/operators/index.d.ts +148 -0
  56. package/core/operators/index.js +271 -0
  57. package/core/operators/index.ts +282 -0
  58. package/{src → core}/random/index.d.ts +0 -0
  59. package/{src → core}/random/index.js +0 -0
  60. package/{src → core}/random/index.ts +0 -0
  61. package/package.json +6 -6
  62. package/tests/BTree.spec.ts +143 -0
  63. package/tests/Cache.spec.ts +161 -0
  64. package/tests/Heap.spec.ts +66 -0
  65. package/tests/SortedMap.spec.ts +144 -0
  66. package/tests/SortedSet.spec.ts +84 -0
  67. package/tests/SortedTree.spec.ts +164 -0
  68. package/tests/SplayTree.spec.ts +121 -0
  69. package/tests/collections.spec.ts +1 -1
  70. package/tests/deque.spec.ts +107 -0
  71. package/tests/globals.spec.ts +2 -2
  72. package/tests/itertools.spec.ts +2 -2
  73. package/tests/math.spec.ts +1 -1
  74. package/tests/operators.spec.ts +5 -5
  75. package/tests/random.spec.ts +10 -10
  76. package/tsconfig.json +10 -10
  77. package/tsconfig.node.json +2 -2
  78. package/tsconfig.xo.json +2 -2
  79. package/src/datetime/index.d.ts +0 -6
  80. package/src/datetime/index.js +0 -6
  81. package/src/datetime/index.ts +0 -7
  82. package/src/operators/index.d.ts +0 -31
  83. package/src/operators/index.js +0 -171
  84. package/src/operators/index.ts +0 -175
@@ -0,0 +1,486 @@
1
+ import { Iteratee, NotImplementedError, ValueError } from '../globals/index.js'
2
+ import { IterableIterator } from '../itertools/index.js'
3
+ import { Mapping } from './abc.js'
4
+ import { getPointerArray } from './typedArrays.js'
5
+
6
+ /**
7
+ * Base append-only Cache collection that supports adding and accessing keys in O(1).
8
+ * The collection has a fixed given size (default 1024) and when full, it evicts keys using LRU approach. This operation is also O(1).
9
+ * @template K, V
10
+ */
11
+ export class Cache<K, V = any> extends Mapping<K, V> {
12
+ capacity: number
13
+ head: number = 0
14
+ tail: number = 0
15
+ count: number = 0
16
+ protected items = new Map<K, number>()
17
+ protected forward: Uint8Array | Uint16Array | Uint32Array
18
+ protected backward: Uint8Array | Uint16Array | Uint32Array
19
+ protected K: K[]
20
+ protected V: V[]
21
+
22
+ /**
23
+ * Create a new cache object of fixed size.
24
+ * @param {number} [capacity=1024] The maximum number of keys to keep in cache.
25
+ * @param {Function} [Keys=Array] The constructor to use for the Keys array. When using numeric values, a TypedArray constructor can be used.
26
+ * @param {Function} [Values=Array] The constructor to use for the Values array. When using numeric values, a TypedArray constructor can be used.
27
+ */
28
+ constructor(capacity = 1024, Keys = Array, Values = Array) {
29
+ super()
30
+ this.capacity = capacity
31
+
32
+ if (typeof this.capacity !== 'number' || this.capacity <= 0)
33
+ throw new ValueError('LRUCache capacity should be a positive integer.')
34
+ else if (!isFinite(this.capacity) || Math.floor(this.capacity) !== this.capacity)
35
+ throw new ValueError('LRUCache capacity should be a finite positive integer.')
36
+
37
+ const PointerArray = getPointerArray(capacity)
38
+ this.forward = new PointerArray(capacity)
39
+ this.backward = new PointerArray(capacity)
40
+ this.K = new Keys(capacity)
41
+ this.V = new Values(capacity)
42
+ }
43
+
44
+ /**
45
+ * This is just an alias of {@link Cache.set}.
46
+ * @param {K} key The key to add (note value will be `undefined`).
47
+ */
48
+ add(key: K) {
49
+ return this.set(key, undefined)
50
+ }
51
+
52
+ /**
53
+ * Method used to check whether the key exists in the cache.
54
+ *
55
+ * @param {any} key - Key.
56
+ * @return {boolean}
57
+ */
58
+ contains(key) {
59
+ return this.items.has(key)
60
+ }
61
+
62
+ /**
63
+ * Method used to clear the structure.
64
+ */
65
+ clear() {
66
+ this.count = 0
67
+ this.head = 0
68
+ this.tail = 0
69
+ this.items = new Map()
70
+ }
71
+
72
+ /**
73
+ * Returns the number of keys in the cache.
74
+ */
75
+ get size() {
76
+ return this.count
77
+ }
78
+
79
+ /**
80
+ * Method used to splay a value on top.
81
+ *
82
+ * @param {number} pointer - Pointer of the value to splay on top.
83
+ * @return {Cache}
84
+ */
85
+ protected splayOnTop(pointer) {
86
+ const oldHead = this.head
87
+
88
+ if (this.head === pointer) return this
89
+
90
+ const previous = this.backward[pointer]
91
+ const next = this.forward[pointer]
92
+
93
+ if (this.tail === pointer) {
94
+ this.tail = previous
95
+ } else {
96
+ this.backward[next] = previous
97
+ }
98
+
99
+ this.forward[previous] = next
100
+
101
+ this.backward[oldHead] = pointer
102
+ this.head = pointer
103
+ this.forward[pointer] = oldHead
104
+
105
+ return this
106
+ }
107
+
108
+ /**
109
+ * Method used to get the value attached to the given key. Will move the
110
+ * related key to the front of the underlying linked list.
111
+ *
112
+ * @param {any} key - Key.
113
+ * @return {any}
114
+ */
115
+ get(key) {
116
+ const pointer = this.items.get(key)
117
+
118
+ if (typeof pointer === 'undefined') return
119
+
120
+ this.splayOnTop(pointer)
121
+
122
+ return this.V[pointer]
123
+ }
124
+
125
+ /**
126
+ * Method used to set the value for the given key in the cache.
127
+ *
128
+ * @param {any} key - Key.
129
+ * @param {any} value - Value.
130
+ * @return {undefined}
131
+ */
132
+ set(key, value) {
133
+ let pointer = this.items.get(key)
134
+
135
+ // The key already exists, we just need to update the value and splay on top
136
+ if (typeof pointer !== 'undefined') {
137
+ this.splayOnTop(pointer)
138
+ this.V[pointer] = value
139
+
140
+ return
141
+ }
142
+
143
+ // The cache is not yet full
144
+ if (this.count < this.capacity) {
145
+ pointer = this.count++
146
+ }
147
+
148
+ // Cache is full, we need to drop the last value
149
+ else {
150
+ pointer = this.tail
151
+ this.tail = this.backward[pointer]
152
+ this.items.delete(this.K[pointer])
153
+ }
154
+
155
+ // Storing key & value
156
+ this.items.set(key, pointer)
157
+ this.K[pointer] = key
158
+ this.V[pointer] = value
159
+
160
+ // Moving the item at the front of the list
161
+ this.forward[pointer] = this.head
162
+ this.backward[this.head] = pointer
163
+ this.head = pointer
164
+ }
165
+
166
+ /**
167
+ * Method used to get the value attached to the given key. Does not modify
168
+ * the ordering of the underlying linked list.
169
+ *
170
+ * @param {any} key - Key.
171
+ * @return {any}
172
+ */
173
+ peek(key) {
174
+ const pointer = this.items.get(key)
175
+
176
+ if (typeof pointer === 'undefined') return
177
+
178
+ return this.V[pointer]
179
+ }
180
+
181
+ /**
182
+ * Method used to iterate over the cache's entries using a callback.
183
+ *
184
+ * @param {Iteratee<V>} iteratee - Function to call for each item.
185
+ */
186
+ forEach(iteratee: Iteratee<V>) {
187
+ let i = 0
188
+ const l = this.count
189
+
190
+ let pointer = this.head
191
+ const keys = this.K
192
+ const values = this.V
193
+ const forward = this.forward
194
+
195
+ while (i < l) {
196
+ iteratee(values[pointer], keys[pointer], this)
197
+ pointer = forward[pointer]
198
+ i++
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Method used to create an iterator over the cache's keys from most
204
+ * recently used to least recently used.
205
+ *
206
+ * @return {Iterator<K>}
207
+ */
208
+ keys() {
209
+ let i = 0
210
+ const l = this.count
211
+
212
+ let pointer = this.head
213
+ const keys = this.K
214
+ const forward = this.forward
215
+
216
+ return IterableIterator(() => {
217
+ if (i >= l) return { done: true }
218
+
219
+ const key = keys[pointer]
220
+
221
+ i++
222
+
223
+ if (i < l) pointer = forward[pointer]
224
+
225
+ return {
226
+ done: false,
227
+ value: key
228
+ }
229
+ })
230
+ }
231
+
232
+ /**
233
+ * Method used to create an iterator over the cache's values from most
234
+ * recently used to least recently used.
235
+ *
236
+ * @return {Iterator<V>}
237
+ */
238
+ values() {
239
+ let i = 0
240
+ const l = this.count
241
+
242
+ let pointer = this.head
243
+ const values = this.V
244
+ const forward = this.forward
245
+
246
+ return IterableIterator(() => {
247
+ if (i >= l) return { done: true }
248
+
249
+ const value = values[pointer]
250
+
251
+ i++
252
+
253
+ if (i < l) pointer = forward[pointer]
254
+
255
+ return {
256
+ done: false,
257
+ value
258
+ }
259
+ })
260
+ }
261
+
262
+ /**
263
+ * Method used to create an iterator over the cache's entries from most
264
+ * recently used to least recently used.
265
+ *
266
+ * @return {Iterator<[K, V]>}
267
+ */
268
+ entries() {
269
+ let i = 0
270
+ const l = this.count
271
+
272
+ let pointer = this.head
273
+ const keys = this.K
274
+ const values = this.V
275
+ const forward = this.forward
276
+
277
+ return IterableIterator<[K, V]>(() => {
278
+ if (i >= l) return { done: true }
279
+
280
+ const key = keys[pointer]
281
+ const value = values[pointer]
282
+
283
+ i++
284
+
285
+ if (i < l) pointer = forward[pointer]
286
+
287
+ return { value: [key, value] }
288
+ })
289
+ }
290
+
291
+ /**
292
+ * NotImplemented -- throws an exception.
293
+ * @param key
294
+ * @returns
295
+ */
296
+ remove(key: any) {
297
+ throw new NotImplementedError(`Base Cache class does not implement remove().`)
298
+ }
299
+
300
+ [Symbol.iterator]() {
301
+ return this.entries()
302
+ }
303
+
304
+ /**
305
+ * Convenience known methods.
306
+ */
307
+ inspect() {
308
+ const proxy = new Map()
309
+
310
+ const iterator = this.entries()
311
+ let step
312
+
313
+ while (((step = iterator.next()), !step.done)) proxy.set(step.value[0], step.value[1])
314
+
315
+ // Trick so that node displays the name of the constructor
316
+ Object.defineProperty(proxy, 'constructor', {
317
+ value: Cache,
318
+ enumerable: false
319
+ })
320
+
321
+ return proxy
322
+ }
323
+
324
+ [Symbol.for('nodejs.util.inspect.custom')]() {
325
+ return this.inspect()
326
+ }
327
+ }
328
+
329
+ /**
330
+ * Implements a Least Recently Used fixed-capacity cache which supports updating, removing, and accessing keys in O(1).
331
+ */
332
+ export class LRUCache<K, V> extends Cache<K, V> {
333
+ deletedSize = 0
334
+ deleted: Uint8Array | Uint16Array | Uint32Array
335
+
336
+ /**
337
+ * Create a new LRU cache object of fixed size.
338
+ * @param {number} [capacity=1024] The maximum number of keys to keep in cache.
339
+ * @param {Function} [Keys=Array] The constructor to use for the Keys array. When using numeric values, a TypedArray constructor can be used.
340
+ * @param {Function} [Values=Array] The constructor to use for the Values array. When using numeric values, a TypedArray constructor can be used.
341
+ */
342
+ constructor(capacity = 1024, Keys = Array, Values = Array) {
343
+ super(capacity, Keys, Values)
344
+ const PointerArray = getPointerArray(capacity)
345
+ this.deleted = new PointerArray(capacity)
346
+ }
347
+
348
+ /** Remove all elements in the cache. */
349
+ clear() {
350
+ super.clear()
351
+ this.deletedSize = 0
352
+ }
353
+
354
+ /**
355
+ * Method used to set the value for the given key in the cache.
356
+ *
357
+ * @param {any} key - Key.
358
+ * @param {any} value - Value.
359
+ * @return {undefined}
360
+ */
361
+ set(key, value) {
362
+ let pointer = this.items.get(key)
363
+
364
+ // The key already exists, we just need to update the value and splay on top
365
+ if (typeof pointer !== 'undefined') {
366
+ this.splayOnTop(pointer)
367
+ this.V[pointer] = value
368
+
369
+ return
370
+ }
371
+
372
+ // The cache is not yet full
373
+ if (this.count < this.capacity) {
374
+ if (this.deletedSize > 0) {
375
+ // If there is a "hole" in the pointer list, reuse it
376
+ pointer = this.deleted[--this.deletedSize]
377
+ } else {
378
+ // otherwise append to the pointer list
379
+ pointer = this.count
380
+ }
381
+ this.count++
382
+ }
383
+
384
+ // Cache is full, we need to drop the last value
385
+ else {
386
+ pointer = this.tail
387
+ this.tail = this.backward[pointer]
388
+ this.items.delete(this.K[pointer])
389
+ }
390
+
391
+ // Storing key & value
392
+ this.items.set(key, pointer)
393
+ this.K[pointer] = key
394
+ this.V[pointer] = value
395
+
396
+ // Moving the item at the front of the list
397
+ this.forward[pointer] = this.head
398
+ this.backward[this.head] = pointer
399
+ this.head = pointer
400
+ }
401
+
402
+ /**
403
+ * Method used to delete the entry for the given key in the cache.
404
+ *
405
+ * @param {any} key - Key.
406
+ * @return {boolean} - true if the item was present
407
+ */
408
+ delete(key) {
409
+ const pointer = this.items.get(key)
410
+
411
+ if (typeof pointer === 'undefined') {
412
+ return false
413
+ }
414
+
415
+ this.items.delete(key)
416
+
417
+ if (this.count === 1) {
418
+ this.count = 0
419
+ this.head = 0
420
+ this.tail = 0
421
+ this.deletedSize = 0
422
+ return true
423
+ }
424
+
425
+ const previous = this.backward[pointer]
426
+ const next = this.forward[pointer]
427
+
428
+ if (this.head === pointer) {
429
+ this.head = next
430
+ }
431
+ if (this.tail === pointer) {
432
+ this.tail = previous
433
+ }
434
+
435
+ this.forward[previous] = next
436
+ this.backward[next] = previous
437
+
438
+ this.count--
439
+ this.deleted[this.deletedSize++] = pointer
440
+
441
+ return true
442
+ }
443
+
444
+ /**
445
+ * Method used to remove and return the value for the given key in the cache.
446
+ *
447
+ * @param {any} key - Key.
448
+ * @return {any} The value, if present; the missing indicator if absent
449
+ */
450
+ remove(key) {
451
+ const pointer = this.items.get(key)
452
+
453
+ if (typeof pointer === 'undefined') {
454
+ return
455
+ }
456
+
457
+ const dead = this.V[pointer]
458
+ this.items.delete(key)
459
+
460
+ if (this.count === 1) {
461
+ this.count = 0
462
+ this.head = 0
463
+ this.tail = 0
464
+ this.deletedSize = 0
465
+ return dead
466
+ }
467
+
468
+ const previous = this.backward[pointer]
469
+ const next = this.forward[pointer]
470
+
471
+ if (this.head === pointer) {
472
+ this.head = next
473
+ }
474
+ if (this.tail === pointer) {
475
+ this.tail = previous
476
+ }
477
+
478
+ this.forward[previous] = next
479
+ this.backward[next] = previous
480
+
481
+ this.count--
482
+ this.deleted[this.deletedSize++] = pointer
483
+
484
+ return dead
485
+ }
486
+ }
@@ -0,0 +1,92 @@
1
+ import { Mapping } from './abc.js';
2
+ /**
3
+ * A `SortedMap` 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.
4
+ * @see {@link Operators.compare}
5
+ * @see {@link Operators.lt}
6
+ * @template K, V
7
+ */
8
+ export declare class SortedMap<K, V> extends Mapping<K, V> {
9
+ private readonly store;
10
+ /**
11
+ * Creates a new `SortedMap` object.
12
+ * @param {Iterable<[K, V]>} [iterable] Initialize the map with entries.
13
+ * @param {Comparer} [compareFn] The `compare` function to sort keys.
14
+ */
15
+ constructor(iterable?: Iterable<[K, V]>, compareFn?: any);
16
+ /**
17
+ * Adds a new `key` with a `null` value, if the `key` doesn't exist.
18
+ * @param {K} key
19
+ * @returns {this} Returns the Map object.
20
+ */
21
+ add(key: K): this;
22
+ /**
23
+ * Returns the value associated with the `key` or `undefined`.
24
+ * @param {K} key
25
+ * @returns {?V} The key value or `undefined`.
26
+ */
27
+ get(key: K): any;
28
+ /**
29
+ * Sets the value for the given `key`.
30
+ * @param {K} key
31
+ * @param {V} value
32
+ * @returns {this} Returns the Map object.
33
+ */
34
+ set(key: K, value: V): void;
35
+ /**
36
+ * Returns the smallest key in the tree.
37
+ * @returns {?K}
38
+ */
39
+ min(): K | undefined;
40
+ /**
41
+ * Returns the largest key in the tree.
42
+ * @returns {?K}
43
+ */
44
+ max(): K | undefined;
45
+ /**
46
+ * Returns `true` if the `key` existed in the map and was removed.
47
+ * @param {K} key
48
+ * @returns {boolean} `true` if key was removed, otherwise `false`.
49
+ */
50
+ delete(item: K): boolean;
51
+ /**
52
+ * Removes all key/value pairs in the tree.
53
+ */
54
+ clear(): void;
55
+ /**
56
+ * Returns the total key/value pairs in the tree.
57
+ * @returns {number}
58
+ */
59
+ get size(): number;
60
+ /**
61
+ * Check if there are no key/value pairs in the tree.
62
+ * @returns {boolean} `true` if is empty.
63
+ */
64
+ empty(): boolean;
65
+ /**
66
+ * Returns `true` if the `key` exists in the map.
67
+ * @param {K} key
68
+ * @returns {boolean} `true` if key is found, otherwise `false`.
69
+ */
70
+ contains(key: K): boolean;
71
+ /**
72
+ * Returns `true` if the `key` exists in the map.
73
+ * @param {K} key
74
+ * @returns {boolean} `true` if key is found, otherwise `false`.
75
+ */
76
+ has(key: K): boolean;
77
+ /**
78
+ * Returns a new iterator of all **ordered** keys in the map.
79
+ * @returns {Iterable<K>}
80
+ */
81
+ keys(): Iterable<K>;
82
+ /**
83
+ * Returns a new iterator of all values **ordered** by their keys.
84
+ * @returns {Iterable<V>}
85
+ */
86
+ values(): Iterable<V>;
87
+ /**
88
+ * Returns a new iterator of all key value pairs **ordered** by their keys.
89
+ * @returns {Iterable<[K, V]>}
90
+ */
91
+ entries(): Iterable<[K, V]>;
92
+ }
@@ -0,0 +1,130 @@
1
+ import { Mapping } from './abc.js';
2
+ import { SplayTree } from './SplayTree.js';
3
+ /**
4
+ * A `SortedMap` 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 Operators.compare}
6
+ * @see {@link Operators.lt}
7
+ * @template K, V
8
+ */
9
+ export class SortedMap extends Mapping {
10
+ store;
11
+ /**
12
+ * Creates a new `SortedMap` object.
13
+ * @param {Iterable<[K, V]>} [iterable] Initialize the map 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 pair of iterable) {
21
+ this.store.set(pair[0], pair[1] ?? null);
22
+ }
23
+ }
24
+ }
25
+ /**
26
+ * Adds a new `key` with a `null` value, if the `key` doesn't exist.
27
+ * @param {K} key
28
+ * @returns {this} Returns the Map object.
29
+ */
30
+ add(key) {
31
+ this.store.set(key, null);
32
+ return this;
33
+ }
34
+ /**
35
+ * Returns the value associated with the `key` or `undefined`.
36
+ * @param {K} key
37
+ * @returns {?V} The key value or `undefined`.
38
+ */
39
+ get(key) {
40
+ return this.store.get(key);
41
+ }
42
+ /**
43
+ * Sets the value for the given `key`.
44
+ * @param {K} key
45
+ * @param {V} value
46
+ * @returns {this} Returns the Map object.
47
+ */
48
+ set(key, value) {
49
+ return this.store.set(key, value);
50
+ }
51
+ /**
52
+ * Returns the smallest key in the tree.
53
+ * @returns {?K}
54
+ */
55
+ min() {
56
+ return this.store.min();
57
+ }
58
+ /**
59
+ * Returns the largest key in the tree.
60
+ * @returns {?K}
61
+ */
62
+ max() {
63
+ return this.store.max();
64
+ }
65
+ /**
66
+ * Returns `true` if the `key` existed in the map and was removed.
67
+ * @param {K} key
68
+ * @returns {boolean} `true` if key was removed, otherwise `false`.
69
+ */
70
+ delete(item) {
71
+ return this.store.remove(item) !== undefined;
72
+ }
73
+ /**
74
+ * Removes all key/value pairs in the tree.
75
+ */
76
+ clear() {
77
+ return this.store.clear();
78
+ }
79
+ /**
80
+ * Returns the total key/value pairs in the tree.
81
+ * @returns {number}
82
+ */
83
+ get size() {
84
+ return this.store.size;
85
+ }
86
+ /**
87
+ * Check if there are no key/value pairs in the tree.
88
+ * @returns {boolean} `true` if is empty.
89
+ */
90
+ empty() {
91
+ return this.store.empty();
92
+ }
93
+ /**
94
+ * Returns `true` if the `key` exists in the map.
95
+ * @param {K} key
96
+ * @returns {boolean} `true` if key is found, otherwise `false`.
97
+ */
98
+ contains(key) {
99
+ return this.store.contains(key);
100
+ }
101
+ /**
102
+ * Returns `true` if the `key` exists in the map.
103
+ * @param {K} key
104
+ * @returns {boolean} `true` if key is found, otherwise `false`.
105
+ */
106
+ has(key) {
107
+ return this.store.contains(key);
108
+ }
109
+ /**
110
+ * Returns a new iterator of all **ordered** keys in the map.
111
+ * @returns {Iterable<K>}
112
+ */
113
+ keys() {
114
+ return this.store.keys();
115
+ }
116
+ /**
117
+ * Returns a new iterator of all values **ordered** by their keys.
118
+ * @returns {Iterable<V>}
119
+ */
120
+ values() {
121
+ return this.store.values();
122
+ }
123
+ /**
124
+ * Returns a new iterator of all key value pairs **ordered** by their keys.
125
+ * @returns {Iterable<[K, V]>}
126
+ */
127
+ entries() {
128
+ return this.store.entries();
129
+ }
130
+ }