fileoverview /**
  * A typed data container that is persistable, high-performance, and can be used
  * as a backing store for collaborative property sets.
 */ class BaseDataArray { protected _buffer : any ; private readonly bufferConstructor ; protected size : number ; constructor ( size ) ; param bufferConstructor param size constructor ( bufferConstructor , size ) ; constructor ( a , b ? ) { if ( typeof a === "number" ) { this . size = a ; this . bufferConstructor = this . getBufferCtor ( ) ; } else { this . bufferConstructor = a ; this . size = b ; } this . _buffer = new this . bufferConstructor ( this . size ) ; } param in_idx returns getValue ( in_idx = 0 ) { if ( in_idx >= this . size || in_idx < 0 ) { throw new Error ( "Trying to access out of bounds!" ) ; } return this . _buffer [ in_idx ] ; } param in_idxStart param in_idxEnd returns getValueRange ( in_idxStart , in_idxEnd ) { if ( in_idxStart >= this . size || in_idxEnd > this . size || in_idxStart < 0 || in_idxEnd < 0 ) { throw new Error ( "Trying to access out of bounds!" ) ; } return this . _buffer . subarray ( in_idxStart , in_idxEnd ) ; } returns serialize ( ) { return Array . from ( this . _buffer . subarray ( 0 , this . size ) ) ; } param in_serialized deserialize ( in_serialized ) { const values = in_serialized ; const length = in_serialized . length ; if ( length !== this . size ) { this . resize ( length ) ; this . size = length ; } let i ; for ( i = 0 ; i < length ; i ++ ) { this . _buffer [ i ] = values [ i ] ; } } param in_idx param in_value setValue ( in_idx , in_value ) { if ( in_idx < this . _buffer . length ) { this . _buffer [ in_idx ] = in_value ; } else { console . error ( "DataArray setValue in_idx is out of bounds." ) ; } } param in_arr param in_offset param in_deleteCount returns private _removeElementsFromArray ( in_arr , in_offset , in_deleteCount ) { const newSize = this . size - in_deleteCount ; const splicedArray = new in_arr . constructor ( newSize ) ; splicedArray . set ( in_arr . subarray ( 0 , in_offset ) ) ; splicedArray . set ( in_arr . subarray ( in_offset + in_deleteCount , this . size ) , in_offset ) ; return splicedArray ; } param in_offset param in_deleteCount removeRange ( in_offset , in_deleteCount ) { if ( in_offset + in_deleteCount < ( this . _buffer . length as number ) + 1 ) { this . _buffer = this . _removeElementsFromArray ( this . _buffer , in_offset , in_deleteCount ) ; this . size = this . size - in_deleteCount ; } else { console . error ( "DataArray removeRange in_offset + in_deleteCount is out of bounds." ) ; } } param in_arr param in_offset param in_addedArray returns private _insert ( in_arr , in_offset , in_addedArray ) { const newSize = this . size + ( in_addedArray . length as number ) ; const insertedArray = new in_arr . constructor ( newSize ) ; insertedArray . set ( in_arr . subarray ( 0 , in_offset ) ) ; insertedArray . set ( in_addedArray , in_offset ) ; insertedArray . set ( in_arr . subarray ( in_offset , this . size ) , in_offset + ( in_addedArray . length as number ) ) ; return insertedArray ; } param in_offset param in_array insertRange ( in_offset , in_array ) { this . _buffer = this . _insert ( this . _buffer , in_offset , in_array ) ; this . size = this . size + ( in_array . length as number ) ; } param in_offset param in_array set ( in_offset , in_array ) { if ( in_array instanceof ArrayBuffer || in_array instanceof Array || in_array instanceof this . getBufferCtor ( ) ) { this . _buffer . set ( in_array , in_offset ) ; } else if ( in_array instanceof BaseDataArray ) { this . _buffer . set ( in_array . getBuffer ( ) , in_offset ) ; } else { console . error ( "DataArray set() must be called with Array, TypedArray or DataArray" ) ; } } param in_value push ( in_value ) { const bufferLength = this . _buffer . length ; if ( this . size > bufferLength - 1 ) { this . _alloc ( this . size * 2 || 1 ) ; } this . setValue ( this . size , in_value ) ; this . size ++ ; } returns getBuffer ( ) { return this . _buffer ; } returns getBufferCtor ( ) { return this . bufferConstructor ; } param in_fn iterate ( in_fn ) { const l = this . size ; for ( let i = 0 ; i < l ; i ++ ) { in_fn ( this . _buffer [ i ] ) ; } } param in_bufferCtor param in_buffer param in_newSize returns private resizeBuffer ( in_bufferCtor , in_buffer , in_newSize ) { const newBuffer = new in_bufferCtor ( in_newSize ) ; const oldSize = in_buffer . length ; const oldBuffer = in_buffer ; const isShrinking = oldSize > in_newSize ; newBuffer . set ( isShrinking ? oldBuffer . subarray ( 0 , in_newSize ) : oldBuffer ) ; return newBuffer ; } param size returns protected _alloc ( size ) { this . _buffer = this . resizeBuffer ( this . bufferConstructor , this . _buffer , size ) ; return this ; } param size returns resize ( size ) { this . _alloc ( size ) ; this . size = size ; return this ; } copy ( ) { const newBuffer = new this . bufferConstructor ( this . size ) ; newBuffer . set ( this . _buffer ) ; return newBuffer ; } get length ( ) { return this . size ; } } class Int8DataArray extends BaseDataArray { constructor ( size ) { super ( Int8Array , size ) ; } } class Int16DataArray extends BaseDataArray { constructor ( size ) { super ( Int16Array , size ) ; } } class Int32DataArray extends BaseDataArray { constructor ( size ) { super ( Int32Array , size ) ; } } class Uint8DataArray extends BaseDataArray { constructor ( size ) { super ( Uint8Array , size ) ; } } class Uint16DataArray extends BaseDataArray { constructor ( size ) { super ( Uint16Array , size ) ; } } class Uint32DataArray extends BaseDataArray { constructor ( size ) { super ( Uint32Array , size ) ; } } class Float32DataArray extends BaseDataArray { constructor ( size ) { super ( Float32Array , size ) ; } } class Float64DataArray extends BaseDataArray { constructor ( size ) { super ( Float64Array , size ) ; } } param size class UniversalDataArray extends BaseDataArray { constructor ( bufferConstructor , size ) ; constructor ( size ) ; constructor ( a ? , b ? ) { if ( b === undefined ) { super ( Array , a ) ; } else { super ( a , b ) ; } } param array param values param offset private arraySet ( array , values , offset = 0 ) { let index = 0 ; values . forEach ( function ( value ) { array [ index + offset ] = value ; index ++ ; } ) ; } param in_offset param in_array insertRange ( in_offset , in_array ) { this . _buffer . splice . call ( this . _buffer , ... [ in_offset , 0 ] . concat ( in_array ) ) ; this . size = this . size + in_array . length ; } param in_offset param in_deleteCount removeRange ( in_offset , in_deleteCount ) { if ( in_offset + in_deleteCount < ( this . _buffer . length as number ) + 1 ) { this . _buffer . splice ( in_offset , in_deleteCount ) ; this . size -= in_deleteCount ; } else { throw Error ( "DataArray removeRange in_offset + in_deleteCount is out of bounds." ) ; } } param in_offset param in_array set ( in_offset , in_array ) { if ( in_array instanceof ArrayBuffer || in_array instanceof Array || in_array instanceof this . getBufferCtor ( ) ) { this . arraySet ( this . _buffer , in_array , in_offset ) ; } else if ( in_array instanceof BaseDataArray ) { this . arraySet ( this . _buffer , in_array . getBuffer ( ) , in_offset ) ; } else { console . error ( "DataArray set() must be called with Array, TypedArray or DataArray" ) ; } } param in_idxStart param in_idxEnd returns getValueRange ( in_idxStart , in_idxEnd ) { if ( in_idxStart >= this . size || in_idxEnd > this . size || in_idxStart < 0 || in_idxEnd < 0 ) { throw new Error ( "Trying to access out of bounds!" ) ; } return this . _buffer . slice ( in_idxStart , in_idxEnd ) ; } param in_buffer param in_newSize returns private resizeBufferArray ( in_buffer , in_newSize ) { const newBuffer = new Array ( in_newSize ) ; const oldSize = in_buffer . length ; const oldBuffer = in_buffer ; const isShrinking = oldSize > in_newSize ; this . arraySet ( newBuffer , isShrinking ? oldBuffer . slice ( 0 , in_newSize ) : oldBuffer ) ; return newBuffer ; } param size returns protected _alloc ( size ) { this . _buffer = this . resizeBufferArray ( this . _buffer , size ) ; return this ; } } /**
 * A data container that contains a string
 */ class StringDataArray extends BaseDataArray { constructor ( ) { super ( String , 0 ) ; this . size = 0 ; this . _buffer = "" ; } param in_offset param in_string insertRange ( in_offset , in_string ) { this . _buffer = `${ this . _buffer . substr ( 0 , in_offset ) }${ in_string }${ this . _buffer . substr ( in_offset ) }` ; this . size = this . size + in_string . length ; } param in_offset param in_deleteCount removeRange ( in_offset , in_deleteCount ) { if ( in_offset + in_deleteCount < ( this . _buffer . length as number ) + 1 ) { this . _buffer = `${ this . _buffer . substr ( 0 , in_offset ) }${ this . _buffer . substr ( in_offset + in_deleteCount ) }` ; this . size -= in_deleteCount ; } else { throw Error ( "DataArray removeRange in_offset + in_deleteCount is out of bounds." ) ; } } param in_offset param in_string set ( in_offset , in_string ) { this . _buffer = `${ this . _buffer . substr ( 0 , in_offset ) }${ in_string }${ this . _buffer . substr ( in_offset + in_string . length ) }` ; } param in_idxStart param in_idxEnd returns getValueRange ( in_idxStart , in_idxEnd ) { if ( in_idxStart >= this . size || in_idxEnd > this . size || in_idxStart < 0 || in_idxEnd < 0 ) { throw new Error ( "Trying to access out of bounds!" ) ; } return this . _buffer . slice ( in_idxStart , in_idxEnd ) ; } get length ( ) { return this . _buffer . length ; } } /**
 * A data container that can contain boolean type
 */ class BoolDataArray extends UniversalDataArray { param size constructor ( size ) { super ( Array , size ) ; } param array param values param offset private arraySetBool ( array , values , offset = 0 ) { let index = 0 ; values . forEach ( function ( value ) { array [ index + offset ] = ! ! ( value as boolean ) ; index ++ ; } ) ; } param in_offset param in_array insertRange ( in_offset , in_array ) { const toBeAdded = in_array . map ( ( val ) => ! ! ( val as boolean ) ) ; this . _buffer . splice . call ( this . _buffer , ... ( [ in_offset , 0 ] . concat ( toBeAdded ) ) ) ; this . size = this . size + in_array . length ; } param in_offset param in_array set ( in_offset , in_array ) { if ( in_array instanceof ArrayBuffer || in_array instanceof Array || in_array instanceof this . getBufferCtor ( ) ) { this . arraySetBool ( this . _buffer , in_array , in_offset ) ; } else if ( in_array instanceof BaseDataArray ) { this . arraySetBool ( this . _buffer , in_array . getBuffer ( ) , in_offset ) ; } else { console . error ( "DataArray set() must be called with Array, TypedArray or DataArray" ) ; } } } export { BaseDataArray , Float32DataArray , Float64DataArray , Int8DataArray , Int16DataArray , Int32DataArray , Uint8DataArray , Uint16DataArray , Uint32DataArray , UniversalDataArray , StringDataArray , BoolDataArray , } ;