tsmathlib
Version:
Typescript Version Math/Physics/CG Library
40 lines (31 loc) • 642 B
text/typescript
interface IntfKeyVal {
(key: string, val: any): void
}
export class HashSet<T> {
private items: { [key: string]: T }
constructor() {
this.items = {}
}
set(key: string, value: T): void {
this.items[key] = value
}
delete(key: string): boolean {
return delete this.items[key]
}
has(key: string): boolean {
return key in this.items
}
get(key: string): T {
return this.items[key]
}
len(): number {
return Object.keys(this.items).length
}
forEach(f: IntfKeyVal) {
for (let k in this.items) {
if (this.items.hasOwnProperty(k)) {
f(k, this.items[k])
}
}
}
}