@mark1russell7/collections 0.9.3 → 0.9.5
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 +4 -0
- package/build/dag/index.d.ts +10 -10
- package/build/dag/index.js +12 -12
- package/build/dag/index.js.map +1 -1
- package/build/index.d.ts +109 -77
- package/build/index.d.ts.map +1 -1
- package/build/index.js +104 -42
- package/build/index.js.map +1 -1
- package/package.json +4 -1
- package/src/async/async-queue.ts +24 -10
- package/src/async/channels.ts +3 -3
- package/src/async/semaphore.ts +88 -0
- package/src/behaviors/bounded.ts +1 -1
- package/src/behaviors/evented.ts +1 -1
- package/src/behaviors/readonly.ts +1 -1
- package/src/behaviors/safe.ts +16 -16
- package/src/behaviors/synchronized.ts +1 -1
- package/src/behaviors/ttl.ts +6 -6
- package/src/core/events.ts +14 -14
- package/src/core/middleware.ts +6 -6
- package/src/core/policies.ts +3 -3
- package/src/dag/builder.ts +5 -5
- package/src/dag/executor.ts +5 -5
- package/src/dag/traversal.ts +2 -2
- package/src/fx/collectors.ts +1 -1
- package/src/impl/hash-map.ts +2 -2
- package/src/impl/hash-set.ts +1 -1
- package/src/impl/linked-hash-map.ts +1 -1
- package/src/index.ts +2 -0
- package/src/interfaces/collection.ts +2 -2
- package/src/interfaces/list.ts +4 -4
- package/src/interfaces/map.ts +3 -3
- package/src/interfaces/queue.ts +10 -10
- package/src/interfaces/set.ts +3 -3
- package/src/utils/defaults.ts +2 -2
- package/src/utils/helpers.ts +4 -4
package/build/index.d.ts
CHANGED
|
@@ -287,11 +287,11 @@ export type MergeFunction<T> = (current: T, incoming: T) => T;
|
|
|
287
287
|
* Policy for when to compact internal storage.
|
|
288
288
|
*/
|
|
289
289
|
export interface CompactionPolicy {
|
|
290
|
-
/**
|
|
290
|
+
/** The collection compacts when the used part of its capacity is less than this ratio, from 0 to 1. */
|
|
291
291
|
readonly minLoadFactor?: number;
|
|
292
|
-
/**
|
|
292
|
+
/** The collection compacts when its wasted space is more than this number of elements. */
|
|
293
293
|
readonly maxWastedSpace?: number;
|
|
294
|
-
/**
|
|
294
|
+
/** When it is true, the collection compacts at each removal. */
|
|
295
295
|
readonly autoCompact?: boolean;
|
|
296
296
|
}
|
|
297
297
|
/**
|
|
@@ -463,11 +463,11 @@ export interface Collection<T> extends ReadonlyCollection<T> {
|
|
|
463
463
|
*/
|
|
464
464
|
export type IsReadonly<C> = C extends ReadonlyCollection<any> ? C extends Collection<any> ? false : true : false;
|
|
465
465
|
/**
|
|
466
|
-
*
|
|
466
|
+
* This type gives the element type of a collection.
|
|
467
467
|
*/
|
|
468
468
|
export type ElementOf<C> = C extends ReadonlyCollection<infer T> ? T : never;
|
|
469
469
|
/**
|
|
470
|
-
*
|
|
470
|
+
* This type makes a collection readonly: it removes the methods that change the collection.
|
|
471
471
|
*/
|
|
472
472
|
export type Readonly<C extends Collection<any>> = C extends Collection<infer T> ? ReadonlyCollection<T> : never;
|
|
473
473
|
/**
|
|
@@ -532,7 +532,7 @@ export declare const hasCapability: <C extends Collection<any>, K extends keyof
|
|
|
532
532
|
*/
|
|
533
533
|
export interface Evented<E extends Record<string, any>> {
|
|
534
534
|
/**
|
|
535
|
-
*
|
|
535
|
+
* This method subscribes a listener to an event.
|
|
536
536
|
* @returns Unsubscribe function
|
|
537
537
|
*/
|
|
538
538
|
on<K extends keyof E>(event: K, handler: (payload: E[K]) => void): () => void;
|
|
@@ -567,7 +567,7 @@ export interface SafeCollection {
|
|
|
567
567
|
readonly safe: unknown;
|
|
568
568
|
}
|
|
569
569
|
/**
|
|
570
|
-
*
|
|
570
|
+
* This type gives the element type of a collection.
|
|
571
571
|
*/
|
|
572
572
|
export type ElementType<C> = C extends {
|
|
573
573
|
[Symbol.iterator](): Iterator<infer T>;
|
|
@@ -577,7 +577,7 @@ export type ElementType<C> = C extends {
|
|
|
577
577
|
peek(): infer T;
|
|
578
578
|
} ? T : never;
|
|
579
579
|
/**
|
|
580
|
-
*
|
|
580
|
+
* This type changes each method of a type so that it gives its async equivalent.
|
|
581
581
|
*/
|
|
582
582
|
export type Asyncify<C> = { [K in keyof C]: C[K] extends ((...args: infer Args) => infer R) ? (...args: Args) => Promise<R> : C[K]; };
|
|
583
583
|
/**
|
|
@@ -634,11 +634,11 @@ export type WithCapability<C, Cap> = C & Cap;
|
|
|
634
634
|
export declare abstract class CollectionBuilder<C> {
|
|
635
635
|
protected middleware: Middleware<C>[];
|
|
636
636
|
/**
|
|
637
|
-
*
|
|
637
|
+
* This method applies a custom middleware.
|
|
638
638
|
*/
|
|
639
639
|
use(middleware: Middleware<C>): this;
|
|
640
640
|
/**
|
|
641
|
-
*
|
|
641
|
+
* This method builds the final collection: it composes all middleware with the base.
|
|
642
642
|
*/
|
|
643
643
|
abstract build(): C;
|
|
644
644
|
}
|
|
@@ -720,7 +720,7 @@ export type EventMap = Record<string, any>;
|
|
|
720
720
|
export declare class Emitter<E extends EventMap> {
|
|
721
721
|
private listeners;
|
|
722
722
|
/**
|
|
723
|
-
*
|
|
723
|
+
* This method subscribes a listener to an event.
|
|
724
724
|
*
|
|
725
725
|
* @param event The event name
|
|
726
726
|
* @param listener The callback to invoke when event is emitted
|
|
@@ -728,7 +728,7 @@ export declare class Emitter<E extends EventMap> {
|
|
|
728
728
|
*/
|
|
729
729
|
on<K extends keyof E>(event: K, listener: Listener<E[K]>): Unsubscribe;
|
|
730
730
|
/**
|
|
731
|
-
*
|
|
731
|
+
* This method subscribes a listener to an event, and unsubscribes it after the first emission.
|
|
732
732
|
*
|
|
733
733
|
* @param event The event name
|
|
734
734
|
* @param listener The callback to invoke once
|
|
@@ -736,40 +736,40 @@ export declare class Emitter<E extends EventMap> {
|
|
|
736
736
|
*/
|
|
737
737
|
once<K extends keyof E>(event: K, listener: Listener<E[K]>): Unsubscribe;
|
|
738
738
|
/**
|
|
739
|
-
*
|
|
739
|
+
* This method emits an event to all registered listeners.
|
|
740
740
|
*
|
|
741
741
|
* @param event The event name
|
|
742
742
|
* @param payload The event payload
|
|
743
743
|
*/
|
|
744
744
|
emit<K extends keyof E>(event: K, payload: E[K]): void;
|
|
745
745
|
/**
|
|
746
|
-
*
|
|
746
|
+
* This method removes all listeners of an event, or of all events when the call gives no event.
|
|
747
747
|
*
|
|
748
748
|
* @param event Optional event name to clear listeners for
|
|
749
749
|
*/
|
|
750
750
|
off<K extends keyof E>(event?: K): void;
|
|
751
751
|
/**
|
|
752
|
-
*
|
|
752
|
+
* This method gives the number of listeners of an event.
|
|
753
753
|
*
|
|
754
754
|
* @param event The event name
|
|
755
755
|
* @returns Number of registered listeners
|
|
756
756
|
*/
|
|
757
757
|
listenerCount<K extends keyof E>(event: K): number;
|
|
758
758
|
/**
|
|
759
|
-
*
|
|
759
|
+
* This method gives the names of the events that have one or more listeners.
|
|
760
760
|
*/
|
|
761
761
|
eventNames(): (keyof E)[];
|
|
762
762
|
/**
|
|
763
|
-
*
|
|
763
|
+
* This method gives true when an event has one or more listeners.
|
|
764
764
|
*/
|
|
765
765
|
hasListeners<K extends keyof E>(event: K): boolean;
|
|
766
766
|
/**
|
|
767
|
-
*
|
|
767
|
+
* This method removes all listeners and releases the resources.
|
|
768
768
|
*/
|
|
769
769
|
dispose(): void;
|
|
770
770
|
}
|
|
771
771
|
/**
|
|
772
|
-
*
|
|
772
|
+
* This function makes an event emitter for an event map.
|
|
773
773
|
*
|
|
774
774
|
* This is a convenience factory function.
|
|
775
775
|
*
|
|
@@ -795,15 +795,15 @@ export declare class EventBatcher<E extends EventMap, K extends keyof E> {
|
|
|
795
795
|
private timer;
|
|
796
796
|
constructor(emitter: Emitter<E & { [P in `batch-${K & string}`]: E[K][]; }>, event: K, delayMs: number);
|
|
797
797
|
/**
|
|
798
|
-
*
|
|
798
|
+
* This method adds an event to the current batch.
|
|
799
799
|
*/
|
|
800
800
|
queue(payload: E[K]): void;
|
|
801
801
|
/**
|
|
802
|
-
*
|
|
802
|
+
* This method emits all batched events at once.
|
|
803
803
|
*/
|
|
804
804
|
flush(): void;
|
|
805
805
|
/**
|
|
806
|
-
*
|
|
806
|
+
* This method sends the events of the batch and releases the resources.
|
|
807
807
|
*/
|
|
808
808
|
dispose(): void;
|
|
809
809
|
}
|
|
@@ -824,7 +824,7 @@ export declare class AsyncEmitter<E extends EventMap> {
|
|
|
824
824
|
private listeners;
|
|
825
825
|
on<K extends keyof E>(event: K, listener: Listener<E[K]>): Unsubscribe;
|
|
826
826
|
/**
|
|
827
|
-
*
|
|
827
|
+
* This method emits an event and waits until all async listeners complete.
|
|
828
828
|
*
|
|
829
829
|
* @param event The event name
|
|
830
830
|
* @param payload The event payload
|
|
@@ -848,7 +848,7 @@ export declare class AsyncEmitter<E extends EventMap> {
|
|
|
848
848
|
*/
|
|
849
849
|
export declare const forwardEvent: <E1 extends EventMap, E2 extends EventMap, K1 extends keyof E1, K2 extends keyof E2>(source: Emitter<E1>, target: Emitter<E2>, sourceEvent: K1, targetEvent: K2, transform?: (payload: E1[K1]) => E2[K2]) => Unsubscribe;
|
|
850
850
|
/**
|
|
851
|
-
*
|
|
851
|
+
* This function makes a filtered event subscription that fires only when the predicate is true.
|
|
852
852
|
*
|
|
853
853
|
* @example
|
|
854
854
|
* const emitter = new Emitter<{ change: { value: number } }>()
|
|
@@ -1025,14 +1025,14 @@ export interface List<T> extends ReadonlyList<T>, Collection<T> {
|
|
|
1025
1025
|
*/
|
|
1026
1026
|
push(element: T): void;
|
|
1027
1027
|
/**
|
|
1028
|
-
*
|
|
1028
|
+
* This method removes the last element of this list and gives it.
|
|
1029
1029
|
*
|
|
1030
1030
|
* @returns The last element
|
|
1031
1031
|
* @throws Error if list is empty
|
|
1032
1032
|
*/
|
|
1033
1033
|
pop(): T;
|
|
1034
1034
|
/**
|
|
1035
|
-
*
|
|
1035
|
+
* This method removes the first element of this list and gives it.
|
|
1036
1036
|
*
|
|
1037
1037
|
* @returns The first element
|
|
1038
1038
|
* @throws Error if list is empty
|
|
@@ -1074,7 +1074,7 @@ export interface Stack<T> extends Iterable<T> {
|
|
|
1074
1074
|
*/
|
|
1075
1075
|
push(element: T): void;
|
|
1076
1076
|
/**
|
|
1077
|
-
*
|
|
1077
|
+
* This method removes the top element and gives it.
|
|
1078
1078
|
*
|
|
1079
1079
|
* @throws Error if stack is empty
|
|
1080
1080
|
*/
|
|
@@ -1373,11 +1373,11 @@ export interface NavigableMap<K, V> extends SortedMap<K, V> {
|
|
|
1373
1373
|
*/
|
|
1374
1374
|
lastEntry(): Entry<K, V> | undefined;
|
|
1375
1375
|
/**
|
|
1376
|
-
*
|
|
1376
|
+
* This method removes the first (lowest) entry and gives it, or gives undefined when the map is empty.
|
|
1377
1377
|
*/
|
|
1378
1378
|
pollFirstEntry(): Entry<K, V> | undefined;
|
|
1379
1379
|
/**
|
|
1380
|
-
*
|
|
1380
|
+
* This method removes the last (highest) entry and gives it, or gives undefined when the map is empty.
|
|
1381
1381
|
*/
|
|
1382
1382
|
pollLastEntry(): Entry<K, V> | undefined;
|
|
1383
1383
|
/**
|
|
@@ -1582,11 +1582,11 @@ export interface NavigableSet<T> extends SortedSet<T> {
|
|
|
1582
1582
|
*/
|
|
1583
1583
|
higher(element: T): T | undefined;
|
|
1584
1584
|
/**
|
|
1585
|
-
*
|
|
1585
|
+
* This method removes the first (lowest) element and gives it, or gives undefined when the set is empty.
|
|
1586
1586
|
*/
|
|
1587
1587
|
pollFirst(): T | undefined;
|
|
1588
1588
|
/**
|
|
1589
|
-
*
|
|
1589
|
+
* This method removes the last (highest) element and gives it, or gives undefined when the set is empty.
|
|
1590
1590
|
*/
|
|
1591
1591
|
pollLast(): T | undefined;
|
|
1592
1592
|
/**
|
|
@@ -1742,7 +1742,7 @@ export declare function dropIndex(point: Point, centers: readonly Point[], rowTo
|
|
|
1742
1742
|
*/
|
|
1743
1743
|
interface ReadonlyQueue<T> extends ReadonlyCollection<T> {
|
|
1744
1744
|
/**
|
|
1745
|
-
*
|
|
1745
|
+
* This method gives the head of this queue, and does not remove it.
|
|
1746
1746
|
*
|
|
1747
1747
|
* @returns The head element
|
|
1748
1748
|
* @throws Error if queue is empty
|
|
@@ -1771,14 +1771,14 @@ interface Queue<T> extends ReadonlyQueue<T>, Collection<T> {
|
|
|
1771
1771
|
*/
|
|
1772
1772
|
offer(element: T): boolean;
|
|
1773
1773
|
/**
|
|
1774
|
-
*
|
|
1774
|
+
* This method removes the head of this queue and gives it.
|
|
1775
1775
|
*
|
|
1776
1776
|
* @returns The head element
|
|
1777
1777
|
* @throws Error if queue is empty
|
|
1778
1778
|
*/
|
|
1779
1779
|
poll(): T;
|
|
1780
1780
|
/**
|
|
1781
|
-
*
|
|
1781
|
+
* This method removes the head of this queue and gives it, or gives undefined when the queue is empty.
|
|
1782
1782
|
*/
|
|
1783
1783
|
pollOrUndefined(): T | undefined;
|
|
1784
1784
|
/**
|
|
@@ -1787,7 +1787,7 @@ interface Queue<T> extends ReadonlyQueue<T>, Collection<T> {
|
|
|
1787
1787
|
*/
|
|
1788
1788
|
enqueue(element: T): boolean;
|
|
1789
1789
|
/**
|
|
1790
|
-
*
|
|
1790
|
+
* This method is an alias for poll(). It removes the element at the front of the queue and gives it.
|
|
1791
1791
|
* This method is here for consistency with standard queue terminology.
|
|
1792
1792
|
*/
|
|
1793
1793
|
dequeue(): T;
|
|
@@ -1812,13 +1812,13 @@ interface Deque<T> extends Queue<T> {
|
|
|
1812
1812
|
*/
|
|
1813
1813
|
offerFirst(element: T): boolean;
|
|
1814
1814
|
/**
|
|
1815
|
-
*
|
|
1815
|
+
* This method removes the first element and gives it.
|
|
1816
1816
|
*
|
|
1817
1817
|
* @throws Error if deque is empty
|
|
1818
1818
|
*/
|
|
1819
1819
|
removeFirst(): T;
|
|
1820
1820
|
/**
|
|
1821
|
-
*
|
|
1821
|
+
* This method removes the first element and gives it, or gives undefined when the deque is empty.
|
|
1822
1822
|
*/
|
|
1823
1823
|
pollFirst(): T | undefined;
|
|
1824
1824
|
/**
|
|
@@ -1843,13 +1843,13 @@ interface Deque<T> extends Queue<T> {
|
|
|
1843
1843
|
*/
|
|
1844
1844
|
offerLast(element: T): boolean;
|
|
1845
1845
|
/**
|
|
1846
|
-
*
|
|
1846
|
+
* This method removes the last element and gives it.
|
|
1847
1847
|
*
|
|
1848
1848
|
* @throws Error if deque is empty
|
|
1849
1849
|
*/
|
|
1850
1850
|
removeLast(): T;
|
|
1851
1851
|
/**
|
|
1852
|
-
*
|
|
1852
|
+
* This method removes the last element and gives it, or gives undefined when the deque is empty.
|
|
1853
1853
|
*/
|
|
1854
1854
|
pollLast(): T | undefined;
|
|
1855
1855
|
/**
|
|
@@ -1895,7 +1895,7 @@ interface BlockingQueue<T> extends Queue<T> {
|
|
|
1895
1895
|
*/
|
|
1896
1896
|
put(element: T, timeoutMs?: number): Promise<void>;
|
|
1897
1897
|
/**
|
|
1898
|
-
*
|
|
1898
|
+
* This method removes the head and gives it. It waits until an element is available.
|
|
1899
1899
|
*
|
|
1900
1900
|
* @param timeoutMs Optional timeout in milliseconds
|
|
1901
1901
|
* @returns Promise that resolves to the head element
|
|
@@ -1948,7 +1948,7 @@ interface AsyncQueue$1<T> extends AsyncIterable<T> {
|
|
|
1948
1948
|
*/
|
|
1949
1949
|
put(element: T): Promise<void>;
|
|
1950
1950
|
/**
|
|
1951
|
-
*
|
|
1951
|
+
* This method removes the next element and gives it.
|
|
1952
1952
|
* Waits for an element if queue is empty.
|
|
1953
1953
|
*/
|
|
1954
1954
|
take(): Promise<T>;
|
|
@@ -2222,7 +2222,7 @@ export interface HashMapOptions<K, V> {
|
|
|
2222
2222
|
*/
|
|
2223
2223
|
initialCapacity?: number;
|
|
2224
2224
|
/**
|
|
2225
|
-
*
|
|
2225
|
+
* This option is the load factor threshold for a resize, from 0 to 1.
|
|
2226
2226
|
* When size > capacity * loadFactor, the map resizes.
|
|
2227
2227
|
* @default 0.75
|
|
2228
2228
|
*/
|
|
@@ -2247,7 +2247,7 @@ export interface HashMapOptions<K, V> {
|
|
|
2247
2247
|
* HashMap<K, V> - Hash table implementation with custom equality/hashing.
|
|
2248
2248
|
*
|
|
2249
2249
|
* This class uses separate chaining for collision resolution.
|
|
2250
|
-
*
|
|
2250
|
+
* The map resizes when its load factor is more than the threshold.
|
|
2251
2251
|
*
|
|
2252
2252
|
* Not thread-safe. Use synchronized() behavior for concurrent access.
|
|
2253
2253
|
*/
|
|
@@ -2350,7 +2350,7 @@ export interface LinkedHashMapOptions<K, V> {
|
|
|
2350
2350
|
*/
|
|
2351
2351
|
initialCapacity?: number;
|
|
2352
2352
|
/**
|
|
2353
|
-
*
|
|
2353
|
+
* This option is the load factor before a resize.
|
|
2354
2354
|
* @default 0.75
|
|
2355
2355
|
*/
|
|
2356
2356
|
loadFactor?: number;
|
|
@@ -2768,7 +2768,7 @@ export interface HashSetOptions<T> {
|
|
|
2768
2768
|
*/
|
|
2769
2769
|
initialCapacity?: number;
|
|
2770
2770
|
/**
|
|
2771
|
-
*
|
|
2771
|
+
* This option is the load factor threshold for a resize.
|
|
2772
2772
|
* @default 0.75
|
|
2773
2773
|
*/
|
|
2774
2774
|
loadFactor?: number;
|
|
@@ -3194,23 +3194,23 @@ export declare const unmodifiableCollection: typeof readonlyCollection;
|
|
|
3194
3194
|
*/
|
|
3195
3195
|
export interface SafeListOperations<T> {
|
|
3196
3196
|
/**
|
|
3197
|
-
*
|
|
3197
|
+
* This method gives the element at an index, as an optional.
|
|
3198
3198
|
*/
|
|
3199
3199
|
get(index: number): Optional<T>;
|
|
3200
3200
|
/**
|
|
3201
|
-
*
|
|
3201
|
+
* This method sets the element at an index. It gives a Result with the old value or an error.
|
|
3202
3202
|
*/
|
|
3203
3203
|
set(index: number, element: T): Result<T, string>;
|
|
3204
3204
|
/**
|
|
3205
|
-
*
|
|
3205
|
+
* This method removes the element at an index. It gives a Result with the removed value or an error.
|
|
3206
3206
|
*/
|
|
3207
3207
|
removeAt(index: number): Result<T, string>;
|
|
3208
3208
|
/**
|
|
3209
|
-
*
|
|
3209
|
+
* This method gives the first element, as an optional.
|
|
3210
3210
|
*/
|
|
3211
3211
|
first(): Optional<T>;
|
|
3212
3212
|
/**
|
|
3213
|
-
*
|
|
3213
|
+
* This method gives the last element, as an optional.
|
|
3214
3214
|
*/
|
|
3215
3215
|
last(): Optional<T>;
|
|
3216
3216
|
/**
|
|
@@ -3227,15 +3227,15 @@ export interface SafeListOperations<T> {
|
|
|
3227
3227
|
*/
|
|
3228
3228
|
export interface SafeQueueOperations<T> {
|
|
3229
3229
|
/**
|
|
3230
|
-
*
|
|
3230
|
+
* This method gives the head element as an optional, and does not remove it.
|
|
3231
3231
|
*/
|
|
3232
3232
|
peek(): Optional<T>;
|
|
3233
3233
|
/**
|
|
3234
|
-
*
|
|
3234
|
+
* This method removes the head element and gives it as an optional.
|
|
3235
3235
|
*/
|
|
3236
3236
|
poll(): Optional<T>;
|
|
3237
3237
|
/**
|
|
3238
|
-
*
|
|
3238
|
+
* This method dequeues the head element and gives it as an optional.
|
|
3239
3239
|
*/
|
|
3240
3240
|
dequeue(): Optional<T>;
|
|
3241
3241
|
}
|
|
@@ -3244,23 +3244,23 @@ export interface SafeQueueOperations<T> {
|
|
|
3244
3244
|
*/
|
|
3245
3245
|
export interface SafeDequeOperations<T> extends SafeQueueOperations<T> {
|
|
3246
3246
|
/**
|
|
3247
|
-
*
|
|
3247
|
+
* This method gives the first element as an optional, and does not remove it.
|
|
3248
3248
|
*/
|
|
3249
3249
|
peekFirst(): Optional<T>;
|
|
3250
3250
|
/**
|
|
3251
|
-
*
|
|
3251
|
+
* This method gives the last element as an optional, and does not remove it.
|
|
3252
3252
|
*/
|
|
3253
3253
|
peekLast(): Optional<T>;
|
|
3254
3254
|
/**
|
|
3255
|
-
*
|
|
3255
|
+
* This method removes the first element and gives it as an optional.
|
|
3256
3256
|
*/
|
|
3257
3257
|
pollFirst(): Optional<T>;
|
|
3258
3258
|
/**
|
|
3259
|
-
*
|
|
3259
|
+
* This method removes the last element and gives it as an optional.
|
|
3260
3260
|
*/
|
|
3261
3261
|
pollLast(): Optional<T>;
|
|
3262
3262
|
/**
|
|
3263
|
-
*
|
|
3263
|
+
* This method pops the top element and gives it as an optional.
|
|
3264
3264
|
*/
|
|
3265
3265
|
pop(): Optional<T>;
|
|
3266
3266
|
}
|
|
@@ -3269,15 +3269,15 @@ export interface SafeDequeOperations<T> extends SafeQueueOperations<T> {
|
|
|
3269
3269
|
*/
|
|
3270
3270
|
export interface SafeMapOperations<K, V> {
|
|
3271
3271
|
/**
|
|
3272
|
-
*
|
|
3272
|
+
* This method gives the value of a key, as an optional.
|
|
3273
3273
|
*/
|
|
3274
3274
|
get(key: K): Optional<V>;
|
|
3275
3275
|
/**
|
|
3276
|
-
*
|
|
3276
|
+
* This method sets the value of a key. It gives a Result with the old value or a success.
|
|
3277
3277
|
*/
|
|
3278
3278
|
set(key: K, value: V): Result<V | undefined, string>;
|
|
3279
3279
|
/**
|
|
3280
|
-
*
|
|
3280
|
+
* This method deletes a key. It gives a Result with the deleted value or an error.
|
|
3281
3281
|
*/
|
|
3282
3282
|
delete(key: K): Result<V | undefined, string>;
|
|
3283
3283
|
}
|
|
@@ -3674,21 +3674,21 @@ export declare class TTLCache<K, V> {
|
|
|
3674
3674
|
delete(key: K): boolean;
|
|
3675
3675
|
clear(): void;
|
|
3676
3676
|
/**
|
|
3677
|
-
*
|
|
3677
|
+
* This method removes the expired entries at once.
|
|
3678
3678
|
*/
|
|
3679
3679
|
cleanup(): void;
|
|
3680
3680
|
/**
|
|
3681
|
-
*
|
|
3681
|
+
* This method gives the remaining TTL of a key, in milliseconds.
|
|
3682
3682
|
* This method gives undefined if key doesn't exist or is expired.
|
|
3683
3683
|
*/
|
|
3684
3684
|
getTTL(key: K): number | undefined;
|
|
3685
3685
|
/**
|
|
3686
|
-
*
|
|
3686
|
+
* This method updates the TTL of a key that is in the map.
|
|
3687
3687
|
*/
|
|
3688
3688
|
touch(key: K, customTTL?: number): boolean;
|
|
3689
3689
|
private startExpirationCheck;
|
|
3690
3690
|
/**
|
|
3691
|
-
*
|
|
3691
|
+
* This method stops the background expiration checker and cleans up.
|
|
3692
3692
|
*/
|
|
3693
3693
|
dispose(): void;
|
|
3694
3694
|
keys(): IterableIterator<K>;
|
|
@@ -3707,7 +3707,8 @@ export declare function ttlCache<K, V>(ttl: number, options?: {
|
|
|
3707
3707
|
*/
|
|
3708
3708
|
export interface AsyncQueueOptions {
|
|
3709
3709
|
/**
|
|
3710
|
-
*
|
|
3710
|
+
* The maximum number of elements: a whole number of 0 or more, or `Infinity` for no bound.
|
|
3711
|
+
* Any other value gives a `RangeError`.
|
|
3711
3712
|
* @default Infinity
|
|
3712
3713
|
*/
|
|
3713
3714
|
capacity?: number;
|
|
@@ -3758,7 +3759,7 @@ export declare class AsyncQueue<T> implements AsyncQueue$1<T> {
|
|
|
3758
3759
|
*/
|
|
3759
3760
|
put(element: T, timeout?: number): Promise<void>;
|
|
3760
3761
|
/**
|
|
3761
|
-
*
|
|
3762
|
+
* This method removes an element from the queue and gives it.
|
|
3762
3763
|
* If the queue is empty, waits until an element is available.
|
|
3763
3764
|
*
|
|
3764
3765
|
* @throws Error if queue is closed and empty
|
|
@@ -3843,6 +3844,8 @@ export declare class AsyncQueue<T> implements AsyncQueue$1<T> {
|
|
|
3843
3844
|
/**
|
|
3844
3845
|
* Factory function to make an AsyncQueue.
|
|
3845
3846
|
*
|
|
3847
|
+
* @throws RangeError if the capacity is not a whole number of 0 or more, or `Infinity`
|
|
3848
|
+
*
|
|
3846
3849
|
* @example
|
|
3847
3850
|
* const queue = asyncQueue<number>({ capacity: 100 })
|
|
3848
3851
|
* await queue.put(42)
|
|
@@ -3863,14 +3866,14 @@ export declare class Channel<T> {
|
|
|
3863
3866
|
constructor(bufferSize?: number);
|
|
3864
3867
|
/**
|
|
3865
3868
|
* This method sends a value through the channel.
|
|
3866
|
-
*
|
|
3869
|
+
* The call blocks while the buffer of the channel is full.
|
|
3867
3870
|
*
|
|
3868
3871
|
* @throws Error if channel is closed
|
|
3869
3872
|
*/
|
|
3870
3873
|
send(value: T): Promise<void>;
|
|
3871
3874
|
/**
|
|
3872
3875
|
* This method receives a value from the channel.
|
|
3873
|
-
*
|
|
3876
|
+
* The call blocks while no value is available.
|
|
3874
3877
|
*
|
|
3875
3878
|
* @throws Error if channel is closed and empty
|
|
3876
3879
|
*/
|
|
@@ -4001,7 +4004,7 @@ export declare function pipeline<T, U>(input: Channel<T>, transform: (value: T)
|
|
|
4001
4004
|
*/
|
|
4002
4005
|
export declare function fanOut<T>(input: Channel<T>, count: number, bufferSize?: number): Channel<T>[];
|
|
4003
4006
|
/**
|
|
4004
|
-
* Fan-in: merges multiple input channels into one output channel.
|
|
4007
|
+
* Fan-in: this function merges multiple input channels into one output channel.
|
|
4005
4008
|
*
|
|
4006
4009
|
* @example
|
|
4007
4010
|
* const ch1 = channel<number>()
|
|
@@ -4086,6 +4089,35 @@ export type Settled<T> = {
|
|
|
4086
4089
|
* their rejections are not reported as unhandled.
|
|
4087
4090
|
*/
|
|
4088
4091
|
export declare function asSettled<T>(promises: Iterable<Promise<T>>): AsyncGenerator<Settled<T>, void, undefined>;
|
|
4092
|
+
/**
|
|
4093
|
+
* semaphore - A bound on the tasks that run at the same time.
|
|
4094
|
+
*
|
|
4095
|
+
* @example
|
|
4096
|
+
* const writes = semaphore(4);
|
|
4097
|
+
* // At most 4 writes run at once. The others wait in the order that they came.
|
|
4098
|
+
* await Promise.all(items.map((item) => writes.run(() => store.set(item.id, item))));
|
|
4099
|
+
*/
|
|
4100
|
+
/** A semaphore: a count of permits, and a queue of the callers that wait for one. */
|
|
4101
|
+
export interface Semaphore {
|
|
4102
|
+
/** The permits of the semaphore. */
|
|
4103
|
+
readonly permits: number;
|
|
4104
|
+
/** The permits that no caller holds. */
|
|
4105
|
+
readonly available: number;
|
|
4106
|
+
/** The callers that wait for a permit. */
|
|
4107
|
+
readonly waiting: number;
|
|
4108
|
+
/**
|
|
4109
|
+
* This method gives a permit. It waits while all permits are held. The waiting callers get the permits in the order
|
|
4110
|
+
* that they came. The result is the release of the permit. A second call of the release does nothing.
|
|
4111
|
+
*/
|
|
4112
|
+
acquire(): Promise<() => void>;
|
|
4113
|
+
/** This method starts a task with a permit. The permit goes back when the task ends, also when it throws. */
|
|
4114
|
+
run<R>(task: () => R | PromiseLike<R>): Promise<R>;
|
|
4115
|
+
}
|
|
4116
|
+
/**
|
|
4117
|
+
* This function makes a semaphore with `permits` permits. The value is a whole number of 1 or more, or `Infinity`
|
|
4118
|
+
* for no bound. Another value throws a `RangeError`.
|
|
4119
|
+
*/
|
|
4120
|
+
export declare function semaphore(permits: number): Semaphore;
|
|
4089
4121
|
/**
|
|
4090
4122
|
* Functional operations for iterables (lazy sync transforms).
|
|
4091
4123
|
*
|
|
@@ -4310,7 +4342,7 @@ declare function toMap<T, K, V>(keyExtractor: (element: T) => K, valueExtractor:
|
|
|
4310
4342
|
*/
|
|
4311
4343
|
export declare function groupingBy<T, K>(classifier: (element: T) => K): Collector<T, HashMap<K, ArrayList<T>>, HashMap<K, ArrayList<T>>>;
|
|
4312
4344
|
/**
|
|
4313
|
-
*
|
|
4345
|
+
* This function groups the elements and transforms each group with a downstream collector.
|
|
4314
4346
|
*
|
|
4315
4347
|
* @example
|
|
4316
4348
|
* const countByAge = collect(
|
|
@@ -4488,7 +4520,7 @@ export declare const hashString: (str: string) => number;
|
|
|
4488
4520
|
*/
|
|
4489
4521
|
export declare const hashNumber: (num: number) => number;
|
|
4490
4522
|
/**
|
|
4491
|
-
*
|
|
4523
|
+
* This function combines hash values into one hash.
|
|
4492
4524
|
* Useful for hashing objects with multiple fields.
|
|
4493
4525
|
*
|
|
4494
4526
|
* @example
|
|
@@ -4497,7 +4529,7 @@ export declare const hashNumber: (num: number) => number;
|
|
|
4497
4529
|
*/
|
|
4498
4530
|
export declare const combineHashes: (...hashes: number[]) => number;
|
|
4499
4531
|
/**
|
|
4500
|
-
*
|
|
4532
|
+
* This function makes a hash function that hashes by a property.
|
|
4501
4533
|
*
|
|
4502
4534
|
* @example
|
|
4503
4535
|
* const userHash = hashBy<User>((u) => u.id)
|
|
@@ -4709,7 +4741,7 @@ declare function toMap$2<T, K, V>(iterable: Iterable<T>, keyExtractor: (value: T
|
|
|
4709
4741
|
*/
|
|
4710
4742
|
export declare function groupBy<T, K>(iterable: Iterable<T>, keyExtractor: (value: T) => K): HashMap<K, ArrayList<T>>;
|
|
4711
4743
|
/**
|
|
4712
|
-
*
|
|
4744
|
+
* This function gives true when an index is in the bounds [0, size).
|
|
4713
4745
|
* This function throws RangeError if out of bounds.
|
|
4714
4746
|
*
|
|
4715
4747
|
* @param index The index to check
|
|
@@ -4719,7 +4751,7 @@ export declare function groupBy<T, K>(iterable: Iterable<T>, keyExtractor: (valu
|
|
|
4719
4751
|
*/
|
|
4720
4752
|
export declare function checkBounds(index: number, size: number, collectionName?: string): void;
|
|
4721
4753
|
/**
|
|
4722
|
-
*
|
|
4754
|
+
* This function gives true when an index is valid for an insertion, in [0, size].
|
|
4723
4755
|
* In this function, index === size is correct for append operations.
|
|
4724
4756
|
*
|
|
4725
4757
|
* @param index The index to check
|
|
@@ -4729,7 +4761,7 @@ export declare function checkBounds(index: number, size: number, collectionName?
|
|
|
4729
4761
|
*/
|
|
4730
4762
|
export declare function checkInsertBounds(index: number, size: number, collectionName?: string): void;
|
|
4731
4763
|
/**
|
|
4732
|
-
*
|
|
4764
|
+
* This function gives true when a range [start, end) is valid.
|
|
4733
4765
|
*
|
|
4734
4766
|
* @param start Start index (inclusive)
|
|
4735
4767
|
* @param end End index (exclusive)
|
|
@@ -4757,7 +4789,7 @@ export declare function findIndex<T>(array: T[], element: T, eq: Eq<T>): number;
|
|
|
4757
4789
|
*/
|
|
4758
4790
|
export declare function findLastIndex<T>(array: T[], element: T, eq: Eq<T>): number;
|
|
4759
4791
|
/**
|
|
4760
|
-
*
|
|
4792
|
+
* This function gives true when an array has an element, with a custom equality.
|
|
4761
4793
|
*
|
|
4762
4794
|
* @param array The array to search
|
|
4763
4795
|
* @param element The element to find
|