voided-data
Version:
Proper DS for TS
34 lines (33 loc) • 1.15 kB
TypeScript
import { Maybe } from '../../monads/maybe';
import { Hashable } from '../../objects/hash';
import { Equalable } from '../../objects/equals';
/**
* A Map:
* Is a lookup table with constant access behavior.
* In the case of a HashMap or HashTable,
* this is achieved by storing the value key pairs in arrays as "buckets"
* using their hash values
* (a good hashing function will distribute the keys evenly)
*
*
* @startuml
* title VNMap
* interface VNMap<Key, Value> {
* size(): Int
* get(key: Key): Maybe<Value>
* set(key: Key, value: Value): Unit
* unset(key: Key): Unit
* toString(): string
* }
* @enduml
*/
export interface VNMap<Key extends Hashable & Equalable, Value> {
get(key: Key): Maybe<Value>;
set(key: Key, value: Value): void;
map<NewKey extends Hashable & Equalable, NewValue>(mapper: (pair: [Key, Value]) => [NewKey, NewValue]): VNMap<NewKey, NewValue>;
iter(): [Key, Value][];
unset(key: Key): void;
size(): number;
toString(): string;
}
export declare function createHashTable<Key extends Hashable & Equalable, Value>(): VNMap<Key, Value>;