This commit is contained in:
maciejhirsz
2018-07-05 18:29:19 +02:00
parent 01da7dfc47
commit 8bec72be35
7 changed files with 43 additions and 33 deletions
-24
View File
@@ -13,27 +13,3 @@ export function idGenerator<I extends Id<any>>(): () => I {
return () => current++ as I;
}
interface HasId<I> {
id: I;
}
export class IdSet<I extends Id<any>, T> {
private map: Map<I, T> = new Map();
public add(item: T & HasId<I>) {
this.map.set(item.id, item);
}
public remove(item: T & HasId<I>) {
this.map.delete(item.id);
}
public entries(): IterableIterator<[I, T]> {
return this.map.entries();
}
public values(): IterableIterator<T> {
return this.map.values();
}
}