UintArrayBuilder Class

A TypedArrayBuilder that can populate a UintArray with the minimum bytes per element required.

By default, the underlying array is a Uint8Array, though this can be configured via UintArrayBuilderOptions.initialType. As values are added to the array, if the bytes per element supported by the underlying array is too small to hold one of the new values, the array is reallocated to a type large enough to hold all of the new values. For example, the following produces a Uint8Array because all values are less than 256:

 const builder = new UintArrayBuilder();
 builder.append([1, 2, 254, 255]);
 const array = builder.toTypedArray();
 assert(array instanceof Uint8Array);

However, the following produces a Uint16Array because one of the values is larger than 255 but none are larger than 65,535:

 const builder = new UintArrayBuilder();
 builder.append([1, 255, 257, 65535]);
 const array = builder.toTypedArray();
 assert(array instanceof Uint16Array);

@see Uint8ArrayBuilder, Uint16ArrayBuilder, or Uint32ArrayBuilder if you know the number of bytes you want to allocate for each element in the array.

Extends

Methods

Name Description
constructor(options?: UintArrayBuilderOptions): UintArrayBuilder    
append(values: UintArray): void See TypedArrayBuilder.append.  
ensureBytesPerElement(newValues: Iterable<number>): void Protected Ensures that the underlying array is of a type that can contain the largest value in newValues.  
push(value: number): void See TypedArrayBuilder.push.  

Inherited methods

Name Inherited from Description
at(index: number): number TypedArrayBuilder<UintArray> Like TypedArray.at,
ensureCapacity(newCapacity: number): number TypedArrayBuilder<UintArray> Ensure that TypedArrayBuilder.capacity is at least equal to newCapacity.
toTypedArray(includeUnusedCapacity: boolean = false): UintArray TypedArrayBuilder<UintArray> Obtain the finished array.

Properties

Name Type Description
bytesPerElement Accessor ReadOnly number The number of bytes (1, 2, or 4) currently allocated per element by the underlying array.  

Inherited properties

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

Defined in

Last Updated: 28 March, 2024