require.mx('mxjs/base/utilities/wrapped_typed_array.js')
Wrap TypedArray objects to provide functions that rely on dynamic sizing (push, pop, etc.).
Status | Name |
---|
A
WrappedTypedArray
object wraps a native
TypedArray
object and provides convenience functions for dynamically changing the length of the internal
TypedArray
. Because Javascript typed arrays have a fixed length, this is simulated by storing a separate 'used length' variable and only considering elements up to the 'used length'. When the 'used length' exceeds the real length of the internal typed array, a larger internal typed array is constructed and the values from the old internal typed array are copied into the new one.
Note that
WrappedTypedArray
is a placeholder for one of the following names, all of which provide the same interface described here, but use a different native
TypedArray
internally:
TypedArray
(or
Array
), so some elemental operations such as iteration or square-bracket access (i.e. array[0]) are not possible with the
WrappedTypedArray
object itself. For these purposes, you can access the internal
TypedArray
using the
internal
property, but
you must be careful not to iterate past the length defined in the parent WrappedTypedArray
.
const wta = new LibWTA.WrappedFloat32Array(...);
for (let i = 0; i < wta.length; ++i) {
print(wta.internal[i]);
}
const wta = new LibWTA.WrappedFloat32Array(...);
for (let i = 0; i < wta.internal.length; ++i) {
print(wta.internal[i]);
}
const wta = new LibWTA.WrappedFloat32Array(...);
for (let i in wta.internal) {
print(wta.internal[i]);
}
Status | Name |
---|---|
Member |
TypedArray TypedArray
the underlying type of |
Member |
Number length
sets or returns the number of elements in this array (equivalent to Array.length). |
Member |
property
{TypedArray} internal gets the internal (fixed-length) |
Boolean every
(
Function callback,
Object thisArg
)
Equivalent to Array.prototype.every(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every |
|
Number get
(
Number index
)
Get the value of the element at the given index. |
|
Number indexOf
(
Number searchElement,
Number (optional)
)
Equivalent to TypedArray.prototype.indexOf(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/indexOf |
|
String join
(
String separator
)
Equivalent to Array.prototype.join(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join |
|
Number pop
(
)
Equivalent to Array.prototype.pop(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop |
|
push
(
Number value
)
Equivalent to Array.prototype.push(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push |
|
push_array
(
Array array
)
Push all values in the given array onto the end of this array. This is a convenience function, equivalent to calling
|
|
reserve
(
Number length
)
Ensure that the underlying TypedArray has enough room for
|
|
reverse
(
)
Equivalent to Array.prototype.reverse(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse |
|
set
(
Number index,
Number value
)
Sets the value of the element at the given index to the supplied value. |
|
WrappedTypedArray slice
(
Number begin,
Number end
)
Equivalent to Array.prototype.slice(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice |
|
SmallSubarray smallsubarray
(
Number begin,
Number end
)
Creates a "view" of a section of this array, starting from the index
|
|
Boolean some
(
Function callback,
Object thisArg
)
Equivalent to Array.prototype.some(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some |
|
toTypedArray
(
)
|
Equivalent to Array.prototype.join(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
Parameters:String
separator String
result Equivalent to Array.prototype.pop(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop
Parameters:Number
popped Equivalent to Array.prototype.push(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push
Parameters:Number
value Push all values in the given array onto the end of this array. This is a convenience function, equivalent to calling
push()
independently for each element in the passed array, but simpler and more performant.
Array
array Ensure that the underlying TypedArray has enough room for
length
elements. If you know that you're going to be adding a lot of elements to a
WrappedTypedArray
, it may improve performance to reserve the space up-front (as when writing to output tables).
Number
length - attempt to reserve space for length
elementsEquivalent to Array.prototype.reverse(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse
Parameters:Equivalent to Array.prototype.slice(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
Parameters: Returns:WrappedTypedArray
slice Creates a "view" of a section of this array, starting from the index
begin
and continuing while the index is less than
end
. This is similar to
TypedArray.prototype.subarray()
: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
Note that the existing builtin
TypedArray.prototype.subarray()
method has poor performance, so this uses a workaround object that has better performance, but does not have all of the methods that would be present on a real subarray. Furthermore, because of the nature of the workaround object, it should only be used for small subarrays (e.g. to use for a 3-length subarray defining an XYZ point).
SmallSubarray
subarray Parameters: