import { Event } from "eventery"; /** * A class wrapping an array of entities of a specific type, providing * performance-optimized methods for adding, looking up and removing entities, and events * for when entities are added or removed. */ export declare class Bucket implements Iterable { protected _entities: E[]; protected _version: number; /** * The current version of the bucket. Increases every time an entity is * added or removed. */ get version(): number; /** * An array of all entities within the bucket. Please note that for iterating * over the entities in this bucket, it is recommended that you use the * `for (const entity of bucket)` iterator form. */ get entities(): E[]; [Symbol.iterator](): { next: () => { value: E; done: boolean; }; }; constructor(_entities?: E[]); /** * Fired when an entity has been added to the bucket. */ onEntityAdded: Event<[entity: E]>; /** * Fired when an entity is about to be removed from the bucket. */ onEntityRemoved: Event<[entity: E]>; /** * A map of entity positions, used for fast lookups. */ private entityPositions; /** * Returns the total size of the bucket, i.e. the number of entities it contains. */ get size(): number; /** * Returns the first entity in the bucket, or `undefined` if the bucket is empty. */ get first(): E | undefined; /** * Returns true if the bucket contains the given entity. * * @param entity The entity to check for. * @returns `true` if the specificed entity is in this bucket, `false` otherwise. */ has(entity: any): entity is E; /** * Adds the given entity to the bucket. If the entity is already in the bucket, it is * not added again. * * @param entity The entity to add to the bucket. * @returns The entity passed into this function (regardless of whether it was added or not). */ add(entity: D): D & E; /** * Removes the given entity from the bucket. If the entity is not in the bucket, nothing * happens. * * @param entity The entity to remove from the bucket. * @returns The entity passed into this function (regardless of whether it was removed or not). */ remove(entity: E): E; /** * Removes all entities from the bucket. Will cause the `onEntityRemoved` event to be * fired for each entity. */ clear(): void; }