@technobuddha/library
Version: 
A large library of useful functions
93 lines (92 loc) • 3.18 kB
TypeScript
import { type Cartesian } from './geometry.ts';
/**
 * Represents a map with keys of cartesian coordinates, optimized for efficient storage and lookup.
 *
 * `CartesianMap` provides map-like operations (get, set, has, etc)
 * for objects with `{ x, y }` properties, where `x` and `y` are numbers.
 *
 * Internally, values are stored in a nested `Map<number, Set<number>>` structure,
 * allowing for fast addition, deletion, and membership checks.
 *
 * Supports all standard map operations, as well as iteration and forEach.
 *
 * @group Geometry
 * @category Coordinates
 */
export declare class CartesianMap<V> implements Map<Cartesian, V> {
    private readonly xaxis;
    /**
     * Creates a new `CartesianSet` optionally initialized with an array of cartesian.
     *
     * @param cartesian - Optional array of cartesian to initialize the set.
     */
    constructor(cartesian?: [Cartesian, V][] | null);
    /**
     * Gets the number of unique cartesian in the set.
     */
    get size(): number;
    readonly [Symbol.toStringTag] = "CartesianMap";
    /**
     * Removes all cartesian from the set.
     */
    clear(): void;
    /**
     * Removes a coordinate from the map.
     *
     * @param value - The coordinate to remove.
     * @returns `true` if the coordinate was present and removed, `false` otherwise.
     */
    delete(value: Cartesian): boolean;
    /**
     * Returns an iterator over `[coordinate, value]` pairs for each coordinate in the map.
     *
     * @returns An iterator of `[Cartesian, *V*]` pairs.
     */
    entries(): MapIterator<[Cartesian, V]>;
    /**
     * Executes a provided function once for each coordinate in the set.
     *
     * @param callback - Function to execute for each coordinate.
     * @param thisArg - Value to use as `this` when executing `callback`.
     */
    forEach(callback: (value: V, key: Cartesian, map: CartesianMap<V>) => void, thisArg?: unknown): void;
    /**
     * Retrieves the value associated with the given Cartesian key.
     *
     * @param key - The Cartesian coordinate used to locate the value.
     * @returns The value of type `V` if found; otherwise, `undefined`.
     */
    get(key: Cartesian): V | undefined;
    /**
     * Returns an iterator over the cartesian in the set.
     *
     * @returns An iterator of `Cartesian`.
     */
    keys(): SetIterator<Cartesian>;
    /**
     * Checks if a coordinate is present in the set.
     *
     * @param coordinate - The coordinate to check.
     * @returns `true` if the coordinate exists in the set, `false` otherwise.
     */
    has({ x, y }: Cartesian): boolean;
    /**
     * Add or update a value in the map.
     *
     * @param value - A single coordinate or an array of cartesian to add.
     * @returns The set itself, for chaining.
     */
    set(key: Cartesian, value: V): this;
    /**
     * Returns an iterator over the cartesian in the set.
     *
     * @returns An iterator of `Cartesian`.
     */
    values(): MapIterator<V>;
    /**
     * Returns an iterator over the cartesian in the set.
     *
     * @returns An iterator of `Cartesian`.
     */
    [Symbol.iterator](): MapIterator<[Cartesian, V]>;
}