@substrate/api-sidecar
Version:
REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.
42 lines • 1.31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultiKeyBiMap = void 0;
class MultiKeyBiMap {
constructor() {
this.keyToValue = new Map();
this.valueToKeys = new Map();
}
set(key, value) {
// Remove old value mapping if it exists
const oldValue = this.keyToValue.get(key);
if (oldValue !== undefined) {
const keys = this.valueToKeys.get(oldValue);
keys === null || keys === void 0 ? void 0 : keys.delete(key);
if (keys && keys.size === 0) {
this.valueToKeys.delete(oldValue);
}
}
this.keyToValue.set(key, value);
if (!this.valueToKeys.has(value)) {
this.valueToKeys.set(value, new Set());
}
this.valueToKeys.get(value).add(key);
}
getByKey(key) {
return this.keyToValue.get(key);
}
getByValue(value) {
return this.valueToKeys.get(value);
}
get(input) {
if (this.keyToValue.has(input)) {
return this.keyToValue.get(input);
}
if (this.valueToKeys.has(input)) {
return this.valueToKeys.get(input);
}
return undefined;
}
}
exports.MultiKeyBiMap = MultiKeyBiMap;
//# sourceMappingURL=MultiKeyBiMap.js.map