/** * @class LazyFactoryMap * * The LazyFactoryMap object holds key-value pairs in the structure similar to the * regular Map. Once created, items can be moved around a grid depending on the operations * performed on that grid - adding or removing rows. The collection requires "key" * to be a zero-based index. * * It's essential to notice that the "key" index under which the item was created * is volatile. After altering the grid, the "key" index can change. */ export default class LazyFactoryMap> { /** * The data factory function. * * @type {Function} */ valueFactory: (key: number) => V; /** * An array which contains data. * * @type {Array} */ data: (V | undefined)[]; /** * An array of indexes where the key of the array is mapped to the value which points to the * specific position of the data array. * * @type {number[]} */ index: number[]; /** * The collection of indexes that points to the data items which can be replaced by obtaining new * ones. The "holes" are an intended effect of deleting entries. * * @type {Set} */ holes: Set; /** * Initializes the map with the given factory function used to create values for new keys on first access. */ constructor(valueFactory: (key: number) => V); /** * Gets or if data not exist creates and returns new data. * * @param {number} key The item key as zero-based index. * @returns {*} */ obtain(key: number): V; /** * Inserts an empty data to the map. This method creates an empty space for obtaining * new data. * * @param {number} key The key as volatile zero-based index at which to begin inserting space for new data. * @param {number} [amount=1] Amount of data to insert. */ insert(key: number | null | undefined, amount?: number): void; /** * Removes (soft remove) data from "index" and according to the amount of data. * * @param {number} key The key as volatile zero-based index at which to begin removing the data. * @param {number} [amount=1] Amount data to remove. */ remove(key: number | null | undefined, amount?: number): void; /** * Returns the size of the data which this map holds. * * @returns {number} */ size(): number; /** * Returns a new Iterator object that contains the values for each item in the LazyMap object. * * @returns {Iterator} */ values(): IterableIterator; /** * Returns a new Iterator object that contains an array of `[index, value]` for each item in the LazyMap object. * * @returns {Iterator} */ entries(): Iterator<[number, V], any, any> & { [Symbol.iterator](): Iterator<[number, V], any, any> & /*elided*/ any; }; /** * Clears the map. */ clear(): void; /** * Gets storage index calculated from the key associated with the specified value. * * @param {number} key Volatile zero-based index. * @returns {number} Returns index 0-N or -1 if no storage index found. */ _getStorageIndexByKey(key: number): number; /** * Gets the key associated with the specified value calculated from storage index. * * @param {number} dataIndex Zero-based storage index. * @returns {number} Returns index 0-N or -1 if no key found. */ _getKeyByStorageIndex(dataIndex: number): number; /** * Makes this object iterable. * * @returns {Iterator} */ [Symbol.iterator](): Iterator<[number, V], any, any> & { [Symbol.iterator](): Iterator<[number, V], any, any> & /*elided*/ any; }; }