UNPKG

s2-tools

Version:

A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.

69 lines 1.96 kB
import { S2FileStore } from '../file'; import { compare } from '../../dataStructures/uint64'; /** File based multimap store */ export class FileMultiMap { #store; /** * Builds a new MultiMap file store * @param fileName - the path + file name without the extension */ constructor(fileName) { this.#store = new S2FileStore(fileName); } /** @returns - the length of the map */ get length() { return this.#store.length; } /** * Adds a value to the list of values associated with a key * @param key - the key * @param value - the value to store */ set(key, value) { this.#store.set(key, value); } /** * Gets the list of values associated with a key * @param key - the key * @returns the list of values if the map contains values for the key */ async get(key) { return await this.#store.get(key); } /** * iterate through the values * @yields - The values in the store */ async *entries() { let entries = []; for await (const entry of this.#store.entries()) { if (entries.length > 0) { const curr = entries[0]; if (compare(curr.key, entry.key) === 0) { entries.push(entry); } else { yield { key: curr.key, value: entries.map((e) => e.value) }; entries = [entry]; } } else { entries.push(entry); } } if (entries.length > 0) yield { key: entries[0].key, value: entries.map((e) => e.value) }; } /** * iterate through the values * @returns - an iterator */ [Symbol.asyncIterator]() { return this.entries(); } /** Closes the store */ close() { this.#store.close(true); } } //# sourceMappingURL=file.js.map