import { Log } from '../log' ; /**
 * Class for associating IDs with objects.
 * Note:
 * Use of length is unreliable as the list may contain also undefined items.
 * This happens when entries are removed.
 */ export class RefList < type > extends Array < type > { param obj returns public addObject ( obj ) { if ( obj == undefined ) return 0 ; this . push ( obj ) ; const id = this . length ; return id ; } param ref returns public getObject ( ref ) { if ( ref <= 0 || ref > this . length ) { Log . log ( 'RefList Error: reference ' + ref + ' not found!' ) ; return undefined ; } const obj = this [ ref - 1 ] ; return obj ; } /**
     * Deletes an entry.
     * Does this by simply setting to undefined.
     * So at least the memory is freed, but still an entry in the list remains.
     */ returns public first ( ) { if ( this . length == 0 ) return undefined ; return this [ 0 ] ; } returns public last ( ) { if ( this . length == 0 ) return undefined ; return this [ this . length - 1 ] ; } /**
     * Removes all variables.
     */ public clear ( ) { this . length = 0 ; } }