gis-tools-ts
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
87 lines • 2.59 kB
TypeScript
import type { S2CellId } from '../..';
import type { Properties, Value } from '../..';
/** A key-value entry in the multimap */
export interface MMEntry<V> {
key: S2CellId;
value: V[];
}
/** Represents a key-value store */
export interface MultiMapStore<V = Properties | Value> {
length: number;
get: ((key: number | S2CellId) => V[] | undefined) | ((key: number | S2CellId) => Promise<V[] | undefined>);
set: (key: number | S2CellId, value: V) => void;
has: (key: number | S2CellId) => boolean | Promise<boolean>;
entries: () => AsyncGenerator<MMEntry<V>>;
[Symbol.asyncIterator]: () => AsyncGenerator<MMEntry<V>>;
close: () => void;
}
/** A constructor for a vector store */
export type MultiMapStoreConstructor<V = Properties | Value> = new () => MultiMapStore<V>;
/**
* # MultiMap Store
*
* ## Description
* A local multimap store
*
* ## Usage
* ```ts
* import { MultiMap } from 'gis-tools-ts';
*
* interface Data { name: string };
*
* const mm = new MultiMap<Data>();
* // set a key
* mm.set(1n, { name: 'test' });
* mm.set(1n, { name: 'test2' });
* // get a key
* const { name } = mm.get(1n); // [{ name: 'test' }, { name: 'test2' }]
* // check if a key exists
* mm.has(1n); // true
* // get length of the store
* console.log(mm.length); // 2
*
* // iterate over the store
* for await (const entry of mm) console.log(entry);
*
* // close the store
* mm.close();
* ```
*/
export declare class MultiMap<V = Properties | Value> implements MultiMapStore<V> {
#private;
/** Builds a new MultiMap */
constructor();
/** @returns - the length of the map */
get length(): number;
/**
* Adds a value to the list of values associated with a key
* @param key - the key
* @param value - the value to store
*/
set(key: number | S2CellId, value: V): void;
/**
* Check if the key exists
* @param key - the key
* @returns true if the key exists
*/
has(key: number | S2CellId): boolean;
/**
* 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
*/
get(key: number | S2CellId): V[] | undefined;
/**
* iterate through the values
* @yields - The values in the store
*/
entries(): AsyncGenerator<MMEntry<V>>;
/**
* iterate through the values
* @returns - an iterator
*/
[Symbol.asyncIterator](): AsyncGenerator<MMEntry<V>>;
/** Closes the store */
close(): void;
}
//# sourceMappingURL=index.d.ts.map