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 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, any, any>): 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 Inherited TypedArrayBuilder<UintArray> Like TypedArray.at,
ensureCapacity(newCapacity: number): number Inherited TypedArrayBuilder<UintArray> Ensure that capacity is at least equal to newCapacity.
toTypedArray(includeUnusedCapacity: booleanfalse): UintArray Inherited 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 Inherited Constructor<UintArray> TypedArrayBuilder<UintArray> The constructor for the specific type of array being populated.
_data Protected Inherited UintArray TypedArrayBuilder<UintArray> The underlying typed array, to be reallocated and copied when its capacity is exceeded.
_length Protected Inherited number TypedArrayBuilder<UintArray> The number of elements added to the array so far.
capacity Accessor Inherited ReadOnly number TypedArrayBuilder<UintArray> The number of elements that can fit into the memory currently allocated for the array.
growthFactor Readonly Inherited number TypedArrayBuilder<UintArray> Multiplier applied to required capacity by ensureCapacity.
length Accessor Inherited ReadOnly number TypedArrayBuilder<UintArray> The number of elements currently in the array.

Defined in

Last Updated: 14 November, 2024