TypedArrayBuilder<T extends UintArray> Class

Incrementally builds a TypedArray of unsigned 8-, 16-, or 32-bit integers. Sometimes you wish to populate a TypedArray, but you don't know how many elements you will need. TypedArray requires you to specify the size upon construction, and does not permit you to change the size later.

TypedArrayBuilder manages a TypedArray, permitting you to TypedArrayBuilder.push and TypedArrayBuilder.append elements to it. It exposes two "size" properties":

Once you've finished adding elements, you can obtain the finished TypedArray via TypedArrayBuilder.toTypedArray.

@see - Uint8ArrayBuilder, Uint16ArrayBuilder, and Uint32ArrayBuilder to build specific types of arrays.

  • UintArrayBuilder when you don't know the maximum number of bytes required for each element in the array.

Extended by

Methods

Name Description
constructor<T extends UintArray>(constructor: Constructor<T>, options?: TypedArrayBuilderOptions): TypedArrayBuilder<T> Protected Constructs a new builder from the specified options, with a TypedArrayBuilder.length of zero.  
append(values: T): void Append an array of values, resizing (at most once) if necessary.  
at(index: number): number Like TypedArray.at,  
ensureCapacity(newCapacity: number): number Ensure that TypedArrayBuilder.capacity is at least equal to newCapacity.  
push(value: number): void Append the specified value, resizing if necessary.  
toTypedArray(includeUnusedCapacity: boolean = false): T Obtain the finished array.  

Properties

Name Type Description
_constructor Protected Constructor<T> The constructor for the specific type of array being populated.  
_data Protected T The underlying typed array, to be reallocated and copied when its capacity is exceeded.  
_length Protected number The number of elements added to the array so far.  
capacity Accessor ReadOnly number The number of elements that can fit into the memory currently allocated for the array.  
growthFactor Readonly number Multiplier applied to required capacity by TypedArrayBuilder.ensureCapacity.  
length Accessor ReadOnly number The number of elements currently in the array.  

Defined in

Last Updated: 15 March, 2024