import { Polyfill as MapPolyfill } from "./Map.ts"; export interface LightSet { has(value: T): boolean; add(value: T): this; values(): Iterable; delete(value: T): boolean; } export class LightSetImpl implements LightSet { private readonly map= new MapPolyfill(); constructor(values?: T[]){ if( values === undefined ){ return; } for( let value of values ){ this.add(value); } } public has(value: T): boolean{ return this.map.has(value); } public add(value: T): this { this.map.set(value, true); return this; } public values(): Iterable { return this.map.keys(); } public delete(value: T): boolean { return this.map.delete(value); } } export const Polyfill: { new(values?: T[]): LightSet } = typeof Set !== "undefined" ? Set : LightSetImpl;