/** * Base class for OSM entity collections. * * Provides common ID and tag storage, streaming iteration, and sorted access. * Subclasses implement entity-specific storage and spatial indexing. * * @module */ import type { ContentHasher } from "@osmix/shared/content-hasher"; import type { GeoBbox2D, OsmEntity, OsmEntityType, OsmTags } from "@osmix/types"; import type { IdOrIndex, Ids, IdsTransferables } from "./ids.ts"; import type { Tags, TagsTransferables } from "./tags.ts"; import type { BufferType } from "./typed-arrays.ts"; /** * Serializable representation of an Entities collection for worker transfer. * Combines ID and tag transferables; subclasses add entity-specific data. */ export interface EntitiesTransferables extends IdsTransferables, TagsTransferables { } /** * Abstract base for typed entity collections. * * Lifecycle: * 1. **Ingest**: `addEntity()` (no lookups). * 2. **Finalize**: `buildIndex()`. * 3. **Query**: Lookups and iteration enabled. */ export declare abstract class Entities { /** The type of entity stored in this collection ("node", "way", or "relation"). */ indexType: OsmEntityType; /** ID storage and lookup */ ids: Ids; /** Tag storage and search */ tags: Tags; /** Whether buildIndex() has been called */ protected indexBuilt: boolean; /** * Create a new Entities collection. * @param indexType - The entity type ("node", "way", or "relation"). * @param ids - The ID storage instance. * @param tags - The tag storage instance. */ constructor(indexType: OsmEntityType, ids: Ids, tags: Tags); /** * Get transferable objects for passing to another thread. */ transferables(): EntitiesTransferables; /** * Check if the index is built and ready for use. */ isReady(): boolean; /** Number of entities in this collection. */ get size(): number; /** * Compact entity-specific typed arrays. * Called by `buildIndex()` after ID and tag indexes are built. * @abstract */ abstract buildEntityIndex(): void; /** * Finalize indexes. * Must be called after adding entities and before querying. */ buildIndex(): void; /** * Get the bounding box of an entity. * @param idOrIndex - Entity identifier (by ID or internal index). * @returns Geographic bounding box [minLon, minLat, maxLon, maxLat]. * @abstract */ abstract getEntityBbox(idOrIndex: IdOrIndex): GeoBbox2D; /** * Reconstruct a full entity object from index data. * @param index - Internal array index. * @param id - OSM entity ID. * @param tags - Optional pre-fetched tags. * @returns The complete entity object. * @abstract */ abstract getFullEntity(index: number, id: number, tags?: OsmTags): T; /** * Add an entity to the index. Tags can be provided as an array of keys and values, or as an object. */ addEntity(id: number, tags: number[], values: number[]): number; addEntity(id: number, tags: OsmTags): number; /** * Get an entity by ID or index. */ get(idOrIndex: IdOrIndex): T | null; /** * Get an entity by index. */ getByIndex(index: number): T; /** * Get multiple entities by their indexes. */ getEntitiesByIndex(indexes: number[]): T[]; /** * Iterate over all entities in the index. */ [Symbol.iterator](): Generator; /** * Get an entity by ID. */ getById(id: number): T | null; /** * Iterate over entities sorted by ID. */ sorted(): Generator; /** * Search for entities with a specific tag key and optional value. */ search(key: string, val?: string): T[]; /** * Update a ContentHasher with this entity collection's base data (IDs and tags). * Subclasses should override to add entity-specific data. */ updateHash(hasher: ContentHasher): ContentHasher; } //# sourceMappingURL=entities.d.ts.map