@jbrowse/core
Version:
JBrowse 2 core libraries used by plugins
60 lines (59 loc) • 1.41 kB
JavaScript
export default class CompositeMap {
submaps;
constructor(submaps) {
this.submaps = submaps;
}
has(id) {
for (const submap of this.submaps.values()) {
if (submap.has(id)) {
return true;
}
}
return false;
}
get(id) {
for (const submap of this.submaps.values()) {
if (submap.has(id)) {
return submap.get(id);
}
}
return undefined;
}
*values() {
for (const key of this.keys()) {
yield this.get(key);
}
}
*keys() {
const keys = new Set();
for (const submap of this.submaps.values()) {
for (const key of submap.keys()) {
keys.add(key);
}
}
for (const key of keys) {
yield key;
}
}
find(f) {
for (const submap of this.submaps.values()) {
for (const value of submap.values()) {
const found = f(value);
if (found) {
return value;
}
}
}
return undefined;
}
*[Symbol.iterator]() {
for (const key of this.keys()) {
yield [key, this.get(key)];
}
}
*entries() {
for (const k of this.keys()) {
yield [k, this.get(k)];
}
}
}