/** @packageDocumentation
 * @module Tiles
 */
import { ReadonlySortedArray, SortedArray } from "@itwin/core-bentley";
import { RenderMemory } from "../render/RenderMemory";
import { Tile } from "./internal";
/** Maintains in sorted order a set of [[TileUser]] Ids for which a given tile has been selected for display. The number of users in a set is expected to be very small - often only 1 for a typical application.
 * Strictly for use by LRUTileList.
 * @see TileUserIdSets.
 * @internal
 */
export declare class TileUserIdSet extends ReadonlySortedArray<number> {
    constructor(userId?: number);
    equals(set: TileUserIdSet): boolean;
    add(userId: number): void;
    drop(userId: number): void;
    clear(): void;
    copyFrom(src: TileUserIdSet): void;
    clone(): TileUserIdSet;
}
/** Maintains a set of TileUserIdSets such that each set represents a unique combination of TileUser ids and each set contains at least one TileUser id.
 * Exported strictly for tests.
 * @see LRUTileList.
 * @internal
 */
export declare class TileUserIdSets extends SortedArray<TileUserIdSet> {
    private readonly _scratch;
    constructor();
    /** Remove the specified TileUser Id from all sets and remove empty and duplicate sets. */
    drop(userId: number): void;
    /** Obtain a TileUserIdSet owned by this object containing userId and (if specified) userIds. */
    plus(userId: number, userIds?: TileUserIdSet): TileUserIdSet;
    /** Obtain a TileUserIdSet owned by this object containing all of userIds (if specified) but not userId. Returns undefined if the resultant set would be empty. */
    minus(userId: number, userIds?: TileUserIdSet): TileUserIdSet | undefined;
    private scratch;
    private getEquivalent;
}
/** A node in an LRUTileList. It is either a [[Tile]], or a sentinel node used to partition the list.
 * Strictly for use by LRUTileList.
 * @internal
 */
export interface LRUTileListNode {
    previous?: LRUTileListNode;
    next?: LRUTileListNode;
    /** The number of bytes of GPU memory allocated to the tile's content. The only node in a LRUTileListNode with `bytesUsed` less than 1 is the sentinel node. */
    bytesUsed: number;
    /** For a tile, the Ids of all of the TileUsers for which the tile is currently in use. The TileUserIdSet is owned by the LRUTileList's TileUserIdSets member.
     * Undefined if the tile is not in use by any TileUser.
     */
    tileUserIds?: TileUserIdSet | undefined;
}
/** An intrusive doubly-linked list of LRUTileListNodes, containing Tiles partitioned by a singleton sentinel node into two partitions and ordered from least-recently- to most-recently-used by any TileUser.
 * Used by TileAdmin to keep track of and impose limits upon the total amount of GPU memory allocated to tile content.
 *
 * Illustration of the structure of the list:
 *
 * ```
 * v------------- Not selected --------------v                                v----------------- Selected ------------------v
 *   ______               ______                           __________                           ______               ______
 *  | head |.next =>     |      |.next => ...             | sentinel |.next => ...             |      |.next =>     | tail |
 *  | 12kb |             |  8kb |                         |   0kb    |                         | 19kb |             | 23kb |
 *  |______| <= previous.|______|         ... <= previous.|__________|         ... <= previous.|______| <= previous.|______|
 *
 * least-recently-selected --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> most-recently-selected
 * ```
 *
 * The sentinel node is always present and floats freely as the contents of each partition change. Note that the `next` and `previous` pointers are stored directly on the tiles - no link nodes are allocated to hold the entries in the list. This of course means that a Tile can only ever belong to one LRUTileList - the one owned by the TileAdmin.
 *
 * The list contains only those tiles whose content has been loaded. Each node records the amount of GPU memory allocated for the tile's content. The list keeps track of the total amount of GPU memory allocated by all tiles. The list's contents are updated as follows:
 *
 * - When a tile's content is loaded, it is added to the end of the "not selected" partition. Its memory usage is computed and added to the list's total.
 * - When a tile's content is unloaded, it is removed from the list. Its memory usage is deducted from the list's totla.
 * - Just before a TileUser selects tiles for use (e.g., Viewport selects tiles for display), it is removed from each tile's set of viewports in which they are selected. If a tile's set of users becomes empty as a result, it is moved to the end of the "not selected" partition.
 * - When a tile becomes selected for use by a TileUser, the user is added to its user set and the tile is moved to the end of the "selected" partition.
 *
 * When the system determines that GPU memory should be freed up, it can simply pop nodes off the beginning of the "not selected" partition, freeing their content, until the target memory usage is reached or no more non-selected nodes exist.
 *
 * Strictly for use by [[TileAdmin]].
 * @internal
 */
export declare class LRUTileList {
    protected readonly _sentinel: LRUTileListNode;
    protected readonly _stats: RenderMemory.Statistics;
    protected readonly _userIdSets: TileUserIdSets;
    protected _head: LRUTileListNode;
    protected _tail: LRUTileListNode;
    protected _totalBytesUsed: number;
    /** The amount of GPU memory, in bytes, allocated to all tiles in the list. */
    get totalBytesUsed(): number;
    constructor();
    dispose(): void;
    /** Compute the amount of GPU memory allocated to the tile's content and, if greater than zero, add the tile to the beginning of the "selected" partition.
     * Invoked by TileAdmin whenever a tile's content is set to a valid RenderGraphic.
     */
    add(tile: Tile): void;
    /** Remove the tile from the list and deduct its previously-used GPU memory from the list's running total.
     * Invoked by TileAdmin when a tile's content is unloaded, including when the list itself disposes of the content in its `freeMemory` method.
     */
    drop(tile: Tile): void;
    /** Mark the tiles as in use by the specified TileUser. They are moved to the end of the "selected" partition. */
    markUsed(userId: number, tiles: Iterable<Tile>): void;
    /** Mark the tiles as no longer in user by the specified TileUser.
     * If this results in a tile being no longer selected for any user, it is moved to the end of the "not selected" partition.
     */
    clearUsed(userId: number): void;
    /** Dispose of the contents of tiles currently not selected for display until the total amount of memory consumed is no more than `maxBytes`
     * or until the contents of all un-selected tiles have been disposed.
     */
    freeMemory(maxBytes: number): void;
    /** Iterate over all of the tiles in the unselected partition. */
    get unselectedTiles(): Iterable<Tile>;
    /** Iterate over all of the tiles in the selected partition. */
    get selectedTiles(): Iterable<Tile>;
    protected computeBytesUsed(tile: Tile): number;
    protected assertList(): void;
    protected append(tile: Tile): void;
    protected unlink(tile: Tile): void;
    protected moveToEnd(tile: Tile): void;
    protected moveBeforeSentinel(tile: Tile): void;
    protected moveAfterSentinel(tile: Tile): void;
}
//# sourceMappingURL=LRUTileList.d.ts.map