voided-data
Version:
Proper DS for TS
36 lines (35 loc) • 1.15 kB
TypeScript
import { Hashable } from '../../objects/hash';
import { Equalable } from '../../objects/equals';
/**
* A Set:
* Is a lookup structure to determine if an entry already exists or not.
*
* @startuml
* title VNSet
* interface VNSet<Key> {
* size(): Int
* has(key: Key): Boolean,
* add(key: Key): Unit
* remove(key: Key): Unit
* map<T>(m: (k: Key) => T): VNSet<T>
* intersect(other: VNSet<Key>): VNSet<Key>
* union(other: VNSet<Key>): VNSet<Key>
* disjunction(other: VNSet<Key>): VNSet<Key>
* }
* @enduml
*/
interface VNSet<Key extends Hashable & Equalable> {
size(): number;
has(key: Key): boolean;
add(key: Key): void;
remove(key: Key): void;
map<T extends Hashable & Equalable>(mapper: (key: Key) => T): VNSet<T>;
iter(): Key[];
union(other: VNSet<Key>): VNSet<Key>;
intersection(other: VNSet<Key>): VNSet<Key>;
disjunction(other: VNSet<Key>): VNSet<Key>;
difference(other: VNSet<Key>): VNSet<Key>;
equals(other: VNSet<Key>): boolean;
}
export declare function createHashSet<Key extends Equalable & Hashable>(): VNSet<Key>;
export {};