simple-bimap
Version:
<div align="center"> <h1>🗺️↔️ simple-bimap</h1> <a href="https://www.npmjs.com/package/simple-bimap"> <img src="https://img.shields.io/npm/v/simple-bimap" alt="simple-bimap on npm"> </a> <a href="https://github.com/aleksander-ciesielski/
1 lines • 1.02 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Bimap=void 0;class Bimap{[Symbol.toStringTag]="Bimap";keyMap=new Map;valueMap=new Map;get size(){return this.keyMap.size}constructor(a){if(a)for(const[b,c]of a)this.set(b,c)}get(a){return this.keyMap.get(a)}getByValue(a){return this.valueMap.get(a)}set(a,b){return this.delete(a),this.deleteByValue(b),this.keyMap.set(a,b),this.valueMap.set(b,a),this}has(a){return this.keyMap.has(a)}hasValue(a){return this.valueMap.has(a)}entries(){return this.keyMap.entries()}keys(){return this.keyMap.keys()}values(){return this.keyMap.values()}[Symbol.iterator](){return this.keyMap[Symbol.iterator]()}clear(){this.keyMap.clear(),this.valueMap.clear()}delete(a){const b=this.get(a);return void 0!==b&&(this.keyMap.delete(a),this.valueMap.delete(b),!0)}deleteByValue(a){const b=this.getByValue(a);return void 0!==b&&(this.keyMap.delete(b),this.valueMap.delete(a),!0)}forEach(a,b){const c=a.bind(b);for(const[d,e]of this)c(e,d,this)}}exports.Bimap=Bimap;