1
0

add equality map size

This commit is contained in:
2024-05-13 22:24:09 +02:00
parent 05390027f8
commit 35d284f030

View File

@@ -2,6 +2,7 @@ import { Equater, MaybeAsyncEquater } from "./types.js";
import { asAsyncGenerator } from "./utils.js";
export interface EqualityMap<K, V> extends Iterable<[K, V]> {
readonly size: number;
get(key: K): V | undefined;
set(key: K, value: V): V | undefined;
contains(key: K): boolean;
@@ -12,6 +13,10 @@ export interface EqualityMap<K, V> extends Iterable<[K, V]> {
class NativeEqualityMap<K, V> implements EqualityMap<K, V> {
readonly #map = new Map<K, V>();
get size() {
return this.#map.size;
}
get(key: K) {
return this.#map.get(key);
}
@@ -49,6 +54,10 @@ class CustomEqualityMap<K, V> implements EqualityMap<K, V> {
this.#keyComparer = keyComparer;
}
get size() {
return this.#list.length;
}
get(key: K) {
for (const entry of this.#list) {
if (this.#keyComparer(key, entry[0])) {