export const enum Handle { none = 0 } /**
 * A handle table provides a fast mapping from an integer `handle` to a value `T`.
 */ export class HandleTable < T , THandle extends Handle = Handle > { public constructor ( private readonly handles = [ 1 ] ) { } public clear ( ) { this . handles . splice ( 0 , this . handles . length , 1 ) ; } /**
     * Allocate a slot in the handle table, set the slot to the given 'value', and
     * return the associated handle.
     *
     * Call 'delete()' when you are finished with the slot to recycle the handle.
     */ public add ( value ) { const free = this . next ; this . next = ( this . handles [ free ] as THandle ) ?? ( free + 1 ) ; this . handles [ free ] = value ; return free ; } /**
     * Returns the given handle to the free list.
     */ public delete ( handle ) { this . handles [ handle ] = this . next ; this . next = handle ; } /**
     * Get the value `T` associated with the given handle, if any.
     */ public get ( handle ) { return this . handles [ handle ] as T ; } /**
     * Set the value `T` associated with the given handle.
     */ public set ( handle , value ) { this . handles [ handle ] = value ; } private get next ( ) { return this . handles [ 0 ] as THandle ; } private set next ( handle ) { this . handles [ 0 ] = handle ; } public toJSON ( ) { return this . handles ; } }