/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Tiles
 */
import { OrderedSet } from "@itwin/core-bentley";
/** A set of [[TileTree]]s disclosed by a set of objects implementing [[TileTreeDiscloser]], used to collect references to tile trees in use by those objects.
 * @public
 * @extensions
 */
export class DisclosedTileTreeSet {
    /** Construct a new set.
     * @param comparator If supplied, a comparison function used to determine the order of iteration of the set; otherwise, iteration will proceed in insertion order.
     */
    constructor(comparator) {
        this._processed = new Set();
        this._trees = comparator ? new OrderedSet(comparator) : new Set();
    }
    /** Returns true if the specified tree has been [[add]]ed to the set. */
    has(tree) {
        return this._trees.has(tree);
    }
    /** Adds the specified tree to the set. */
    add(tree) {
        this._trees.add(tree);
    }
    /** Iterates all trees in the set.
     * @note Do not [[add]] to the set during iteration.
     */
    [Symbol.iterator]() {
        return this._trees[Symbol.iterator]();
    }
    /** The number of trees in the set. */
    get size() {
        return this._trees.size;
    }
    /** Add all tile trees referenced by `discloser` to the set. */
    disclose(discloser) {
        if (this._processed.has(discloser))
            return;
        this._processed.add(discloser);
        discloser.discloseTileTrees(this);
    }
    /** Clear the contents of this set. */
    clear() {
        this._processed.clear();
        this._trees.clear();
    }
}
//# sourceMappingURL=DisclosedTileTreeSet.js.map