@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
49 lines (43 loc) • 847 B
JavaScript
/**
* Bi-directional map
* @template K,V
*/
export class BiMap {
/**
*
* @type {Map<K, V>}
*/
forward = new Map();
/**
*
* @type {Map<V, K>}
*/
backward = new Map();
/**
*
* @param {K} key
* @param {V} value
*/
add(key, value) {
this.forward.set(value, key);
this.backward.set(key, value);
}
/**
*
* @param {V} value
* @returns {K|undefined}
*/
getKeyByValue(value) {
return this.backward.get(value);
}
/**
*
* @param {K} address
* @returns {V|undefined}
*/
getValueByKey(address) {
return this.forward.get(address);
}
}
BiMap.prototype.get = BiMap.prototype.getValueByKey;
BiMap.prototype.set = BiMap.prototype.add;