1
0

add size to async equality map

This commit is contained in:
2024-05-13 22:43:39 +02:00
parent 7553b70882
commit c38092c60e

View File

@@ -149,6 +149,7 @@ export function createEqualityMap<K, V>(keyComparer?: Equater<K>): EqualityMap<K
} }
export interface AsyncEqualityMap<K, V> extends Iterable<[K, V]> { export interface AsyncEqualityMap<K, V> extends Iterable<[K, V]> {
readonly size: number;
get(key: K): Promise<V | undefined>; get(key: K): Promise<V | undefined>;
set(key: K, value: V): Promise<V | undefined>; set(key: K, value: V): Promise<V | undefined>;
contains(key: K): Promise<boolean>; contains(key: K): Promise<boolean>;
@@ -162,6 +163,10 @@ export interface AsyncEqualityMap<K, V> extends Iterable<[K, V]> {
class NativeAsyncEqualityMap<K, V> implements AsyncEqualityMap<K, V> { class NativeAsyncEqualityMap<K, V> implements AsyncEqualityMap<K, V> {
readonly #map = new Map<K, V>(); readonly #map = new Map<K, V>();
get size() {
return this.#map.size;
}
async get(key: K) { async get(key: K) {
return this.#map.get(key); return this.#map.get(key);
} }
@@ -211,6 +216,10 @@ class CustomAsyncEqualityMap<K, V> implements AsyncEqualityMap<K, V> {
this.#keyComparer = keyComparer; this.#keyComparer = keyComparer;
} }
get size() {
return this.#list.length;
}
async get(key: K) { async get(key: K) {
for (const entry of this.#list) { for (const entry of this.#list) {
if (await this.#keyComparer(key, entry[0])) { if (await this.#keyComparer(key, entry[0])) {