diff --git a/lib/node_modules/@stdlib/array/int64/README.md b/lib/node_modules/@stdlib/array/int64/README.md new file mode 100644 index 000000000000..46fb5217d05a --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/README.md @@ -0,0 +1,521 @@ + + +# Int64Array + +> 64-bit signed integer array. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Int64Array = require( '@stdlib/array/int64' ); +``` + +#### Int64Array() + +Creates a 64-bit signed integer array. + +```javascript +var arr = new Int64Array(); +// returns +``` + +#### Int64Array( length ) + +Creates a 64-bit signed integer array having a specified length. + +```javascript +var arr = new Int64Array( 5 ); +// returns [ 0n, 0n, 0n, 0n, 0n ] +``` + +#### Int64Array( typedarray ) + +Creates a 64-bit signed integer array from another [typed array][mdn-typed-array]. + +```javascript +var Uint32Array = require( '@stdlib/array/uint32' ); + +var arr1 = new Uint32Array( [ 5, 5, 5 ] ); +var arr2 = new Int64Array( arr1 ); +// returns [ 5n, 5n, 5n ] +``` + +#### Int64Array( obj ) + +Creates a 64-bit signed integer array from an array-like object or iterable. + +```javascript +var arr = new Int64Array( [ 5.0, -5.0, 5.0 ] ); +// returns [ 5n, -5n, 5n ] +``` + +#### Int64Array( buffer\[, byteOffset\[, length]] ) + +Returns a 64-bit signed integer array view of an [`ArrayBuffer`][@stdlib/array/buffer]. + +```javascript +var ArrayBuffer = require( '@stdlib/array/buffer' ); + +var buf = new ArrayBuffer( 32 ); +var arr = new Int64Array( buf, 0, 4 ); +// returns [ 0n, 0n, 0n, 0n ] +``` + +* * * + +### Properties + + + +#### Int64Array.BYTES_PER_ELEMENT + +Static property returning the size (in bytes) of each array element. + +```javascript +var nbytes = Int64Array.BYTES_PER_ELEMENT; +// returns 8 +``` + + + +#### Int64Array.name + +Static property returning the constructor name. + +```javascript +var str = Int64Array.name; +// returns 'Int64Array' +``` + + + +#### Int64Array.prototype.buffer + +**Read-only** property which returns the underlying [`ArrayBuffer`][@stdlib/array/buffer] referenced by array instance. + +```javascript +var arr = new Int64Array( 5 ); + +var buf = arr.buffer; +// returns +``` + + + +#### Int64Array.prototype.byteLength + +**Read-only** property which returns the length (in bytes) of the array instance. + +```javascript +var arr = new Int64Array( 5 ); + +var byteLength = arr.byteLength; +// returns 40 +``` + + + +#### Int64Array.prototype.byteOffset + +**Read-only** property which returns the offset (in bytes) of the array instance from the start of its underlying [`ArrayBuffer`][@stdlib/array/buffer]. + +```javascript +var arr = new Int64Array( 5 ); + +var byteOffset = arr.byteOffset; +// returns 0 +``` + + + +#### Int64Array.prototype.BYTES_PER_ELEMENT + +Size (in bytes) of each array element. + +```javascript +var arr = new Int64Array( 5 ); + +var nbytes = arr.BYTES_PER_ELEMENT; +// returns 8 +``` + + + +#### Int64Array.prototype.length + +**Read-only** property which returns the number of array elements. + +```javascript +var arr = new Int64Array( 5 ); + +var len = arr.length; +// returns 5 +``` + +* * * + +### Methods + + + +#### Int64Array.from( src\[, map\[, thisArg]] ) + +Creates a new 64-bit signed integer array from an array-like object or an iterable. + +```javascript +var arr = Int64Array.from( [ 1, -2 ] ); +// returns [ 1n, -2n ] +``` + +To invoke a function for each `src` value, provide a callback function. + +```javascript +function mapFcn( v ) { + return v * 2; +} + +var arr = Int64Array.from( [ -1, 2 ], mapFcn ); +// returns [ -2n, 4n ] +``` + +A callback function is provided two arguments: + +- **value**: source value. +- **index**: source index. + +To set the callback execution context, provide a `thisArg`. + +```javascript +function mapFcn( v ) { + this.count += 1; + return v * 2; +} + +var ctx = { + 'count': 0 +}; + +var arr = Int64Array.from( [ 1, -2 ], mapFcn, ctx ); +// returns [ 2n, -4n ] + +var n = ctx.count; +// returns 2 +``` + + + +#### Int64Array.of( element0\[, element1\[, ...elementN]] ) + +Creates a new 64-bit signed integer array from a variable number of arguments. + +```javascript +var arr = Int64Array.of( 1, 2 ); +// returns [ 1n, 2n ] +``` + + + +#### Int64Array.prototype.at( i ) + +Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer positions. + +```javascript +var arr = new Int64Array( 10 ); + +// Set the first, second, and last elements: +arr.set( 1, 0 ); +arr.set( 2, 1 ); +arr.set( 9, 9 ); + +// Get the first element: +var z = arr.at( 0 ); +// returns [ 1n ] + +// Get the last element: +z = arr.at( -1 ); +// returns [ 9n ] +``` + +If provided an out-of-bounds index, the method returns `undefined`. + +```javascript +var arr = new Int64Array( 10 ); + +var z = arr.at( 100 ); +// returns undefined + +z = arr.at( -100 ); +// returns undefined +``` + + + +#### Int64Array.prototype.entries() + +Returns an iterator for iterating over array key-value pairs. + +```javascript +var Int64 = require( '@stdlib/number/int64/ctor' ); + +var arr = [ + new Int64( 1 ), + new Int64( 2 ), + new Int64( 3 ) +]; +arr = new Int64Array( arr ); + +// Create an iterator: +var it = arr.entries(); + +// Iterate over the key-value pairs... +var v = it.next().value; +// returns [ 0, [ 1n ] ] + +v = it.next().value; +// returns [ 1, [ 2n ] ] + +v = it.next().value; +// returns [ 2, [ 3n ] ] + +var bool = it.next().done; +// returns true +``` + +The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: + +- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. +- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + + + +#### Int64Array.prototype.get( i ) + +Returns an array element located at position (index) `i`. + +```javascript +var arr = new Int64Array( 10 ); + +// Set the first element: +arr.set( 1, 0 ); + +// Get the first element: +var z = arr.get( 0 ); +// returns [ 1n ] +``` + +If provided an out-of-bounds index, the method returns `undefined`. + +```javascript +var arr = new Int64Array( 10 ); + +var z = arr.get( 100 ); +// returns undefined +``` + + + +#### Int64Array.prototype.set( value\[, i] ) + +Sets one or more array elements. + +```javascript +var Int64 = require( '@stdlib/number/int64/ctor' ); + +var arr = new Int64Array( [ 1, 2, 3 ] ); +// returns [ 1n, 2n, 3n ] + +// Get the first element: +var z = arr.get( 0 ); +// returns [ 1n ] + +// Set the first element: +arr.set( new Int64( 5 ) ); + +// Get the first element: +z = arr.get( 0 ); +// returns [ 5n ] +``` + +By default, the method sets array elements starting at position (index) `i = 0`. To set elements starting elsewhere in the array, provide an index argument `i`. + +```javascript +var Int64 = require( '@stdlib/number/int64/ctor' ); + +var arr = new Int64Array( [ 1, 2, 3 ] ); +// returns [ 1n, 2n, 3n ] + +// Get the third element: +var z = arr.get( 2 ); +// returns [ 3n ] + +// Set the third element: +arr.set( new Int64( 5 ), 2 ); + +// Get the third element: +z = arr.get( 2 ); +// returns [ 5n ] +``` + +In addition to providing a scalar value (e.g., integer, [`bigint`][@stdlib/bigint/ctor], or [`Int64`][@stdlib/number/int64/ctor]), to set one or more array elements, provide an array-like object containing scalar values + +```javascript +var Int64 = require( '@stdlib/number/int64/ctor' ); + +var arr = new Int64Array( [ 1, 2, 3 ] ); +// returns [ 1n, 2n, 3n ] + +// Set the first two array elements: +arr.set( [ 4, 5 ] ); + +var z = arr.get( 0 ); +// returns [ 4n ] + +z = arr.get( 1 ); +// returns [ 5n ] +``` + +A few notes: + +- If `i` is out-of-bounds, the method throws an error. +- If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error. +- If provided a [typed array][@stdlib/array/typed] which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range. + +
+ + + +* * * + + + +
+ +* * * + +## Notes + +- While an `Int64Array` _strives_ to maintain (but does not **guarantee**) consistency with [typed arrays][@stdlib/array/typed], significant deviations from ECMAScript-defined [typed array][@stdlib/array/typed] behavior are as follows: + + - The constructor does **not** require the `new` operator. + - The constructor and associated methods support a broader variety of input argument types in order to better accommodate signed integer input. + - Accessing array elements using bracket syntax (e.g., `X[i]`) is **not** supported. Instead, one **must** use the `.get()` method. + - The `set` method has extended behavior in order to support 64-bit signed integer instances. + +
+ + + + + +
+ +* * * + +## Examples + + + +```javascript +var Int64 = require( '@stdlib/number/int64/ctor' ); +var logEach = require( '@stdlib/console/log-each' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Int64Array = require( '@stdlib/array/int64' ); + +// Create a 64-bit signed integer array by specifying a length: +var out = new Int64Array( 3 ); +logEach( '%s', out ); + +// Create a 64-bit signed integer array from an array of 64-bit signed integer numbers: +var arr = [ + new Int64( 1 ), + new Int64( -2 ), + new Int64( 3 ) +]; +out = new Int64Array( arr ); +logEach( '%s', out ); + +// Create a 64-bit signed integer array from a typed array: +arr = new Uint32Array( [ 1, 2, 3, 4 ] ); +out = new Int64Array( arr ); +logEach( '%s', out ); + +// Create a 64-bit signed integer array from an array buffer, where underlying storage consists of interleaved high and low 32-bit words: +arr = new Uint32Array( [ 1, 2, 3, 4 ] ); +out = new Int64Array( arr.buffer ); +logEach( '%s', out ); + +// Create a 64-bit signed integer array from an array buffer view, where underlying storage represents each 64-bit integer as interleaved high and low 32-bit words: +arr = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); +out = new Int64Array( arr.buffer, 16, 2 ); +logEach( '%s', out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.at.js b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.at.js new file mode 100644 index 000000000000..c3ae77b1d6df --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.at.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var format = require( '@stdlib/string/format' ); +var isInt64 = require( '@stdlib/assert/is-int64' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var pkg = require( './../package.json' ).name; +var Int64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::nonnegative_indices:at', pkg ), function benchmark( b ) { + var arr; + var N; + var u; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( new Int64( i ) ); + } + arr = new Int64Array( arr ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + u = arr.at( i%N ); + if ( typeof u !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isInt64( u ) ) { + b.fail( 'should return a 64-bit signed integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::negative_indices:at', pkg ), function benchmark( b ) { + var arr; + var N; + var u; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( new Int64( i ) ); + } + arr = new Int64Array( arr ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + u = arr.at( -(i%N)-1 ); + if ( typeof u !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isInt64( u ) ) { + b.fail( 'should return a 64-bit signed integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.entries.js b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.entries.js new file mode 100644 index 000000000000..419f428e2751 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.entries.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var format = require( '@stdlib/string/format' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var pkg = require( './../package.json' ).name; +var Int64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:entries', pkg ), function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Int64Array( zeroTo( 10, 'generic' ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = arr.entries(); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.from.js b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.from.js new file mode 100644 index 000000000000..6d095c165387 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.from.js @@ -0,0 +1,239 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var identity = require( '@stdlib/number/int64/base/identity' ); +var bench = require( '@stdlib/bench' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var format = require( '@stdlib/string/format' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var pkg = require( './../package.json' ).name; +var Int64Array = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// MAIN // + +bench( format( '%s::typed_array:from', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Uint32Array( [ 1, 2 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Int64Array.from( buf ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::typed_array,clbk:from', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Uint32Array( [ 1, 2 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Int64Array.from( buf, clbk ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return identity( v ); + } +}); + +bench( format( '%s::array:from', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1, 2 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Int64Array.from( buf ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::array,clbk:from', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1, 2 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Int64Array.from( buf, clbk ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return identity( v ); + } +}); + +bench( format( '%s::iterable:from', pkg ), opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Int64Array.from( createIterable() ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out; + var i; + + out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + + i = 0; + + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + i += 1; + if ( i <= 2 ) { + return { + 'value': 0, + 'done': false + }; + } + return { + 'done': true + }; + } + } +}); + +bench( format( '%s::iterable,clbk:from', pkg ), opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Int64Array.from( createIterable(), clbk ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out; + var i; + + out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + + i = 0; + + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + i += 1; + if ( i <= 2 ) { + return { + 'value': 1, + 'done': false + }; + } + return { + 'done': true + }; + } + } + + function clbk( v ) { + return identity( v ); + } +}); diff --git a/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.get.js b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.get.js new file mode 100644 index 000000000000..806aa8f01e5b --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.get.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isInt64 = require( '@stdlib/assert/is-int64' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Int64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:get', pkg ), function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = zeroTo( 10, 'generic' ); + arr = new Int64Array( arr ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.get( i%N ); + if ( !isInt64( v ) ) { + b.fail( 'should return an Int64' ); + } + } + b.toc(); + if ( !isInt64( v ) ) { + b.fail( 'should return an Int64' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.js new file mode 100644 index 000000000000..9c2a87df9128 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.js @@ -0,0 +1,340 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var format = require( '@stdlib/string/format' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var pkg = require( './../package.json' ).name; +var Int64Array = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// MAIN // + +bench( format( '%s::instantiation,new', pkg ), function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Int64Array(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,no_new', pkg ), function benchmark( b ) { + var ctor; + var arr; + var i; + + ctor = Int64Array; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = ctor(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,length', pkg ), function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Int64Array( 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,typed_array', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Uint32Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Int64Array( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,array', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Int64Array( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,iterable', pkg ), opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Int64Array( createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +bench( format( '%s::instantiation,arraybuffer', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Int64Array( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,arraybuffer,byte_offset', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Int64Array( buf, 8 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,arraybuffer,byte_offset,length', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Int64Array( buf, 8, 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::get:buffer', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Int64Array(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.buffer; + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArrayBuffer( v ) ) { + b.fail( 'should return an ArrayBuffer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::get:byteLength', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Int64Array(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteLength; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::get:byteOffset', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Int64Array(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteOffset; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::get:length', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Int64Array(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.length; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.of.js b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.of.js new file mode 100644 index 000000000000..c9d490c92b0b --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.of.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Int64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:of', pkg ), function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Int64Array.of( i, 2 ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !(arr instanceof Int64Array) ) { + b.fail( 'should return an Int64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.set.js b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.set.js new file mode 100644 index 000000000000..606e69426e76 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/benchmark/benchmark.set.js @@ -0,0 +1,210 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Int64Array = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasBigIntSupport() +}; + + +// MAIN // + +bench( format( '%s::integer:set', pkg ), function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = zeroTo( 10, 'generic' ); + arr = new Int64Array( values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values[ (i+1)%N ] * pow( -1, (i+1)%N ) ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::bigint:set', pkg ), opts, function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( BigInt( i ) ); + } + arr = new Int64Array( values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values[ (i+1)%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::Int64:set', pkg ), function benchmark( b ) { + var values; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( new Int64( i ) ); + } + arr = new Int64Array( values ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values[ (i+1)%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::array:set', pkg ), function benchmark( b ) { + var values; + var buf; + var arr; + var N; + var v; + var i; + + values = zeroTo( 10, 'generic' ); + N = values.length; + + arr = new Int64Array( 2 ); + buf = [ 0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + buf[ 0 ] = values[ i%N ]; + v = arr.set( buf ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::typed_array:set', pkg ), function benchmark( b ) { + var values; + var arr; + var buf; + var N; + var v; + var i; + + values = zeroTo( 20, 'uint32' ); + N = values.length; + + arr = new Int64Array( 2 ); + buf = new Uint32Array( 1 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + buf[ 0 ] = values[ i%N ]; + v = arr.set( buf ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::int64array:set', pkg ), function benchmark( b ) { + var values; + var arr; + var v; + var i; + + values = new Int64Array( [ 1234 ] ); + arr = new Int64Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/int64/docs/repl.txt b/lib/node_modules/@stdlib/array/int64/docs/repl.txt new file mode 100644 index 000000000000..7257066a15cb --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/docs/repl.txt @@ -0,0 +1,332 @@ + +{{alias}}() + A typed array constructor which returns a typed array representing an array + of 64-bit signed integers in the platform byte order. + + Returns + ------- + out: Int64Array + A typed array. + + Examples + -------- + > var arr = new {{alias}}() + + + +{{alias}}( length ) + Returns a typed array having a specified length. + + Parameters + ---------- + length: integer + Typed array length. + + Returns + ------- + out: Int64Array + A typed array. + + Examples + -------- + > var arr = new {{alias}}( 5 ) + [ 0n, 0n, 0n, 0n, 0n ] + + +{{alias}}( typedarray ) + Creates a typed array from another typed array. + + Parameters + ---------- + typedarray: TypedArray + Typed array from which to generate another typed array. + + Returns + ------- + out: Int64Array + A typed array. + + Examples + -------- + > var arr1 = new {{alias:@stdlib/array/int32}}( [ 5, 5, 5 ] ); + > var arr2 = new {{alias}}( arr1 ) + [ 5n, 5n, 5n ] + + +{{alias}}( obj ) + Creates a typed array from an array-like object or iterable. + + Parameters + ---------- + obj: Object + Array-like object or iterable from which to generate a typed array. + + Returns + ------- + out: Int64Array + A typed array. + + Examples + -------- + > var arr1 = [ 5, 5, 5 ]; + > var arr2 = new {{alias}}( arr1 ) + [ 5n, 5n, 5n ] + + +{{alias}}( buffer[, byteOffset[, length]] ) + Returns a typed array view of an ArrayBuffer. + + Parameters + ---------- + buffer: ArrayBuffer + Underlying ArrayBuffer. + + byteOffset: integer (optional) + Integer byte offset specifying the location of the first typed array + element. Default: 0. + + length: integer (optional) + View length. If not provided, the view spans from the byteOffset to + the end of the underlying ArrayBuffer. + + Returns + ------- + out: Int64Array + A typed array. + + Examples + -------- + > var buf = new {{alias:@stdlib/array/buffer}}( 32 ); + > var arr = new {{alias}}( buf, 0, 4 ) + [ 0n, 0n, 0n, 0n ] + + +{{alias}}.from( src[, map[, thisArg]] ) + Creates a new typed array from an array-like object or an iterable. + + A callback is provided the following arguments: + + - value: source value. + - index: source index. + + Parameters + ---------- + src: ArrayLike|Iterable + Source of array elements. + + map: Function (optional) + Callback to invoke for each source element. + + thisArg: any (optional) + Callback execution context. + + Returns + ------- + out: Int64Array + A typed array. + + Examples + -------- + > function mapFcn( v ) { return v; }; + > var arr = {{alias}}.from( [ 1, 2 ], mapFcn ) + [ 1n, 2n ] + + +{{alias}}.of( element0[, element1[, ...elementN]] ) + Creates a new typed array from a variable number of arguments. + + Parameters + ---------- + element0: number + Array element. + + element1: number (optional) + Array element. + + elementN: ...number (optional) + Array elements. + + Returns + ------- + out: Int64Array + A typed array. + + Examples + -------- + > var arr = {{alias}}.of( 1, 2 ) + [ 1n, 2n ] + + +{{alias}}.BYTES_PER_ELEMENT + Number of bytes per view element. + + Examples + -------- + > {{alias}}.BYTES_PER_ELEMENT + 8 + + +{{alias}}.name + Typed array constructor name. + + Examples + -------- + > {{alias}}.name + 'Int64Array' + + +{{alias}}.prototype.buffer + Read-only property which returns the ArrayBuffer referenced by the typed + array. + + Examples + -------- + > var arr = new {{alias}}( 5 ); + > arr.buffer + + + +{{alias}}.prototype.byteLength + Read-only property which returns the length (in bytes) of the typed array. + + Examples + -------- + > var arr = new {{alias}}( 5 ); + > arr.byteLength + 40 + + +{{alias}}.prototype.byteOffset + Read-only property which returns the offset (in bytes) of the typed array + from the start of its ArrayBuffer. + + Examples + -------- + > var arr = new {{alias}}( 5 ); + > arr.byteOffset + 0 + + +{{alias}}.prototype.BYTES_PER_ELEMENT + Number of bytes per view element. + + Examples + -------- + > var arr = new {{alias}}( 5 ); + > arr.BYTES_PER_ELEMENT + 8 + + +{{alias}}.prototype.length + Read-only property which returns the number of view elements. + + Examples + -------- + > var arr = new {{alias}}( 5 ); + > arr.length + 5 + + +{{alias}}.prototype.at( i ) + Returns an array element located at integer position (index) `i`, with + support for both nonnegative and negative integer positions. + + If provided an index outside the array index range, the method returns + `undefined`. + + Parameters + ---------- + i: integer + Element index. + + Returns + ------- + out: Int64|void + Array element or `undefined`. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2 ] ) + [ 1n, 2n ] + > var z = arr.at( 1 ) + [ 2n ] + + +{{alias}}.prototype.entries() + Returns an iterator for iterating over array key-value pairs. + + Returns + ------- + iterator: Iterator + Iterator for iterating over array key-value pairs. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3 ] ) + [ 1n, 2n, 3n ] + > var it = arr.entries(); + > var v = it.next().value + [ 0, [ 1n ] ] + > v = it.next().value + [ 1, [ 2n ] ] + > v = it.next().value + [ 2, [ 3n ] ] + > var bool = it.next().done + true + + +{{alias}}.prototype.get( i ) + Returns an array element located at integer position (index) `i`. + + If provided an index outside the array index range, the method returns + `undefined`. + + Parameters + ---------- + i: integer + Element index. + + Returns + ------- + out: Int64|void + Array element or `undefined`. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2 ] ) + [ 1n, 2n ] + > var z = arr.get( 1 ) + [ 2n ] + + +{{alias}}.prototype.set( v[, i] ) + Sets one or more array elements. + + If provided a single argument, the method sets array elements starting at + position (index) `i = 0`. To set elements starting elsewhere in the array, + provide an index argument `i`. + + To set one or more array elements, provide an array-like object. + + Parameters + ---------- + v: Int64|number|bigint|ArrayLikeObject + Scalar or source array containing array values to set. + + i: integer (optional) + Array index at which to start setting elements. Default: 0. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3 ] ); + > arr.set( new {{alias:@stdlib/number/int64/ctor}}( 4 ), 1 ); + > var z = arr.get( 1 ) + [ 4n ] + > arr.set( [ 5, 6 ], 1 ); + > z = arr.get( 1 ) + [ 5n ] + > z = arr.get( 2 ) + [ 6n ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/array/int64/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/int64/docs/types/index.d.ts new file mode 100644 index 000000000000..5bfb2966e3bc --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/docs/types/index.d.ts @@ -0,0 +1,822 @@ +/* eslint-disable max-lines */ + +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Iterator as Iter, IterableIterator, TypedIterator } from '@stdlib/types/iter'; +import { ArrayLike, Int64Array as Int64ArrayInterface } from '@stdlib/types/array'; +import { Int64 } from '@stdlib/types/number'; +import ArrayBuffer = require( '@stdlib/array/buffer' ); + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = Iter | IterableIterator; + +// Define a type representing a value from which a 64-bit signed integer can be derived: +type Int = Int64 | bigint | number; + +/** +* Locale-specific configuration options. +*/ +interface LocaleOptions { + /** + * Configuration property. + */ + [ key: string | symbol | number ]: T | undefined; +} + +/** +* Callback invoked for each element in a source object. +* +* @returns transformed value +*/ +type FromNullary = ( this: U ) => Int; + +/** +* Callback invoked for each element in a source object. +* +* @param value - source element +* @returns transformed value +*/ +type FromUnary = ( this: U, value: Int ) => Int; + +/** +* Callback invoked for each element in a source object. +* +* @param value - source element +* @param index - source element index +* @returns transformed value +*/ +type FromBinary = ( this: U, value: Int, index: number ) => Int; + +/** +* Callback invoked for each element in a source object. +* +* @param value - source element +* @param index - source element index +* @returns transformed value +*/ +type FromCallback = FromNullary | FromUnary | FromBinary; + +/** +* Checks whether an element in an array passes a test. +* +* @returns boolean indicating whether an element in an array passes a test +*/ +type NullaryPredicate = ( this: U ) => boolean; + +/** +* Checks whether an element in an array passes a test. +* +* @param value - current array element +* @returns boolean indicating whether an element in an array passes a test +*/ +type UnaryPredicate = ( this: U, value: Int64 ) => boolean; + +/** +* Checks whether an element in an array passes a test. +* +* @param value - current array element +* @param index - current array element index +* @returns boolean indicating whether an element in an array passes a test +*/ +type BinaryPredicate = ( this: U, value: Int64, index: number ) => boolean; + +/** +* Checks whether an element in an array passes a test. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns boolean indicating whether an element in an array passes a test +*/ +type TernaryPredicate = ( this: U, value: Int64, index: number, arr: Int64Array ) => boolean; + +/** +* Checks whether an element in an array passes a test. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns boolean indicating whether an element in an array passes a test +*/ +type Predicate = NullaryPredicate | UnaryPredicate | BinaryPredicate | TernaryPredicate; + +/** +* Callback invoked for each element in an array. +* +* @returns undefined +*/ +type NullaryCallback = ( this: U ) => void; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @returns undefined +*/ +type UnaryCallback = ( this: U, value: Int64 ) => void; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @returns undefined +*/ +type BinaryCallback = ( this: U, value: Int64, index: number ) => void; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns undefined +*/ +type TernaryCallback = ( this: U, value: Int64, index: number, arr: Int64Array ) => void; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns undefined +*/ +type Callback = NullaryCallback | UnaryCallback | BinaryCallback | TernaryCallback; + +/** +* Callback invoked for each element in an array. +* +* @returns transformed value +*/ +type NullaryMapFcn = ( this: U ) => Int; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @returns transformed value +*/ +type UnaryMapFcn = ( this: U, value: Int64 ) => Int; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @returns transformed value +*/ +type BinaryMapFcn = ( this: U, value: Int64, index: number ) => Int; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns transformed value +*/ +type TernaryMapFcn = ( this: U, value: Int64, index: number, arr: Int64Array ) => Int; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns transformed value +*/ +type MapFcn = NullaryMapFcn | UnaryMapFcn | BinaryMapFcn | TernaryMapFcn; + +/** +* Reducer function invoked for each element in an array. +* +* @returns accumulated result +*/ +type NullaryReducer = () => U; + +/** +* Reducer function invoked for each element in an array. +* +* @param acc - accumulated result +* @returns accumulated result +*/ +type UnaryReducer = ( acc: U ) => U; + +/** +* Reducer function invoked for each element in an array. +* +* @param acc - accumulated result +* @param value - current array element +* @returns accumulated result +*/ +type BinaryReducer = ( acc: U, value: Int64 ) => U; + +/** +* Reducer function invoked for each element in an array. +* +* @param acc - accumulated result +* @param value - current array element +* @param index - current array element index +* @returns accumulated result +*/ +type TernaryReducer = ( acc: U, value: Int64, index: number ) => U; + +/** +* @param acc - accumulated result +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns accumulated result +*/ +type QuaternaryReducer = ( acc: U, value: Int64, index: number, arr: Int64Array ) => U; + +/** +* Reducer function invoked for each element in an array. +* +* @param acc - accumulated result +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns accumulated result +*/ +type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; + +/** +* Comparator function. +* +* @param a - first value for comparison +* @param b - second value for comparison +* @returns number indicating comparison result +*/ +type CompareFcn = ( a: Int64, b: Int64 ) => number; + +/** +* Class for creating a 64-bit signed integer array. +*/ +declare class Int64Array implements Int64ArrayInterface { + /** + * 64-bit signed integer array constructor. + * + * @param arg - length, typed array, array-like object, or buffer + * @param byteOffset - byte offset (default: 0) + * @param length - view length + * @throws ArrayBuffer byte length must be a multiple of `8` + * @throws if provided only a single argument, must provide a valid argument + * @throws byte offset must be a nonnegative integer + * @throws byte offset must be a multiple of `8` + * @throws view length must be a positive multiple of `8` + * @throws must provide sufficient memory to accommodate byte offset and view length requirements + * @throws an array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer + * @throws an iterator must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer + * @returns 64-bit signed integer array + * + * @example + * var arr = new Int64Array(); + * // returns + * + * var len = arr.length; + * // returns 0 + * + * @example + * var arr = new Int64Array( 2 ); + * // returns [ 0n, 0n ] + * + * var len = arr.length; + * // returns 2 + * + * @example + * var arr = new Int64Array( [ 1 ] ); + * // returns [ 1n ] + * + * var len = arr.length; + * // returns 1 + * + * @example + * var ArrayBuffer = require( '@stdlib/array/buffer' ); + * + * var buf = new ArrayBuffer( 16 ); + * var arr = new Int64Array( buf ); + * // returns [ 0n, 0n ] + * + * var len = arr.length; + * // returns 2 + * + * @example + * var ArrayBuffer = require( '@stdlib/array/buffer' ); + * + * var buf = new ArrayBuffer( 32 ); + * var arr = new Int64Array( buf, 16 ); + * // returns [ 0n, 0n ] + * + * var len = arr.length; + * // returns 2 + * + * @example + * var ArrayBuffer = require( '@stdlib/array/buffer' ); + * + * var buf = new ArrayBuffer( 64 ); + * var arr = new Int64Array( buf, 16, 2 ); + * // returns [ 0n, 0n ] + * + * var len = arr.length; + * // returns 2 + */ + constructor( arg?: number | ArrayLike | Int64Array | ArrayBuffer | Iterable, byteOffset?: number, length?: number ); + + /** + * Pointer to the underlying data buffer. + * + * @example + * var arr = new Int64Array( 10 ); + * + * var buf = arr.buffer; + * // returns + */ + readonly buffer: ArrayBuffer; + + /** + * Length (in bytes) of the array. + * + * @example + * var arr = new Int64Array( 10 ); + * + * var byteLength = arr.byteLength; + * // returns 80 + */ + readonly byteLength: number; + + /** + * Offset (in bytes) of the array from the start of its underlying `ArrayBuffer`. + * + * @example + * var arr = new Int64Array( 10 ); + * + * var byteOffset = arr.byteOffset; + * // returns 0 + */ + readonly byteOffset: number; + + /** + * Size (in bytes) of each array element. + * + * @example + * var arr = new Int64Array( 10 ); + * + * var nbytes = arr.BYTES_PER_ELEMENT; + * // returns 8 + */ + readonly BYTES_PER_ELEMENT: 8; + + /** + * Number of array elements. + * + * @example + * var arr = new Int64Array( 10 ); + * + * var len = arr.length; + * // returns 10 + */ + readonly length: number; + + /** + * Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer indices. + * + * @param i - element index + * @throws index argument must be an integer + * @returns array element + * + * @example + * var arr = new Int64Array( 10 ); + * + * var u = arr.at( 0 ); + * // returns [ 0n ] + * + * arr.set( 1, 0 ); + * arr.set( 9, 9 ); + * + * u = arr.at( -1 ); + * // returns [ 9n ] + * + * u = arr.at( 100 ); + * // returns undefined + * + * u = arr.at( -100 ); + * // returns undefined + */ + at( i: number ): Int64 | void; + + /** + * Returns an iterator for iterating over array key-value pairs. + * + * @returns iterator + * + * @example + * var Int64 = require( '@stdlib/number/int64/ctor' ); + * + * var arr = [ + * new Int64( 1 ), + * new Int64( 2 ), + * new Int64( 3 ) + * ]; + * arr = new Int64Array( arr ); + * + * // Create an iterator: + * var it = arr.entries(); + * + * // Iterate over the key-value pairs... + * var v = it.next().value; + * // returns [ 0, [ 1n ] ] + * + * v = it.next().value; + * // returns [ 1, [ 2n ] ] + * + * v = it.next().value; + * // returns [ 2, [ 3n ] ] + * + * var bool = it.next().done; + * // returns true + */ + entries(): TypedIterator<[number, Int64]>; + + /** + * Returns an array element. + * + * @param i - element index + * @throws index argument must be a nonnegative integer + * @returns array element + * + * @example + * var arr = new Int64Array( 10 ); + * + * var z = arr.get( 0 ); + * // returns [ 0n ] + * + * arr.set( 1, 0 ); + * + * var z = arr.get( 0 ); + * // returns [ 1n ] + * + * z = arr.get( 100 ); + * // returns undefined + */ + get( i: number ): Int64 | void; + + /** + * Sets an array element. + * + * ## Notes + * + * - When provided a typed array, we must check whether the source array shares the same buffer as the target array and whether the underlying memory overlaps. In particular, we are concerned with the following scenario: + * + * ```text + * buf: --------------------- + * src: --------------------- + * ``` + * + * In the above, as we copy values from `src`, we will overwrite values in the `src` view, resulting in duplicated values copied into the end of `buf`, which is not intended. Hence, to avoid overwriting source values, we must **copy** source values to a temporary array. + * + * In the other overlapping scenario, + * + * ```text + * buf: --------------------- + * src: --------------------- + * ``` + * + * by the time we begin copying into the overlapping region, we are copying from the end of `src`, a non-overlapping region, which means we don't run the risk of copying copied values, rather than the original `src` values as intended. + * + * + * @param value - value(s) + * @param i - element index at which to start writing values (default: 0) + * @throws index argument must be a nonnegative integer + * @throws index argument is out-of-bounds + * @throws target array lacks sufficient storage to accommodate source values + * @throws an array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer + * + * @example + * var arr = new Int64Array( 10 ); + * + * var z = arr.get( 0 ); + * // returns [ 0n ] + * + * arr.set( 1, 0 ); + * + * z = arr.get( 0 ); + * // returns [ 1n ] + */ + set( value: ArrayLike | Int64Array | Int, i?: number ): void; +} + +/** +* Interface defining a 64-bit signed integer array constructor which is both "newable" and "callable". +*/ +interface Int64ArrayConstructor { + /** + * 64-bit signed integer array constructor. + * + * @param arg - length, typed array, array-like object, or buffer + * @param byteOffset - byte offset (default: 0) + * @param length - view length + * @throws ArrayBuffer byte length must be a multiple of `8` + * @throws if provided only a single argument, must provide a valid argument + * @throws byte offset must be a nonnegative integer + * @throws byte offset must be a multiple of `8` + * @throws view length must be a positive multiple of `8` + * @throws must provide sufficient memory to accommodate byte offset and view length requirements + * @throws an array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer + * @throws an iterator must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer + * @returns 64-bit signed integer array + * + * @example + * var arr = new Int64Array(); + * // returns + * + * var len = arr.length; + * // returns 0 + * + * @example + * var arr = new Int64Array( 2 ); + * // returns [ 0n, 0n ] + * + * var len = arr.length; + * // returns 2 + * + * @example + * var arr = new Int64Array( [ 1 ] ); + * // returns [ 1n ] + * + * var len = arr.length; + * // returns 1 + * + * @example + * var ArrayBuffer = require( '@stdlib/array/buffer' ); + * + * var buf = new ArrayBuffer( 16 ); + * var arr = new Int64Array( buf ); + * // returns [ 0n, 0n ] + * + * var len = arr.length; + * // returns 2 + * + * @example + * var ArrayBuffer = require( '@stdlib/array/buffer' ); + * + * var buf = new ArrayBuffer( 16 ); + * var arr = new Int64Array( buf, 8 ); + * // returns [ 0n ] + * + * var len = arr.length; + * // returns 1 + * + * @example + * var ArrayBuffer = require( '@stdlib/array/buffer' ); + * + * var buf = new ArrayBuffer( 64 ); + * var arr = new Int64Array( buf, 16, 2 ); + * // returns [ 0n, 0n ] + * + * var len = arr.length; + * // returns 2 + */ + new( arg?: number | ArrayLike | Int64Array | ArrayBuffer | Iterable, byteOffset?: number, length?: number ): Int64Array; + + /** + * 64-bit signed integer array constructor. + * + * @param arg - length, typed array, array-like object, or buffer + * @param byteOffset - byte offset (default: 0) + * @param length - view length + * @throws ArrayBuffer byte length must be a multiple of `8` + * @throws if provided only a single argument, must provide a valid argument + * @throws byte offset must be a nonnegative integer + * @throws byte offset must be a multiple of `8` + * @throws view length must be a positive multiple of `8` + * @throws must provide sufficient memory to accommodate byte offset and view length requirements + * @throws an array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer + * @throws an iterator must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer + * @returns 64-bit signed integer array + * + * @example + * var arr = new Int64Array(); + * // returns + * + * var len = arr.length; + * // returns 0 + * + * @example + * var arr = new Int64Array( 2 ); + * // returns [ 0n, 0n ] + * + * var len = arr.length; + * // returns 2 + * + * @example + * var arr = new Int64Array( [ 1 ] ); + * // returns [ 1n ] + * + * var len = arr.length; + * // returns 1 + * + * @example + * var ArrayBuffer = require( '@stdlib/array/buffer' ); + * + * var buf = new ArrayBuffer( 16 ); + * var arr = new Int64Array( buf ); + * // returns [ 0n, 0n ] + * + * var len = arr.length; + * // returns 2 + * + * @example + * var ArrayBuffer = require( '@stdlib/array/buffer' ); + * + * var buf = new ArrayBuffer( 16 ); + * var arr = new Int64Array( buf, 8 ); + * // returns [ 0n ] + * + * var len = arr.length; + * // returns 1 + * + * @example + * var ArrayBuffer = require( '@stdlib/array/buffer' ); + * + * var buf = new ArrayBuffer( 64 ); + * var arr = new Int64Array( buf, 16, 2 ); + * // returns [ 0n, 0n ] + * + * var len = arr.length; + * // returns 2 + */ + ( arg?: number | ArrayLike | Int64Array | ArrayBuffer | Iterable, byteOffset?: number, length?: number ): Int64Array; + + /** + * Constructor name. + * + * @example + * var str = Int64Array.name; + * // returns 'Int64Array' + */ + readonly name: 'Int64Array'; + + /** + * Size (in bytes) of each array element. + * + * @example + * var nbytes = Int64Array.BYTES_PER_ELEMENT; + * // returns 8 + */ + readonly BYTES_PER_ELEMENT: 8; + + /** + * Creates a new 64-bit signed integer array from an array-like object or an iterable. + * + * @param src - array-like object or iterable + * @param clbk - callback to invoke for each source element + * @param thisArg - context + * @throws an array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer + * @throws an iterator must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer + * @throws when provided an iterator, a callback must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer + * @returns 64-bit signed integer array + * + * @example + * var arr = Int64Array.from( [ 1 ] ); + * // returns [ 1n ] + * + * var len = arr.length; + * // returns 1 + * + * @example + * var Int64 = require( '@stdlib/number/int64/ctor' ); + * + * var arr = Int64Array.from( [ new Int64( 1 ) ] ); + * // returns [ 1n ] + * + * var len = arr.length; + * // returns 1 + * + * @example + * var Int64 = require( '@stdlib/number/int64/ctor' ); + * + * function clbk( v ) { + * return v * 2; + * } + * + * var arr = Int64Array.from( [ 1, 2 ], clbk ); + * // returns [ 2n, 4n ] + * + * var len = arr.length; + * // returns 2 + */ + from( src: ArrayLike | Int64Array | Iterable, clbk?: FromCallback, thisArg?: ThisParameterType> ): Int64Array; + + /** + * Creates a new 64-bit signed integer array from a variable number of arguments. + * + * @param elements - array elements + * @returns 64-bit signed integer array + * + * @example + * var arr = Int64Array.of( 1, 2, 3, 4 ); + * // returns [ 1n, 2n, 3n, 4n ] + * + * var len = arr.length; + * // returns 4 + */ + of( ...elements: Array ): Int64Array; +} + +/** +* 64-bit signed integer array constructor. +* +* @param arg - length, typed array, array-like object, or buffer +* @param byteOffset - byte offset (default: 0) +* @param length - view length +* @throws ArrayBuffer byte length must be a multiple of `8` +* @throws if provided only a single argument, must provide a valid argument +* @throws byte offset must be a nonnegative integer +* @throws byte offset must be a multiple of `8` +* @throws view length must be a positive multiple of `8` +* @throws must provide sufficient memory to accommodate byte offset and view length requirements +* @throws an array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer +* @throws an iterator must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer +* @returns 64-bit signed integer array +* +* @example +* var arr = new Int64Array(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var arr = new Int64Array( 2 ); +* // returns [ 0n, 0n ] +* +* var len = arr.length; +* // returns 2 +* +* @example +* var arr = new Int64Array( [ 1 ] ); +* // returns [ 1n ] +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Int64Array( buf ); +* // returns [ 0n, 0n ] +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Int64Array( buf, 8 ); +* // returns [ 0n ] +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 64 ); +* var arr = new Int64Array( buf, 16, 2 ); +* // returns [ 0n, 0n ] +* +* var len = arr.length; +* // returns 2 +*/ +declare var ctor: Int64ArrayConstructor; + + +// EXPORTS // + +export = ctor; + +// eslint-doctest-alias: Int64Array diff --git a/lib/node_modules/@stdlib/array/int64/docs/types/test.ts b/lib/node_modules/@stdlib/array/int64/docs/types/test.ts new file mode 100644 index 000000000000..07a88597c913 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/docs/types/test.ts @@ -0,0 +1,159 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions */ + +import Int64 = require( '@stdlib/number/int64/ctor' ); +import getLowWord = require( '@stdlib/number/int64/base/get-low-word' ); +import getHighWord = require( '@stdlib/number/int64/base/get-high-word' ); +import ArrayBuffer = require( '@stdlib/array/buffer' ); +import Int64Array = require( './index' ); + +/** +* Callback function. +* +* @param v - input value +* @returns output value +*/ +function clbk( v: Int64 ): Int64 { + return Int64.of( getLowWord( v ), getHighWord( v ) ); +} + + +// TESTS // + +// The function returns a 64-bit signed integer array... +{ + new Int64Array(); // $ExpectType Int64Array + Int64Array(); // $ExpectType Int64Array + new Int64Array( 2 ); // $ExpectType Int64Array + Int64Array( 2 ); // $ExpectType Int64Array + new Int64Array( [ 1 ] ); // $ExpectType Int64Array + Int64Array( [ 1 ] ); // $ExpectType Int64Array + + const buf = new ArrayBuffer( 8 ); + new Int64Array( buf ); // $ExpectType Int64Array + Int64Array( buf ); // $ExpectType Int64Array + new Int64Array( buf, 4 ); // $ExpectType Int64Array + Int64Array( buf, 4 ); // $ExpectType Int64Array + new Int64Array( buf, 4, 1 ); // $ExpectType Int64Array + Int64Array( buf, 4, 1 ); // $ExpectType Int64Array +} + +// The compiler throws an error if the function is provided a first argument that is not a number, typed array, array-like object, or array buffer... +{ + new Int64Array( true ); // $ExpectError + new Int64Array( false ); // $ExpectError + new Int64Array( null ); // $ExpectError + new Int64Array( 'abc' ); // $ExpectError + new Int64Array( {} ); // $ExpectError + new Int64Array( ( x: number ): number => x ); // $ExpectError + + Int64Array( true ); // $ExpectError + Int64Array( false ); // $ExpectError + Int64Array( null ); // $ExpectError + Int64Array( 'abc' ); // $ExpectError + Int64Array( {} ); // $ExpectError + Int64Array( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument that is not a number... +{ + const buf = new ArrayBuffer( 8 ); + new Int64Array( buf, true ); // $ExpectError + new Int64Array( buf, false ); // $ExpectError + new Int64Array( buf, null ); // $ExpectError + new Int64Array( buf, 'abc' ); // $ExpectError + new Int64Array( buf, {} ); // $ExpectError + new Int64Array( buf, ( x: number ): number => x ); // $ExpectError + + Int64Array( buf, true ); // $ExpectError + Int64Array( buf, false ); // $ExpectError + Int64Array( buf, null ); // $ExpectError + Int64Array( buf, 'abc' ); // $ExpectError + Int64Array( buf, {} ); // $ExpectError + Int64Array( buf, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument that is not a number... +{ + const buf = new ArrayBuffer( 8 ); + new Int64Array( buf, 4, true ); // $ExpectError + new Int64Array( buf, 4, false ); // $ExpectError + new Int64Array( buf, 4, null ); // $ExpectError + new Int64Array( buf, 4, 'abc' ); // $ExpectError + new Int64Array( buf, 4, {} ); // $ExpectError + new Int64Array( buf, 4, ( x: number ): number => x ); // $ExpectError + + Int64Array( buf, 4, true ); // $ExpectError + Int64Array( buf, 4, false ); // $ExpectError + Int64Array( buf, 4, null ); // $ExpectError + Int64Array( buf, 4, 'abc' ); // $ExpectError + Int64Array( buf, 4, {} ); // $ExpectError + Int64Array( buf, 4, ( x: number ): number => x ); // $ExpectError +} + +// The `from` method returns a 64-bit signed integer array... +{ + Int64Array.from( [ 1 ] ); // $ExpectType Int64Array + Int64Array.from( [ 1 ], ( x: number ): number => x * x ); // $ExpectType Int64Array + Int64Array.from( [ new Int64( 1 ) ], clbk, {} ); // $ExpectType Int64Array +} + +// The compiler throws an error if the `from` method is provided a first argument which is not array-like or iterable... +{ + Int64Array.from( true ); // $ExpectError + Int64Array.from( false ); // $ExpectError + Int64Array.from( 123 ); // $ExpectError + Int64Array.from( null ); // $ExpectError + Int64Array.from( {} ); // $ExpectError + + Int64Array.from( true, clbk ); // $ExpectError + Int64Array.from( false, clbk ); // $ExpectError + Int64Array.from( 123, clbk ); // $ExpectError + Int64Array.from( null, clbk ); // $ExpectError + Int64Array.from( {}, clbk ); // $ExpectError + + Int64Array.from( true, clbk, {} ); // $ExpectError + Int64Array.from( false, clbk, {} ); // $ExpectError + Int64Array.from( 123, clbk, {} ); // $ExpectError + Int64Array.from( null, clbk, {} ); // $ExpectError + Int64Array.from( {}, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the `from` method is provided a second argument which is not a function with a supported signature... +{ + Int64Array.from( [ 1 ], true ); // $ExpectError + Int64Array.from( [ 1 ], false ); // $ExpectError + Int64Array.from( [ 1 ], 123 ); // $ExpectError + Int64Array.from( [ 1 ], null ); // $ExpectError + Int64Array.from( [ 1 ], {} ); // $ExpectError +} + +// The `of` method returns a 64-bit signed integer array... +{ + Int64Array.of( 1, 1, 1, 1 ); // $ExpectType Int64Array +} + +// The compiler throws an error if the `of` method is provided arguments that are not numbers... +{ + Int64Array.of( 'abc', 'def' ); // $ExpectError + Int64Array.of( true, false ); // $ExpectError + Int64Array.of( {}, [] ); // $ExpectError + Int64Array.of( null, null ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/int64/examples/index.js b/lib/node_modules/@stdlib/array/int64/examples/index.js new file mode 100644 index 000000000000..9175c22d94de --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/examples/index.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var Int64 = require( '@stdlib/number/int64/ctor' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var logEach = require( '@stdlib/console/log-each' ); +var Int64Array = require( './../lib' ); + +// Create a 64-bit signed integer array by specifying a length: +var out = new Int64Array( 3 ); +logEach( '%s', out ); + +// Create a 64-bit signed integer array from an array of 64-bit signed integer numbers: +var arr = [ + new Int64( 1 ), + new Int64( -2 ), + new Int64( 3 ) +]; +out = new Int64Array( arr ); +logEach( '%s', out ); + +// Create a 64-bit signed integer array from a typed array: +arr = new Uint32Array( [ 1, 2, 3, 4 ] ); +out = new Int64Array( arr ); +logEach( '%s', out ); + +// Create a 64-bit signed integer array from an array buffer, where underlying storage consists of interleaved high and low 32-bit words: +arr = new Uint32Array( [ 1, 2, 3, 4 ] ); +out = new Int64Array( arr.buffer ); +logEach( '%s', out ); + +// Create a 64-bit signed integer array from an array buffer view, where underlying storage represents each 64-bit integer as interleaved high and low 32-bit words: +arr = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); +out = new Int64Array( arr.buffer, 16, 2 ); +logEach( '%s', out ); diff --git a/lib/node_modules/@stdlib/array/int64/lib/from_array.js b/lib/node_modules/@stdlib/array/int64/lib/from_array.js new file mode 100644 index 000000000000..543a4350d2da --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/lib/from_array.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isInt64 = require( '@stdlib/assert/is-int64' ); +var toWords = require( '@stdlib/number/int64/base/to-words' ).assign; +var Int64 = require( '@stdlib/number/int64/ctor' ); +var format = require( '@stdlib/string/format' ); +var indices = require( './indices.js' ); + + +// MAIN // + +/** +* Returns a strided array of high and low words. +* +* @private +* @param {Uint32Array} buf - output array +* @param {Array} arr - array containing 64-bit signed integers +* @returns {(Uint32Array|TypeError)} output array or an error +*/ +function fromArray( buf, arr ) { + var words; + var len; + var v; + var i; + var j; + + // Workspace for storing high and low words: + words = [ 0, 0 ]; + + len = arr.length; + j = 0; + for ( i = 0; i < len; i++ ) { + v = arr[ i ]; + if ( !isInt64( v ) ) { + try { + v = new Int64( v ); + } catch ( err ) { // eslint-disable-line no-unused-vars + return new TypeError( format( 'invalid argument. An array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer. Value: `%s`.', v ) ); + } + } + toWords( v, words, 1, 0 ); + buf[ j+indices.HIGH ] = words[ 0 ]; + buf[ j+indices.LOW ] = words[ 1 ]; + j += 2; // stride + } + return buf; +} + + +// EXPORTS // + +module.exports = fromArray; diff --git a/lib/node_modules/@stdlib/array/int64/lib/from_iterator.js b/lib/node_modules/@stdlib/array/int64/lib/from_iterator.js new file mode 100644 index 000000000000..3af2e80a1a32 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/lib/from_iterator.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isInt64 = require( '@stdlib/assert/is-int64' ); +var toWords = require( '@stdlib/number/int64/base/to-words' ).assign; +var Int64 = require( '@stdlib/number/int64/ctor' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an array of iterated values. +* +* @private +* @param {Object} it - iterator +* @returns {(Array|TypeError)} array or an error +*/ +function fromIterator( it ) { + var words; + var out; + var v; + var u; + + // Workspace for storing high and low words: + words = [ 0, 0 ]; + + out = []; + while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + u = v.value; + if ( !isInt64( u ) ) { + try { + u = new Int64( u ); + } catch ( err ) { // eslint-disable-line no-unused-vars + return new TypeError( format( 'invalid argument. An iterator must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer. Value: `%s`.', u ) ); + } + } + toWords( u, words, 1, 0 ); + out.push( words[ 0 ], words[ 1 ] ); + } + return out; +} + + +// EXPORTS // + +module.exports = fromIterator; diff --git a/lib/node_modules/@stdlib/array/int64/lib/from_iterator_map.js b/lib/node_modules/@stdlib/array/int64/lib/from_iterator_map.js new file mode 100644 index 000000000000..700cd954985e --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/lib/from_iterator_map.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isInt64 = require( '@stdlib/assert/is-int64' ); +var toWords = require( '@stdlib/number/int64/base/to-words' ).assign; +var Int64 = require( '@stdlib/number/int64/ctor' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an array of iterated values. +* +* @private +* @param {Object} it - iterator +* @param {Function} clbk - callback to invoke for each iterated value +* @param {*} thisArg - invocation context +* @returns {(Array|TypeError)} array or an error +*/ +function fromIteratorMap( it, clbk, thisArg ) { + var words; + var out; + var v; + var u; + var i; + + // Workspace for storing high and low words: + words = [ 0, 0 ]; + + out = []; + i = -1; + while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + i += 1; + u = clbk.call( thisArg, v.value, i ); + if ( !isInt64( u ) ) { + try { + u = new Int64( u ); + } catch ( err ) { // eslint-disable-line no-unused-vars + return new TypeError( format( 'invalid argument. An iterator must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer. Value: `%s`.', u ) ); + } + } + toWords( u, words, 1, 0 ); + out.push( words[ 0 ], words[ 1 ] ); + } + return out; +} + + +// EXPORTS // + +module.exports = fromIteratorMap; diff --git a/lib/node_modules/@stdlib/array/int64/lib/index.js b/lib/node_modules/@stdlib/array/int64/lib/index.js new file mode 100644 index 000000000000..41e82d6fb55f --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/lib/index.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* 64-bit signed integer array. +* +* @module @stdlib/array/int64 +* +* @example +* var Int64Array = require( '@stdlib/array/int64' ); +* +* var arr = new Int64Array(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var Int64Array = require( '@stdlib/array/int64' ); +* +* var arr = new Int64Array( 2 ); +* // returns [ 0n, 0n ] +* +* var len = arr.length; +* // returns 2 +* +* @example +* var Int64Array = require( '@stdlib/array/int64' ); +* +* var arr = new Int64Array( [ 1 ] ); +* // returns [ 1n ] +* +* var len = arr.length; +* // returns 1 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Int64Array = require( '@stdlib/array/int64' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Int64Array( buf ); +* // returns [ 0n, 0n, 0n, 0n ] +* +* var len = arr.length; +* // returns 4 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Int64Array = require( '@stdlib/array/int64' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Int64Array( buf, 16 ); +* // returns [ 0n, 0n ] +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Int64Array = require( '@stdlib/array/int64' ); +* +* var buf = new ArrayBuffer( 64 ); +* var arr = new Int64Array( buf, 16, 2 ); +* // returns [ 0n, 0n ] +* +* var len = arr.length; +* // returns 2 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/int64/lib/indices.js b/lib/node_modules/@stdlib/array/int64/lib/indices.js new file mode 100644 index 000000000000..57341d75b278 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/lib/indices.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isLittleEndian = require( '@stdlib/assert/is-little-endian' ); + + +// MAIN // + +var indices; +var HIGH; +var LOW; + +if ( isLittleEndian === true ) { + HIGH = 1; // second index + LOW = 0; // first index +} else { + HIGH = 0; // first index + LOW = 1; // second index +} +indices = { + 'HIGH': HIGH, + 'LOW': LOW +}; + + +// EXPORTS // + +module.exports = indices; diff --git a/lib/node_modules/@stdlib/array/int64/lib/main.js b/lib/node_modules/@stdlib/array/int64/lib/main.js new file mode 100644 index 000000000000..a3348b4fd33b --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/lib/main.js @@ -0,0 +1,976 @@ +/* eslint-disable no-restricted-syntax, max-lines, no-invalid-this */ + +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); +var isBigInt = require( '@stdlib/assert/is-bigint' ).isPrimitive; +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isIntegerPrimitive = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isCollection = require( '@stdlib/assert/is-collection' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isObject = require( '@stdlib/assert/is-object' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isInt64 = require( '@stdlib/assert/is-int64' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var accessorGetter = require( '@stdlib/array/base/accessor-getter' ); +var getter = require( '@stdlib/array/base/getter' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Number = require( '@stdlib/number/ctor' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var toWords = require( '@stdlib/number/int64/base/to-words' ).assign; +var format = require( '@stdlib/string/format' ); +var copy = require( '@stdlib/array/base/copy' ); +var indices = require( './indices.js' ); +var fromIterator = require( './from_iterator.js' ); +var fromIteratorMap = require( './from_iterator_map.js' ); +var fromArray = require( './from_array.js' ); + + +// VARIABLES // + +var BYTES_PER_ELEMENT = Uint32Array.BYTES_PER_ELEMENT * 2; +var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); + + +// FUNCTIONS // + +/** +* Returns a boolean indicating if a value is a 64-bit signed integer array. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a signed typed array +*/ +function isInt64Array( value ) { + return ( + value instanceof Int64Array || + ( + typeof value === 'object' && + value !== null && + value.constructor.name === 'Int64Array' && + value.BYTES_PER_ELEMENT === BYTES_PER_ELEMENT && + typeof value._length === 'number' && // eslint-disable-line no-underscore-dangle + + // NOTE: we don't perform a more rigorous test here for a typed array for performance reasons, as robustly checking for a typed array instance could require walking the prototype tree and performing relatively expensive constructor checks... + typeof value._buffer === 'object' // eslint-disable-line no-underscore-dangle + ) + ); +} + +/** +* Returns a boolean indicating if a value is a 64-bit signed integer typed array constructor. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a 64-bit signed integer typed array constructor +*/ +function isInt64ArrayConstructor( value ) { + return ( value === Int64Array ); +} + +/** +* Retrieves a 64-bit signed integer from a 32-bit unsigned integer array buffer. +* +* @private +* @param {Uint32Array} buf - array buffer +* @param {NonNegativeInteger} idx - element index +* @returns {Int64} 64-bit signed integer +*/ +function getInt64( buf, idx ) { + idx *= 2; + return Int64.of( buf[ idx+indices.HIGH ], buf[ idx+indices.LOW ] ); +} + + +// MAIN // + +/** +* 64-bit signed integer array constructor. +* +* @constructor +* @param {(NonNegativeInteger|Collection|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, buffer, or iterable +* @param {NonNegativeInteger} [byteOffset=0] - byte offset +* @param {NonNegativeInteger} [length] - view length +* @throws {RangeError} ArrayBuffer byte length must be a multiple of `8` +* @throws {TypeError} if provided only a single argument, must provide a valid argument +* @throws {TypeError} byte offset must be a nonnegative integer +* @throws {RangeError} byte offset must be a multiple of `8` +* @throws {TypeError} view length must be a positive multiple of `8` +* @throws {RangeError} must provide sufficient memory to accommodate byte offset and view length requirements +* @throws {TypeError} an array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer +* @throws {TypeError} an iterator must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer +* @returns {Int64Array} 64-bit signed integer array +* +* @example +* var arr = new Int64Array(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var arr = new Int64Array( 2 ); +* // returns [ 0n, 0n ] +* +* var len = arr.length; +* // returns 2 +* +* @example +* var arr = new Int64Array( [ 1, 2 ] ); +* // returns [ 1n, 2n ] +* +* var len = arr.length; +* // returns 2 +* +* @example +* var arr = new Int64Array( [ -1, -2 ] ); +* // returns [ -1n, -2n ] +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Int64Array( buf ); +* // returns [ 0n, 0n, 0n, 0n ] +* +* var len = arr.length; +* // returns 4 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Int64Array( buf, 16 ); +* // returns [ 0n, 0n ] +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 64 ); +* var arr = new Int64Array( buf, 16, 2 ); +* // returns [ 0n, 0n ] +* +* var len = arr.length; +* // returns 2 +*/ +function Int64Array() { + var byteOffset; + var nargs; + var buf; + var len; + var tmp; + var arg; + var i; + + nargs = arguments.length; + if ( !(this instanceof Int64Array) ) { + if ( nargs === 0 ) { + return new Int64Array(); + } + if ( nargs === 1 ) { + return new Int64Array( arguments[0] ); + } + if ( nargs === 2 ) { + return new Int64Array( arguments[0], arguments[1] ); + } + return new Int64Array( arguments[0], arguments[1], arguments[2] ); + } + // Create the underlying data buffer... + if ( nargs === 0 ) { + buf = new Uint32Array( 0 ); // backward-compatibility + } else if ( nargs === 1 ) { + arg = arguments[ 0 ]; + if ( isNonNegativeInteger( arg ) ) { + buf = new Uint32Array( arg*2 ); + } else if ( isCollection( arg ) ) { + len = arg.length; + if ( isInt64Array( arg ) ) { + // Source is already arranged as high/low words, so just copy buffer to buffer: + buf = new Uint32Array( arg._buffer ); // eslint-disable-line no-underscore-dangle + } else { + // Assume that every element represents a single 64-bit signed integer: + buf = fromArray( new Uint32Array( len*2 ), arg ); + if ( buf instanceof Error ) { + throw buf; + } + } + } else if ( isArrayBuffer( arg ) ) { + if ( !isInteger( arg.byteLength/BYTES_PER_ELEMENT ) ) { + throw new RangeError( format( 'invalid argument. ArrayBuffer byte length must be a multiple of %u. Byte length: `%u`.', BYTES_PER_ELEMENT, arg.byteLength ) ); + } + buf = new Uint32Array( arg ); + } else if ( isObject( arg ) ) { + buf = arg; + if ( HAS_ITERATOR_SYMBOL === false ) { + throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `%s`.', buf ) ); + } + if ( !isFunction( buf[ ITERATOR_SYMBOL ] ) ) { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) ); + } + buf = buf[ ITERATOR_SYMBOL ](); + if ( !isFunction( buf.next ) ) { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) ); + } + buf = fromIterator( buf ); + if ( buf instanceof Error ) { + throw buf; + } + len = buf.length; + tmp = new Uint32Array( len ); + for ( i = 0; i < len; i += 2 ) { + tmp[ i+indices.HIGH ] = buf[ i ]; + tmp[ i+indices.LOW ] = buf[ i+1 ]; + } + buf = tmp; + } else { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + } + } else { + buf = arguments[ 0 ]; + if ( !isArrayBuffer( buf ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', buf ) ); + } + byteOffset = arguments[ 1 ]; + if ( !isNonNegativeInteger( byteOffset ) ) { + throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', byteOffset ) ); + } + if ( !isInteger( byteOffset/BYTES_PER_ELEMENT ) ) { + throw new RangeError( format( 'invalid argument. Byte offset must be a multiple of %u. Value: `%u`.', BYTES_PER_ELEMENT, byteOffset ) ); + } + if ( nargs === 2 ) { + len = buf.byteLength - byteOffset; + if ( !isInteger( len/BYTES_PER_ELEMENT ) ) { + throw new RangeError( format( 'invalid arguments. ArrayBuffer view byte length must be a multiple of %u. View byte length: `%u`.', BYTES_PER_ELEMENT, len ) ); + } + buf = new Uint32Array( buf, byteOffset ); + } else { + len = arguments[ 2 ]; + if ( !isNonNegativeInteger( len ) ) { + throw new TypeError( format( 'invalid argument. Length must be a nonnegative integer. Value: `%s`.', len ) ); + } + if ( (len*BYTES_PER_ELEMENT) > (buf.byteLength-byteOffset) ) { + throw new RangeError( format( 'invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity: `%u`.', len*BYTES_PER_ELEMENT ) ); + } + buf = new Uint32Array( buf, byteOffset, len*2 ); + } + } + setReadOnly( this, '_buffer', buf ); + setReadOnly( this, '_length', buf.length/2 ); + + return this; +} + +/** +* Size (in bytes) of each array element. +* +* @name BYTES_PER_ELEMENT +* @memberof Int64Array +* @readonly +* @type {PositiveInteger} +* @default 8 +* +* @example +* var nbytes = Int64Array.BYTES_PER_ELEMENT; +* // returns 8 +*/ +setReadOnly( Int64Array, 'BYTES_PER_ELEMENT', BYTES_PER_ELEMENT ); + +/** +* Constructor name. +* +* @name name +* @memberof Int64Array +* @readonly +* @type {string} +* @default 'Int64Array' +* +* @example +* var name = Int64Array.name; +* // returns 'Int64Array' +*/ +setReadOnly( Int64Array, 'name', 'Int64Array' ); + +/** +* Creates a new 64-bit signed integer array from an array-like object or an iterable. +* +* @name from +* @memberof Int64Array +* @type {Function} +* @param {(Collection|Object)} src - array-like object or iterable +* @param {Function} [clbk] - callback to invoke for each source element +* @param {*} [thisArg] - context +* @throws {TypeError} `this` context must be a constructor +* @throws {TypeError} `this` must be a 64-bit signed integer array +* @throws {TypeError} first argument must be an array-like object or an iterable +* @throws {TypeError} second argument must be a function +* @throws {TypeError} an array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer +* @throws {TypeError} an iterator must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer +* @throws {TypeError} when provided an iterator, a callback must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer +* @returns {Int64Array} 64-bit signed integer array +* +* @example +* var arr = Int64Array.from( [ 1, 2, 3 ] ); +* // returns [ 1n, 2n, 3n ] +* +* var len = arr.length; +* // returns 3 +* +* @example +* var Int64 = require( '@stdlib/number/int64/ctor' ); +* +* var arr = Int64Array.from( [ new Int64( 1 ) ] ); +* // returns [ 1n ] +* +* var len = arr.length; +* // returns 1 +* +* @example +* var Int64 = require( '@stdlib/number/int64/ctor' ); +* var identity = require( '@stdlib/number/int64/base/identity' ); +* +* function clbk( v ) { +* return identity( v ); +* } +* +* var arr = Int64Array.from( [ new Int64( 1 ) ], clbk ); +* // returns [ 1n ] +* +* var len = arr.length; +* // returns 1 +* +* @example +* var arr = Int64Array.from( [ -1, -2, -3 ] ); +* // returns [ -1n, -2n, -3n ] +* +* var len = arr.length; +* // returns 3 +*/ +setReadOnly( Int64Array, 'from', function from( src ) { + var thisArg; + var nargs; + var words; + var clbk; + var out; + var buf; + var tmp; + var get; + var len; + var v; + var i; + var j; + if ( !isFunction( this ) ) { + throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + } + if ( !isInt64ArrayConstructor( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit signed integer array.' ); + } + nargs = arguments.length; + if ( nargs > 1 ) { + clbk = arguments[ 1 ]; + if ( !isFunction( clbk ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) ); + } + if ( nargs > 2 ) { + thisArg = arguments[ 2 ]; + } + } + if ( isCollection( src ) ) { + if ( clbk ) { + len = src.length; + if ( src.get && src.set ) { + get = accessorGetter( 'default' ); + } else { + get = getter( 'default' ); + } + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + + words = [ 0, 0 ]; + j = 0; + for ( i = 0; i < len; i++ ) { + v = clbk.call( thisArg, get( src, i ), i ); + if ( !isInt64( v ) ) { + try { + v = new Int64( v ); + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new TypeError( format( 'invalid argument. A callback must return either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer. Value: `%s`.', v ) ); + } + } + toWords( v, words, 1, 0 ); + buf[ j+indices.HIGH ] = words[ 0 ]; + buf[ j+indices.LOW ] = words[ 1 ]; + j += 2; // stride + } + return out; + } + return new this( src ); + } + if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len + buf = src[ ITERATOR_SYMBOL ](); + if ( !isFunction( buf.next ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) ); + } + if ( clbk ) { + tmp = fromIteratorMap( buf, clbk, thisArg ); + } else { + tmp = fromIterator( buf ); + } + if ( tmp instanceof Error ) { + throw tmp; + } + len = tmp.length / 2; + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < tmp.length; i += 2 ) { + buf[ i+indices.HIGH ] = tmp[ i ]; + buf[ i+indices.LOW ] = tmp[ i+1 ]; + } + return out; + } + throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) ); +}); + +/** +* Creates a new 64-bit signed integer array from a variable number of arguments. +* +* @name of +* @memberof Int64Array +* @type {Function} +* @param {...*} element - array elements +* @throws {TypeError} `this` context must be a constructor +* @throws {TypeError} `this` must be a 64-bit signed integer array +* @returns {Int64Array} 64-bit signed integer array +* +* @example +* var arr = Int64Array.of( 1, 2, 3, 4 ); +* // returns [ 1n, 2n, 3n, 4n ] +* +* var len = arr.length; +* // returns 4 +* +* @example +* var arr = Int64Array.of( -1, -2, -3, -4 ); +* // returns [ -1n, -2n, -3n, -4n ] +* +* var len = arr.length; +* // returns 4 +*/ +setReadOnly( Int64Array, 'of', function of() { + var args; + var i; + if ( !isFunction( this ) ) { + throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + } + if ( !isInt64ArrayConstructor( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit signed integer array.' ); + } + args = []; + for ( i = 0; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return new this( args ); +}); + +/** +* Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer indices. +* +* @name at +* @memberof Int64Array.prototype +* @type {Function} +* @param {integer} idx - element index +* @throws {TypeError} `this` must be a 64-bit signed integer array +* @throws {TypeError} must provide an integer +* @returns {(Int64|void)} array element +* +* @example +* var arr = new Int64Array( 10 ); +* +* var u = arr.at( 0 ); +* // returns [ 0n ] +* +* arr.set( 1, 0 ); +* arr.set( 2, 1 ); +* arr.set( 9, 9 ); +* +* u = arr.at( 0 ); +* // returns [ 1n ] +* +* u = arr.at( -1 ); +* // returns [ 9n ] +* +* u = arr.at( 100 ); +* // returns undefined +* +* u = arr.at( -100 ); +* // returns undefined +*/ +setReadOnly( Int64Array.prototype, 'at', function at( idx ) { + if ( !isInt64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit signed integer array.' ); + } + if ( !isInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) ); + } + if ( idx < 0 ) { + idx += this._length; + } + if ( idx < 0 || idx >= this._length ) { + return; + } + return getInt64( this._buffer, idx ); +}); + +/** +* Pointer to the underlying data buffer. +* +* @name buffer +* @memberof Int64Array.prototype +* @readonly +* @type {ArrayBuffer} +* +* @example +* var arr = new Int64Array( 10 ); +* +* var buf = arr.buffer; +* // returns +*/ +setReadOnlyAccessor( Int64Array.prototype, 'buffer', function get() { + return this._buffer.buffer; +}); + +/** +* Size (in bytes) of the array. +* +* @name byteLength +* @memberof Int64Array.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new Int64Array( 10 ); +* +* var byteLength = arr.byteLength; +* // returns 80 +*/ +setReadOnlyAccessor( Int64Array.prototype, 'byteLength', function get() { + return this._buffer.byteLength; +}); + +/** +* Offset (in bytes) of the array from the start of its underlying `ArrayBuffer`. +* +* @name byteOffset +* @memberof Int64Array.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new Int64Array( 10 ); +* +* var byteOffset = arr.byteOffset; +* // returns 0 +*/ +setReadOnlyAccessor( Int64Array.prototype, 'byteOffset', function get() { + return this._buffer.byteOffset; +}); + +/** +* Size (in bytes) of each array element. +* +* @name BYTES_PER_ELEMENT +* @memberof Int64Array.prototype +* @readonly +* @type {PositiveInteger} +* @default 8 +* +* @example +* var arr = new Int64Array( 10 ); +* +* var nbytes = arr.BYTES_PER_ELEMENT; +* // returns 8 +*/ +setReadOnly( Int64Array.prototype, 'BYTES_PER_ELEMENT', Int64Array.BYTES_PER_ELEMENT ); + +/** +* Returns an iterator for iterating over array key-value pairs. +* +* @name entries +* @memberof Int64Array.prototype +* @type {Function} +* @throws {TypeError} `this` must be a 64-bit signed integer array +* @returns {Iterator} iterator +* +* @example +* var Int64 = require( '@stdlib/number/int64/ctor' ); +* +* var arr = [ +* new Int64( 1 ), +* new Int64( 2 ), +* new Int64( 3 ) +* ]; +* arr = new Int64Array( arr ); +* +* // Create an iterator: +* var it = arr.entries(); +* +* // Iterate over the key-value pairs... +* var v = it.next().value; +* // returns [ 0, [ 1n ] ] +* +* v = it.next().value; +* // returns [ 1, [ 2n ] ] +* +* v = it.next().value; +* // returns [ 2, [ 3n ] ] +* +* var bool = it.next().done; +* // returns true +*/ +setReadOnly( Int64Array.prototype, 'entries', function entries() { + var buffer; + var self; + var iter; + var len; + var FLG; + var i; + if ( !isInt64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit signed integer array.' ); + } + self = this; + buffer = this._buffer; + len = this._length; + + // Initialize an iteration index: + i = -1; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + if ( ITERATOR_SYMBOL ) { + setReadOnly( iter, ITERATOR_SYMBOL, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + i += 1; + if ( FLG || i >= len ) { + return { + 'done': true + }; + } + return { + 'value': [ i, getInt64( buffer, i ) ], + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return self.entries(); + } +}); + +/** +* Returns an array element. +* +* @name get +* @memberof Int64Array.prototype +* @type {Function} +* @param {NonNegativeInteger} idx - element index +* @throws {TypeError} `this` must be a 64-bit signed integer array +* @throws {TypeError} must provide a nonnegative integer +* @returns {(Int64|void)} array element +* +* @example +* var arr = new Int64Array( 10 ); +* +* var z = arr.get( 0 ); +* // returns [ 0n ] +* +* arr.set( [ 1 ], 0 ); +* +* z = arr.get( 0 ); +* // returns [ 1n ] +* +* z = arr.get( 100 ); +* // returns undefined +*/ +setReadOnly( Int64Array.prototype, 'get', function get( idx ) { + if ( !isInt64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit signed integer array.' ); + } + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', idx ) ); + } + if ( idx >= this._length ) { + return; + } + return getInt64( this._buffer, idx ); +}); + +/** +* Number of array elements. +* +* @name length +* @memberof Int64Array.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new Int64Array( 10 ); +* +* var len = arr.length; +* // returns 10 +*/ +setReadOnlyAccessor( Int64Array.prototype, 'length', function get() { + return this._length; +}); + +/** +* Sets an array element. +* +* ## Notes +* +* - When provided a typed array, we must check whether the source array shares the same buffer as the target array and whether the underlying memory overlaps. In particular, we are concerned with the following scenario: +* +* ```text +* buf: --------------------- +* src: --------------------- +* ``` +* +* In the above, as we copy values from `src`, we will overwrite values in the `src` view, resulting in duplicated values copied into the end of `buf`, which is not intended. Hence, to avoid overwriting source values, we must **copy** source values to a temporary array. +* +* In the other overlapping scenario, +* +* ```text +* buf: --------------------- +* src: --------------------- +* ``` +* +* by the time we begin copying into the overlapping region, we are copying from the end of `src`, a non-overlapping region, which means we don't run the risk of copying copied values, rather than the original `src` values as intended. +* +* @name set +* @memberof Int64Array.prototype +* @type {Function} +* @param {(Collection|Int64Array|Int64|bigint|number)} value - value(s) +* @param {NonNegativeInteger} [i=0] - element index at which to start writing values +* @throws {TypeError} `this` must be a 64-bit signed integer array +* @throws {TypeError} index argument must be a nonnegative integer +* @throws {RangeError} index argument is out-of-bounds +* @throws {RangeError} target array lacks sufficient storage to accommodate source values +* @throws {TypeError} an array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer +* @throws {TypeError} first argument must be either a 64-bit signed integer, a value which can be converted to a 64-bit signed integer, a 64-bit signed integer array, or an array-like object containing 64-bit signed integers or values which can be converted to a 64-bit signed integers +* @returns {void} +* +* @example +* var arr = new Int64Array( 10 ); +* +* var z = arr.get( 0 ); +* // returns [ 0n ] +* +* arr.set( 1n, 0 ); +* +* z = arr.get( 0 ); +* // returns [ 1n ] +* +* @example +* var arr = new Int64Array( 10 ); +* +* arr.set( -1, 0 ); +* +* var z = arr.get( 0 ); +* // returns [ -1n ] +* +* arr.set( -2n, 1 ); +* +* z = arr.get( 1 ); +* // returns [ -2n ] +* +* arr.set( [ -3, -4 ], 2 ); +* +* z = arr.get( 3 ); +* // returns [ -4n ] +*/ +setReadOnly( Int64Array.prototype, 'set', function set( value ) { + /* eslint-disable no-underscore-dangle */ + var words; + var sbuf; + var idx; + var buf; + var tmp; + var N; + var v; + var i; + var j; + if ( !isInt64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit signed integer array.' ); + } + buf = this._buffer; + if ( arguments.length > 1 ) { + idx = arguments[ 1 ]; + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); + } + } else { + idx = 0; + } + words = [ 0, 0 ]; + if ( isInt64( value ) ) { + if ( idx >= this._length ) { + throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); + } + idx *= 2; + toWords( value, words, 1, 0 ); + buf[ idx+indices.HIGH ] = words[ 0 ]; + buf[ idx+indices.LOW ] = words[ 1 ]; + return; + } + if ( isIntegerPrimitive( value ) || ( isBigInt( value ) && isIntegerPrimitive( Number( value ) ) ) ) { + if ( idx >= this._length ) { + throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); + } + value = new Int64( value ); + idx *= 2; + toWords( value, words, 1, 0 ); + buf[ idx+indices.HIGH ] = words[ 0 ]; + buf[ idx+indices.LOW ] = words[ 1 ]; + return; + } + if ( isInt64Array( value ) ) { + N = value._length; + if ( idx+N > this._length ) { + throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + } + sbuf = value._buffer; + + // Check for overlapping memory... + j = buf.byteOffset + (idx*BYTES_PER_ELEMENT); + if ( + sbuf.buffer === buf.buffer && + ( + sbuf.byteOffset < j && + sbuf.byteOffset+sbuf.byteLength > j + ) + ) { + // We need to copy source values... + tmp = copy( sbuf ); + sbuf = tmp; + } + idx *= 2; + j = 0; + for ( i = 0; i < N; i++ ) { + buf[ idx+indices.HIGH ] = sbuf[ j+indices.HIGH ]; + buf[ idx+indices.LOW ] = sbuf[ j+indices.LOW ]; + idx += 2; // stride + j += 2; // stride + } + return; + } + if ( isCollection( value ) ) { + N = value.length; + if ( idx+N > this._length ) { + throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + } + sbuf = value; + + // Check for overlapping memory... + j = buf.byteOffset + (idx*BYTES_PER_ELEMENT); + if ( + sbuf.buffer === buf.buffer && + ( + sbuf.byteOffset < j && + sbuf.byteOffset+sbuf.byteLength > j + ) + ) { + // We need to copy source values... + tmp = copy( sbuf ); + sbuf = tmp; + } + idx *= 2; + for ( i = 0; i < N; i++ ) { + v = sbuf[ i ]; + if ( !isInt64( v ) ) { + try { + v = new Int64( v ); + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new TypeError( format( 'invalid argument. An array element must be either a 64-bit signed integer or a value which can be converted to a 64-bit signed integer. Value: `%s`.', v ) ); + } + } + toWords( v, words, 1, 0 ); + buf[ idx+indices.HIGH ] = words[ 0 ]; + buf[ idx+indices.LOW ] = words[ 1 ]; + idx += 2; // stride + } + return; + } + throw new TypeError( format( 'invalid argument. First argument must be either a 64-bit signed integer, a value which can be converted to a 64-bit signed integer, a 64-bit signed integer array, or an array-like object containing 64-bit signed integers or values which can be converted to a 64-bit signed integers. Value: `%s`.', value ) ); + + /* eslint-enable no-underscore-dangle */ +}); + + +// EXPORTS // + +module.exports = Int64Array; diff --git a/lib/node_modules/@stdlib/array/int64/package.json b/lib/node_modules/@stdlib/array/int64/package.json new file mode 100644 index 000000000000..0967922a5125 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/array/int64", + "version": "0.0.0", + "description": "Int64Array.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "data", + "structure", + "array", + "typed", + "typed array", + "typed-array", + "int64array", + "int64", + "int64_t", + "integer", + "int", + "signed", + "long" + ] +} diff --git a/lib/node_modules/@stdlib/array/int64/test/test.at.js b/lib/node_modules/@stdlib/array/int64/test/test.at.js new file mode 100644 index 000000000000..4eb37b79a5a3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/test/test.at.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isEqual = require( '@stdlib/number/int64/base/assert/is-equal' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var Int64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Int64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `at` method for returning an array element', function test( t ) { + t.strictEqual( hasOwnProp( Int64Array.prototype, 'at' ), true, 'has property' ); + t.strictEqual( isFunction( Int64Array.prototype.at ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit signed integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.at.call( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.at( value ); + }; + } +}); + +tape( 'the method returns `undefined` if provided an index which exceeds array dimensions', function test( t ) { + var arr; + var v; + var i; + + arr = new Int64Array( 10 ); + for ( i = -arr.length; i < arr.length; i++ ) { + if ( i < 0 ) { + v = arr.at( i-arr.length ); + t.strictEqual( v, void 0, 'returns expected value for index '+( i - arr.length ) ); + } else { + v = arr.at( arr.length + i ); + t.strictEqual( v, void 0, 'returns expected value for index '+( arr.length + i ) ); + } + } + t.end(); +}); + +tape( 'the method returns an array element', function test( t ) { + var arr; + var v; + var i; + var j; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( new Int64( i * pow( -1, i ) ) ); + } + arr = new Int64Array( arr ); + + for ( i = -arr.length; i < arr.length; i++ ) { + v = arr.at( i ); + if ( i < 0 ) { + j = arr.length + i; + } else { + j = i; + } + t.strictEqual( isEqual( v, new Int64( j * pow( -1, j ) ) ), true, 'returns expected value for index '+i ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/int64/test/test.entries.js b/lib/node_modules/@stdlib/array/int64/test/test.entries.js new file mode 100644 index 000000000000..aaec3695710e --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/test/test.entries.js @@ -0,0 +1,264 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var proxyquire = require( 'proxyquire' ); +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isInt64 = require( '@stdlib/assert/is-int64' ); +var isEqual = require( '@stdlib/number/int64/base/assert/is-equal' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var Int64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Int64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `entries` method for returning an iterator for iterating over array key-value pairs', function test( t ) { + t.strictEqual( hasOwnProp( Int64Array.prototype, 'entries' ), true, 'has property' ); + t.strictEqual( isFunction( Int64Array.prototype.entries ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit signed integer instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.entries.call( value ); + }; + } +}); + +tape( 'the method returns an iterator protocol-compliant object', function test( t ) { + var buf; + var arr; + var it; + var v; + var i; + + buf = [ + new Int64( 1 ), + new Int64( -2 ), + new Int64( 3 ), + new Int64( -4 ) + ]; + arr = new Int64Array( buf ); + + it = arr.entries(); + t.strictEqual( it.next.length, 0, 'has zero arity' ); + + for ( i = 0; i < arr.length; i++ ) { + v = it.next(); + t.strictEqual( isArray( v.value ), true, 'returns expected value' ); + t.strictEqual( v.value[ 0 ], i, 'returns an index' ); + t.strictEqual( isInt64( v.value[ 1 ] ), true, 'returns a 64-bit signed integer' ); + t.strictEqual( isEqual( v.value[ 1 ], buf[ i ] ), true, 'returns expected value' ); + t.strictEqual( typeof v.done, 'boolean', 'returns expected value' ); + } + t.end(); +}); + +tape( 'the method returns an iterator which has a `return` method for closing an iterator (no argument)', function test( t ) { + var buf; + var arr; + var it; + var v; + + buf = [ + new Int64( 1 ), + new Int64( -2 ), + new Int64( 3 ), + new Int64( -4 ) + ]; + arr = new Int64Array( buf ); + + it = arr.entries(); + + v = it.next(); + t.strictEqual( isEqual( v.value[ 1 ], buf[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( isEqual( v.value[ 1 ], buf[ 1 ] ), true, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.return(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns an iterator which has a `return` method for closing an iterator (argument)', function test( t ) { + var buf; + var arr; + var it; + var v; + + buf = [ + new Int64( 1 ), + new Int64( -2 ), + new Int64( 3 ), + new Int64( -4 ) + ]; + arr = new Int64Array( buf ); + + it = arr.entries(); + + v = it.next(); + t.strictEqual( isEqual( v.value[ 1 ], buf[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( isEqual( v.value[ 1 ], buf[ 1 ] ), true, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.return( 'finished' ); + t.strictEqual( v.value, 'finished', 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator`, the method returns an iterable', function test( t ) { + var Int64Array; + var arr; + var buf; + var it1; + var it2; + var v1; + var v2; + var i; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + buf = [ + new Int64( 1 ), + new Int64( -2 ), + new Int64( 3 ), + new Int64( -4 ) + ]; + arr = new Int64Array( buf ); + + it1 = arr.entries(); + t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.strictEqual( typeof it2, 'object', 'returns expected value' ); + t.strictEqual( typeof it2.next, 'function', 'has `next` method' ); + t.strictEqual( typeof it2.return, 'function', 'has `return` method' ); + + for ( i = 0; i < arr.length; i++ ) { + v1 = it1.next().value; + v2 = it2.next().value; + t.strictEqual( isEqual( v1[ 0 ], v2[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isEqual( v1[ 1 ], v2[ 1 ] ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if an environment does not support `Symbol.iterator`, the method does not return an "iterable"', function test( t ) { + var Int64Array; + var arr; + var buf; + var it; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + buf = [ + new Int64( 1 ), + new Int64( -2 ), + new Int64( 3 ), + new Int64( -4 ) + ]; + arr = new Int64Array( buf ); + + it = arr.entries(); + t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/int64/test/test.from.js b/lib/node_modules/@stdlib/array/int64/test/test.from.js new file mode 100644 index 000000000000..1bab7be14739 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/test/test.from.js @@ -0,0 +1,912 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Int64Array = require( './../lib' ); + + +// VARIABLES // + +var HAS_BIGINTS = hasBigIntSupport(); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Int64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a `from` method for creating a 64-bit signed integer array from an array-like object or iterable', function test( t ) { + var arr; + + t.strictEqual( hasOwnProp( Int64Array, 'from' ), true, 'has property' ); + t.strictEqual( isFunction( Int64Array.from ), true, 'has method' ); + + arr = Int64Array.from( [] ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a constructor', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.from.call( value, [] ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a signed integer array constructor', function test( t ) { + var values; + var i; + + values = [ + Int64, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.from.call( value, [] ); + }; + } +}); + +tape( 'the method throws an error if not provided an iterable or array-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.from( value ); + }; + } +}); + +tape( 'the method throws an error if not provided an iterable or array-like object (callback)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.from( value, clbk ); + }; + } + + function clbk() { + return new Int64( 1 ); + } +}); + +tape( 'the method throws an error if not provided an iterable or array-like object (callback, thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.from( value, clbk, {} ); + }; + } + + function clbk() { + return new Int64( 1 ); + } +}); + +tape( 'the method throws an error if provided a second argument which is not a function', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.from( [], value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not a function (thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.from( [], value, {} ); + }; + } +}); + +tape( 'the method returns a 64-bit signed integer array', function test( t ) { + var arr; + var v; + var u; + + // Generic array: + arr = Int64Array.from( [] ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Int64Array.from( [ 1, -2, 3, -4 ] ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Generic array containing 64-bit signed integers: + arr = Int64Array.from( [ new Int64( 1 ), new Int64( -2 ) ] ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + u = new Int64( 1 ); + arr = Int64Array.from( [ u, 1.0 ] ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Typed array: + arr = Int64Array.from( new Float64Array( 0 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Int64Array.from( new Float64Array( [ 1.0, -1.0 ] ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Unsigned integer typed array (widened to signed): + arr = Int64Array.from( new Uint32Array( 0 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Int64Array.from( new Uint32Array( [ 1, -1 ] ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + arr = Int64Array.from( new Int64Array( 0 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Int64Array.from( new Int64Array( [ 1, -1 ] ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns a 64-bit signed integer array (iterable)', function test( t ) { + var Int64Array; + var iter1; + var iter2; + var iter3; + var arr; + var v; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + iter1 = { + 'next': next1, + 'i': 0, + 'N': 4 + }; + + arr = Int64Array.from( createIterable( iter1 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter1.N, 'returns expected value' ); + + iter2 = { + 'next': next2, + 'i': 0, + 'N': 4 + }; + + arr = Int64Array.from( createIterable( iter2 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter2.N, 'returns expected value' ); + + iter2 = { + 'next': next2, + 'i': 0, + 'N': 4 + }; + + arr = Int64Array.from( createIterable( iter2 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter2.N, 'returns expected value' ); + + if ( HAS_BIGINTS ) { + iter3 = { + 'next': next3, + 'i': 0, + 'N': 4 + }; + + arr = Int64Array.from( createIterable( iter3 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter3.N, 'returns expected value' ); + } + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable( iterator ) { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return iterator; + } + } + + function next1() { + iter1.i += 1; + if ( iter1.i <= iter1.N ) { + return { + 'value': new Int64( 1 ) + }; + } + return { + 'done': true + }; + } + + function next2() { + iter2.i += 1; + if ( iter2.i <= iter2.N ) { + return { + 'value': 1 + }; + } + return { + 'done': true + }; + } + + function next3() { + iter3.i += 1; + if ( iter3.i <= iter3.N ) { + return { + 'value': BigInt( 1 ) + }; + } + return { + 'done': true + }; + } +}); + +tape( 'the method supports providing a "map" function which is invoked for each source element', function test( t ) { + var arr; + var v; + + // Generic array: + arr = Int64Array.from( [], clbk1 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Int64Array.from( [ 1, -2, 3, -4 ], clbk1 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Generic array containing 64-bit signed integers: + arr = Int64Array.from( [ new Int64( 1 ) ], clbk2 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + // Typed array: + arr = Int64Array.from( new Float64Array( 0 ), clbk1 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Int64Array.from( new Float64Array( [ 1.0, -1.0 ] ), clbk1 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // 64-bit signed integer typed array: + arr = Int64Array.from( new Int64Array( 0 ), clbk2 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Int64Array.from( new Int64Array( [ 1, -1 ] ), clbk2 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v; + } + + function clbk2() { + return new Int64( 1 ); + } +}); + +tape( 'the method supports providing a "map" function which is invoked for each iterated value', function test( t ) { + var Int64Array; + var iter1; + var iter2; + var arr; + var v; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + iter1 = { + 'next': next1, + 'i': 0, + 'N': 4 + }; + arr = Int64Array.from( createIterable( iter1 ), clbk ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter1.N, 'returns expected value' ); + + iter2 = { + 'next': next2, + 'i': 0, + 'N': 4 + }; + arr = Int64Array.from( createIterable( iter2 ), clbk ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter2.N, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable( iterator ) { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return iterator; + } + } + + function next1() { + iter1.i += 1; + if ( iter1.i <= iter1.N ) { + return { + 'value': new Int64( 1 ) + }; + } + return { + 'done': true + }; + } + + function next2() { + iter2.i += 1; + if ( iter2.i <= iter2.N ) { + return { + 'value': 1 + }; + } + return { + 'done': true + }; + } + + function clbk() { + return 1; + } +}); + +tape( 'the method supports providing a `this` context for a provided map function', function test( t ) { + var arr; + var ctx; + + ctx = { + 'count': 0 + }; + arr = Int64Array.from( [ 1, -2, 3, -4 ], clbk1, ctx ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + ctx = { + 'count': 0 + }; + arr = [ new Int64( 1 ), new Int64( 2 ) ]; + arr = Int64Array.from( arr, clbk2, ctx ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v; + } + + function clbk2( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v; + } +}); + +tape( 'the method supports providing a `this` context for a provided map function (iterable)', function test( t ) { + var Int64Array; + var iter; + var ctx; + var arr; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + iter = { + 'next': next, + 'i': 0, + 'N': 4 + }; + ctx = { + 'count': 0 + }; + + arr = Int64Array.from( createIterable( iter ), clbk, ctx ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable( iterator ) { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return iterator; + } + } + + function next() { + iter.i += 1; + if ( iter.i <= iter.N ) { + return { + 'value': new Int64( 1 ) + }; + } + return { + 'done': true + }; + } + + function clbk( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v; + } +}); + +tape( 'the method throws an error if provided a non-iterable object (non-ES2015+)', function test( t ) { + var Int64Array; + var values; + var i; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport + }); + + values = [ + {}, + { + '0': 1, + '1': 2, + '2': 3 + } + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.from( value ); + }; + } + + function hasSupport() { + return false; + } +}); + +tape( 'the method throws an error if provided a non-iterable object (ES2015+)', function test( t ) { + var Int64Array; + var values; + var i; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + values = [ + {}, + { + '0': 1, + '1': 2, + '2': 3 + }, + { + '__SYMBOL_ITERATOR__': null + }, + { + '__SYMBOL_ITERATOR__': 'beep' + }, + { + '__SYMBOL_ITERATOR__': nonIterable1 + }, + { + '__SYMBOL_ITERATOR__': nonIterable2 + } + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.from( value ); + }; + } + + function hasSupport() { + return true; + } + + function nonIterable1() { + return null; + } + + function nonIterable2() { + return {}; + } +}); + +tape( 'the method throws an error if provided an iterable object which returns values which cannot be converted to a 64-bit signed integers', function test( t ) { + var Int64Array; + var values; + var i; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + values = [ + { + '__SYMBOL_ITERATOR__': createIterable( next1 ) + }, + { + '__SYMBOL_ITERATOR__': createIterable( next2 ) + } + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.from( value ); + }; + } + + function hasSupport() { + return true; + } + + function createIterable( next ) { + return iterable; + + function iterable() { + return { + 'next': next + }; + } + } + + function next1() { + return { + 'value': 1.5 + }; + } + + function next2() { + return { + 'value': 'hello' + }; + } +}); + +tape( 'the method throws an error if provided a 64-bit signed integer source array and a "map" function which does not return 64-bit signed integer', function test( t ) { + var values; + var clbks; + var i; + + values = [ + [ new Int64( 1 ) ], + [ new Int64( 1 ), new Int64( 1 ) ] + ]; + clbks = [ + clbk1, + clbk2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i], clbks[i] ), TypeError, 'throws an error when provided callback '+i ); + } + t.end(); + + function badValue( value, clbk ) { + return function badValue() { + return Int64Array.from( value, clbk ); + }; + } + + function clbk1() { + return NaN; + } + + function clbk2() { + return {}; + } +}); + +tape( 'the method throws an error if provided a "map" function which returns values which cannot be converted to a 64-bit signed integers (iterable)', function test( t ) { + var Int64Array; + var values; + var clbks; + var i; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + values = [ + { + '__SYMBOL_ITERATOR__': createIterable( next1 ) + }, + { + '__SYMBOL_ITERATOR__': createIterable( next2 ) + } + ]; + clbks = [ + clbk1, + clbk2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i], clbks[i] ), TypeError, 'throws an error when provided callback '+i ); + } + t.end(); + + function badValue( value, clbk ) { + return function badValue() { + return Int64Array.from( value, clbk ); + }; + } + + function hasSupport() { + return true; + } + + function createIterable( next ) { + return iterable; + + function iterable() { + return { + 'next': next + }; + } + } + + function next1() { + return { + 'value': 1 + }; + } + + function clbk1() { + return {}; + } + + function next2() { + return { + 'value': new Int64( 1 ) + }; + } + + function clbk2() { + return '1.0'; + } +}); diff --git a/lib/node_modules/@stdlib/array/int64/test/test.get.js b/lib/node_modules/@stdlib/array/int64/test/test.get.js new file mode 100644 index 000000000000..659dd0804ea5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/test/test.get.js @@ -0,0 +1,139 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isEqual = require( '@stdlib/number/int64/base/assert/is-equal' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var Int64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Int64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `get` method for returning an array element', function test( t ) { + t.strictEqual( hasOwnProp( Int64Array.prototype, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( Int64Array.prototype.get ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit signed integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.get.call( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is not a nonnegative integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 10 ); + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.get( value ); + }; + } +}); + +tape( 'the method returns `undefined` if provided an index which exceeds array dimensions', function test( t ) { + var arr; + var v; + var i; + + arr = new Int64Array( 10 ); + for ( i = 0; i < arr.length; i++ ) { + v = arr.get( arr.length+i ); + t.strictEqual( v, void 0, 'returns expected value for index '+(arr.length+i) ); + } + t.end(); +}); + +tape( 'the method returns an array element', function test( t ) { + var expected; + var arr; + var v; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( new Int64( i * pow( -1, i ) ) ); + } + arr = new Int64Array( arr ); + + for ( i = 0; i < arr.length; i++ ) { + v = arr.get( i ); + expected = new Int64( i * pow( -1, i ) ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+i ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/int64/test/test.js b/lib/node_modules/@stdlib/array/int64/test/test.js new file mode 100644 index 000000000000..193f8a40c889 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/test/test.js @@ -0,0 +1,922 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Int64Array = require( './../lib' ); + + +// VARIABLES // + +var HAS_BIGINTS = hasBigIntSupport(); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Int64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var arr = new Int64Array( 0 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor does not require the `new` keyword', function test( t ) { + var ctor; + var arr; + + ctor = Int64Array; + + arr = ctor( 0 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (no argument)', function test( t ) { + var arr = new Int64Array(); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (no argument, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Int64Array; + + arr = ctor(); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (length)', function test( t ) { + var arr = new Int64Array( 10 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (length, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Int64Array; + + arr = ctor( 10 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (array)', function test( t ) { + var arr = new Int64Array( [] ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (array, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Int64Array; + + arr = ctor( [] ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (typed array)', function test( t ) { + var arr = new Int64Array( new Uint32Array( 0 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (typed array, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Int64Array; + + arr = ctor( new Uint32Array( 0 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (signed integer typed array)', function test( t ) { + var arr = new Int64Array( new Int64Array( 0 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (signed integer typed array, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Int64Array; + + arr = ctor( new Int64Array( 0 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (iterable)', function test( t ) { + var Int64Array; + var arr; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + arr = new Int64Array( createIterable() ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable() { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +tape( 'the constructor returns a 64-bit signed integer array (iterable, no new)', function test( t ) { + var ctor; + var arr; + + ctor = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + arr = ctor( createIterable() ); + t.strictEqual( arr instanceof ctor, true, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable() { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +tape( 'the constructor returns a 64-bit signed integer array (ArrayBuffer)', function test( t ) { + var arr = new Int64Array( new ArrayBuffer( 0 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (ArrayBuffer, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Int64Array; + + arr = ctor( new ArrayBuffer( 0 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (ArrayBuffer, byte offset)', function test( t ) { + var arr = new Int64Array( new ArrayBuffer( 16 ), 16 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (ArrayBuffer, byte offset, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Int64Array; + + arr = ctor( new ArrayBuffer( 16 ), 16 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (ArrayBuffer, byte offset, length)', function test( t ) { + var arr = new Int64Array( new ArrayBuffer( 16 ), 16, 0 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 64-bit signed integer array (ArrayBuffer, byte offset, length, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Int64Array; + + arr = ctor( new ArrayBuffer( 16 ), 16, 0 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'attached to the constructor is a property returning the number of bytes per array element', function test( t ) { + t.strictEqual( hasOwnProp( Int64Array, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Int64Array.BYTES_PER_ELEMENT, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the constructor is a property returning the constructor name', function test( t ) { + t.strictEqual( hasOwnProp( Int64Array, 'name' ), true, 'has property' ); + t.strictEqual( Int64Array.name, 'Int64Array', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `BYTES_PER_ELEMENT` property returning the number of bytes per array element', function test( t ) { + var arr; + + t.strictEqual( hasOwnProp( Int64Array.prototype, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Int64Array.prototype.BYTES_PER_ELEMENT, 8, 'returns expected value' ); + + arr = new Int64Array( 0 ); + t.strictEqual( arr.BYTES_PER_ELEMENT, 8, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `buffer` property for returning the underlying memory (i.e., ArrayBuffer)', function test( t ) { + var arr; + var buf; + + arr = new Int64Array( 0 ); + buf = arr.buffer; + t.strictEqual( isArrayBuffer( buf ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `byteLength` property for returning the number of bytes belonging to the array view', function test( t ) { + var arr; + var v; + + arr = new Int64Array( 0 ); + v = arr.byteLength; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Int64Array( new ArrayBuffer( 128 ), 16 ); + v = arr.byteLength; + t.strictEqual( v, 112, 'returns expected value' ); + + arr = new Int64Array( new ArrayBuffer( 128 ), 128 ); + v = arr.byteLength; + t.strictEqual( v, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `byteOffset` property for returning the byte offset pointing to the first array element in the underlying memory', function test( t ) { + var arr; + var v; + + arr = new Int64Array( 0 ); + v = arr.byteOffset; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Int64Array( new ArrayBuffer( 128 ), 64 ); + v = arr.byteOffset; + t.strictEqual( v, 64, 'returns expected value' ); + + arr = new Int64Array( new ArrayBuffer( 128 ), 128 ); + v = arr.byteOffset; + t.strictEqual( v, 128, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `length` property for returning the number of array elements', function test( t ) { + var arr; + var v; + + // No arguments: + arr = new Int64Array(); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + // Explicit array length: + arr = new Int64Array( 0 ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Int64Array( 10 ); + v = arr.length; + t.strictEqual( v, 10, 'returns expected value' ); + + // Generic array: + arr = new Int64Array( [] ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Int64Array( [ 1, -2, 3, -4 ] ); + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Generic array containing `Int64` instances: + arr = new Int64Array( [ new Int64( 1 ) ] ); + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + // Typed array: + arr = new Int64Array( new Uint32Array( 0 ) ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Int64Array( new Uint32Array( [ -1, 1 ] ) ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // 64-bit signed typed array: + arr = new Int64Array( new Int64Array( 0 ) ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Int64Array( new Int64Array( [ 1, -1 ] ) ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // ArrayBuffer: + arr = new Int64Array( new ArrayBuffer( 128 ), 64 ); + v = arr.length; + t.strictEqual( v, 8, 'returns expected value' ); + + arr = new Int64Array( new ArrayBuffer( 128 ), 128 ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Int64Array( new ArrayBuffer( 128 ), 64, 2 ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `length` property for returning the number of array elements (iterable)', function test( t ) { + var Int64Array; + var iter1; + var iter2; + var iter3; + var arr; + var v; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + iter1 = { + 'next': next1, + 'i': 0, + 'N': 4 + }; + + arr = new Int64Array( createIterable( iter1 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter1.N, 'returns expected value' ); + + iter2 = { + 'next': next2, + 'i': 0, + 'N': 4 + }; + + arr = new Int64Array( createIterable( iter2 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter2.N, 'returns expected value' ); + + iter2 = { + 'next': next2, + 'i': 0, + 'N': 4 + }; + + arr = new Int64Array( createIterable( iter2 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter2.N, 'returns expected value' ); + + if ( HAS_BIGINTS ) { + iter3 = { + 'next': next3, + 'i': 0, + 'N': 4 + }; + + arr = new Int64Array( createIterable( iter3 ) ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter3.N, 'returns expected value' ); + } + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable( iterator ) { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return iterator; + } + } + + function next1() { + iter1.i += 1; + if ( iter1.i <= iter1.N ) { + return { + 'value': new Int64( 1 ) + }; + } + return { + 'done': true + }; + } + + function next2() { + iter2.i += 1; + if ( iter2.i <= iter2.N ) { + return { + 'value': 1 + }; + } + return { + 'done': true + }; + } + + function next3() { + iter3.i += 1; + if ( iter3.i <= iter3.N ) { + return { + 'value': BigInt( 1 ) + }; + } + return { + 'done': true + }; + } +}); + +tape( 'the constructor throws an error if provided an ArrayBuffer which is not a multiple of 8', function test( t ) { + var values; + var i; + + values = [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 9, + 21, + 74, + 801 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided an ArrayBuffer having a byte length equal to '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( new ArrayBuffer( value ) ); + }; + } +}); + +tape( 'the constructor throws an error if provided a non-iterable object (non-ES2015+)', function test( t ) { + var Int64Array; + var values; + var i; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport + }); + + values = [ + {}, + { + '0': 1, + '1': 2, + '2': 3 + } + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( value ); + }; + } + + function hasSupport() { + return false; + } +}); + +tape( 'the constructor throws an error if provided a non-iterable object (ES2015+)', function test( t ) { + var Int64Array; + var values; + var i; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + values = [ + {}, + { + '0': 1, + '1': 2, + '2': 3 + }, + { + '__SYMBOL_ITERATOR__': null + }, + { + '__SYMBOL_ITERATOR__': 'beep' + }, + { + '__SYMBOL_ITERATOR__': nonIterable1 + }, + { + '__SYMBOL_ITERATOR__': nonIterable2 + } + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( value ); + }; + } + + function hasSupport() { + return true; + } + + function nonIterable1() { + return null; + } + + function nonIterable2() { + return {}; + } +}); + +tape( 'the constructor throws an error if provided an iterable object which returns values which cannot be converted to a 64-bit signed integers', function test( t ) { + var Int64Array; + var values; + var i; + + Int64Array = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + values = [ + { + '__SYMBOL_ITERATOR__': createIterable( next1 ) + }, + { + '__SYMBOL_ITERATOR__': createIterable( next2 ) + } + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( value ); + }; + } + + function hasSupport() { + return true; + } + + function createIterable( next ) { + return iterable; + + function iterable() { + return { + 'next': next + }; + } + } + + function next1() { + return { + 'value': 1.5 + }; + } + + function next2() { + return { + 'value': 'hello' + }; + } +}); + +tape( 'the constructor throws an error if provided an array containing values which cannot be converted to a 64-bit signed integers', function test( t ) { + var values; + var i; + + values = [ + [ 1.5 ], + [ NaN ], + [ {} ], + [ [] ], + [ function noop() {} ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( value ); + }; + } +}); + +tape( 'the constructor throws an error if not provided a length, iterable, array-like object, or ArrayBuffer', function test( t ) { + var values; + var i; + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( value ); + }; + } +}); + +tape( 'the constructor throws an error if provided more than one argument and the first argument is not an ArrayBuffer', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( value, 0 ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument which is not a nonnegative integer', function test( t ) { + var values; + var i; + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( new ArrayBuffer( 64 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a length argument which is not a nonnegative integer (ArrayBuffer)', function test( t ) { + var values; + var i; + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( new ArrayBuffer( 128 ), 0, value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument which is not a multiple of 8', function test( t ) { + var values; + var i; + + values = [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 9, + 21, + 65, + 78, + 801 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( new ArrayBuffer( 64 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument such that the view byte length is not a multiple of 8', function test( t ) { + var values; + var i; + + values = [ + 8, + 16, + 24, + 32, + 48, + 56, + 64, + 72, + 80, + 88, + 100 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( new ArrayBuffer( 102 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided insufficient memory to accommodate byte offset and length arguments', function test( t ) { + var values; + var i; + + values = [ + 16, + 24, + 32, + 48 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Int64Array( new ArrayBuffer( 100 ), value, 1e3 ); + }; + } +}); diff --git a/lib/node_modules/@stdlib/array/int64/test/test.of.js b/lib/node_modules/@stdlib/array/int64/test/test.of.js new file mode 100644 index 000000000000..7a5d0577eb78 --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/test/test.of.js @@ -0,0 +1,133 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var Int64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Int64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `of` method for creating a 64-bit signed integer array from a variable number of arguments', function test( t ) { + var arr; + + t.strictEqual( hasOwnProp( Int64Array, 'of' ), true, 'has property' ); + t.strictEqual( isFunction( Int64Array.of ), true, 'has method' ); + + arr = Int64Array.of(); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a constructor', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.of.call( value, 1, 1 ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit signed integer array constructor', function test( t ) { + var values; + var i; + + values = [ + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Int64Array.of.call( value, 1, 1 ); + }; + } +}); + +tape( 'the method returns a 64-bit signed integer array', function test( t ) { + var arr; + var u; + var v; + + // No arguments: + arr = Int64Array.of(); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + // Integer arguments: + arr = Int64Array.of( 1, -2, 3, -4 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // 64-bit signed integers: + u = new Int64( 1 ); + arr = Int64Array.of( u, u, u, u, u ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 5, 'returns expected value' ); + + // Mixed arguments: + u = new Int64( 1 ); + arr = Int64Array.of( u, 2, -u, -4 ); + t.strictEqual( arr instanceof Int64Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/int64/test/test.set.js b/lib/node_modules/@stdlib/array/int64/test/test.set.js new file mode 100644 index 000000000000..8e24bc4c26fa --- /dev/null +++ b/lib/node_modules/@stdlib/array/int64/test/test.set.js @@ -0,0 +1,732 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var isEqual = require( '@stdlib/number/int64/base/assert/is-equal' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var Int64Array = require( './../lib' ); + + +// VARIABLES // + +var HAS_BIGINTS = hasBigIntSupport(); +var opts = { + 'skip': !HAS_BIGINTS +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Int64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `set` method for setting one or more array elements', function test( t ) { + t.strictEqual( hasOwnProp( Int64Array.prototype, 'set' ), true, 'has property' ); + t.strictEqual( isFunction( Int64Array.prototype.set ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit signed integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set.call( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an integer, bigint, 64-bit signed integer, 64-bit signed integer array, or array-like object', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 10 ); + + values = [ + 1.5, + -1.5, + '5', + '-5', + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set( value ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an integer, bigint, 64-bit signed integer, 64-bit signed integer array, or array-like object (index argument)', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 10 ); + + values = [ + 1.5, + -1.5, + '5', + '-5', + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is not a nonnegative integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set( new Int64.of( 1, 1 ), value ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is out-of-bounds (64-bit signed integer)', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 10 ); + + values = [ + arr.length, + arr.length + 1, + arr.length + 2, + arr.length + 3 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set( new Int64( 1 ), value ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is out-of-bounds (nonnegative integer)', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 10 ); + + values = [ + arr.length, + arr.length + 1, + arr.length + 2, + arr.length + 3 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set( 1, value ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is out-of-bounds (nonnegative bigint)', opts, function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 10 ); + + values = [ + arr.length, + arr.length + 1, + arr.length + 2, + arr.length + 3 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set( BigInt( 1 ), value ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is out-of-bounds (64-bit signed integer array)', function test( t ) { + var values; + var arr1; + var arr2; + var i; + + arr1 = new Int64Array( 10 ); + arr2 = new Int64Array( 10 ); + + values = [ + 1, + 2, + 3, + 4, + 5 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr1.set( arr2, value ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is out-of-bounds (array-like object containing 64-bit signed integers)', function test( t ) { + var values; + var arr1; + var arr2; + var i; + + arr1 = new Int64Array( 10 ); + arr2 = []; + for ( i = 0; i < arr1.length; i++ ) { + arr2.push( new Int64( i ) ); + } + + values = [ + 1, + 2, + 3, + 4, + 5 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr1.set( arr2, value ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is out-of-bounds (array-like object containing nonnegative integers)', function test( t ) { + var values; + var arr1; + var arr2; + var i; + + arr1 = new Int64Array( 4 ); + arr2 = [ 1, 2, 3, 4, 5 ]; + + values = [ + 1, + 2, + 3, + 4, + 5 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr1.set( arr2, value ); + }; + } +}); + +tape( 'the method throws an error if provided an array-like object containing an invalid element', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 10 ); + + values = [ + [ 1.5 ], + [ '5' ], + [ NaN ], + [ true ], + [ false ], + [ null ], + [ void 0 ], + [ {} ], + [ function noop() {} ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set( value ); + }; + } +}); + +tape( 'the method throws an error if provided an array-like object containing an invalid element (index argument)', function test( t ) { + var values; + var arr; + var i; + + arr = new Int64Array( 10 ); + + values = [ + [ 1.5 ], + [ '5' ], + [ NaN ], + [ true ], + [ false ], + [ null ], + [ void 0 ], + [ {} ], + [ function noop() {} ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set( value, 0 ); + }; + } +}); + +tape( 'the method sets an array element (64-bit signed integer)', function test( t ) { + var expected; + var arr; + var v; + var u; + var i; + + arr = new Int64Array( 10 ); + + v = arr.get( 0 ); + expected = new Int64( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + // No index argument: + u = new Int64( 20 ); + expected = u; + arr.set( u ); + + v = arr.get( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + arr.set( new Int64( 0 ) ); + + u = new Int64( -20 ); + expected = u; + arr.set( u ); + + v = arr.get( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + arr.set( new Int64( 0 ) ); + + // Index argument: + for ( i = 0; i < arr.length; i++ ) { + v = arr.get( i ); + expected = new Int64( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+i ); + + u = new Int64( i ); + expected = u; + arr.set( u, i ); + + v = arr.get( i ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+i ); + } + t.end(); +}); + +tape( 'the method sets an array element (bigint)', opts, function test( t ) { + var expected; + var arr; + var v; + var u; + var i; + + arr = new Int64Array( 10 ); + + v = arr.get( 0 ); + expected = new Int64( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + // No index argument: + u = BigInt( 20 ); + arr.set( u ); + expected = new Int64( u ); + + v = arr.get( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + arr.set( BigInt( 0 ) ); + + u = BigInt( -20 ); + arr.set( u ); + expected = new Int64( u ); + + v = arr.get( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + arr.set( BigInt( 0 ) ); + + // Index argument: + for ( i = 0; i < arr.length; i++ ) { + v = arr.get( i ); + expected = new Int64( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+i ); + + expected = new Int64( i ); + arr.set( BigInt( i ), i ); + + v = arr.get( i ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+i ); + } + t.end(); +}); + +tape( 'the method sets an array element (array-like object containing 64-bit signed integers)', function test( t ) { + var expected1; + var expected2; + var expected; + var arr; + var u1; + var u2; + var v; + var u; + var i; + + arr = new Int64Array( 10 ); + + v = arr.get( 0 ); + expected = new Int64( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + // No index argument: + u = new Int64( 20 ); + expected = u; + arr.set( [ u ] ); + + v = arr.get( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+1 ); + + arr.set( [ new Int64( 0 ) ] ); + + u = new Int64( -20 ); + expected = u; + arr.set( [ u ] ); + + v = arr.get( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+1 ); + + arr.set( [ new Int64( 0 ) ] ); + + // Index argument: + for ( i = 0; i < arr.length; i++ ) { + v = arr.get( i ); + expected = new Int64( 0 ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+i ); + + u = new Int64( i ); + expected = u; + arr.set( [ u ], i ); + + v = arr.get( i ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+i ); + } + + // Multiple values, no index argument: + u1 = new Int64( 10 ); + u2 = new Int64( -40 ); + + arr.set( [ u1, u2 ] ); + + v = arr.get( 0 ); + expected1 = u1; + t.strictEqual( isEqual( v, expected1 ), true, 'returns expected value for index '+0 ); + + v = arr.get( 1 ); + expected2 = u2; + t.strictEqual( isEqual( v, expected2 ), true, 'returns expected value for index '+1 ); + + // Multiple values, index argument: + u1 = new Int64( -100 ); + u2 = new Int64( 300 ); + + arr.set( [ u1, u2 ], 2 ); + + v = arr.get( 2 ); + expected1 = u1; + t.strictEqual( isEqual( v, expected1 ), true, 'returns expected value for index '+2 ); + + v = arr.get( 3 ); + expected2 = u2; + t.strictEqual( isEqual( v, expected2 ), true, 'returns expected value for index '+3 ); + + t.end(); +}); + +tape( 'the method sets an array element (typed array; shared buffer)', function test( t ) { + var byteOffset; + var expected; + var arr; + var src; + var buf; + var ab; + var v; + + byteOffset = 224; + + ab = new ArrayBuffer( 480 ); + arr = new Int64Array( ab, byteOffset, 10 ); + + // Overlapping (requires copy), multiple values, no index argument: + buf = [ 20, 30 ]; + src = new Float64Array( ab, byteOffset-(1*arr.BYTES_PER_ELEMENT), 2 ); + src.set( buf ); + arr.set( src ); + + v = arr.get( 0 ); + expected = new Int64( buf[ 0 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + v = arr.get( 1 ); + expected = new Int64( buf[ 1 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index'+1 ); + + // Overlapping (requires copy), multiple values, index argument: + buf = [ -100, 200 ]; + src = new Float64Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); + src.set( buf ); + arr.set( src, 2 ); + + v = arr.get( 2 ); + expected = new Int64( buf[ 0 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index'+0 ); + + v = arr.get( 3 ); + expected = new Int64( buf[ 1 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+1 ); + + // Overlapping (no copy), multiple values, no index argument: + buf = [ 25, -45 ]; + src = new Float64Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); + src.set( buf ); + arr.set( src ); + + v = arr.get( 0 ); + expected = new Int64( buf[ 0 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + v = arr.get( 1 ); + expected = new Int64( buf[ 1 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+1 ); + + // Overlapping (no copy), multiple values, index argument: + buf = [ -105, 205 ]; + src = new Float64Array( ab, byteOffset+(3*arr.BYTES_PER_ELEMENT), 2 ); + src.set( buf ); + arr.set( src, 2 ); + + v = arr.get( 2 ); + expected = new Int64( buf[ 0 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+2 ); + + v = arr.get( 3 ); + expected = new Int64( buf[ 1 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+3 ); + + t.end(); +}); + +tape( 'the method sets an array element (64-bit signed integer typed array; shared buffer)', function test( t ) { + var byteOffset; + var expected; + var arr; + var src; + var buf; + var ab; + var v; + + byteOffset = 224; + + ab = new ArrayBuffer( 480 ); + arr = new Int64Array( ab, byteOffset, 10 ); + + // Overlapping (requires copy), multiple values, no index argument: + buf = [ 20, -30 ]; + src = new Int64Array( ab, byteOffset-(1*arr.BYTES_PER_ELEMENT), 2 ); + src.set( buf ); + arr.set( src ); + + v = arr.get( 0 ); + expected = new Int64( buf[ 0 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + v = arr.get( 1 ); + expected = new Int64( buf[ 1 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+1 ); + + // Overlapping (requires copy), multiple values, index argument: + buf = [ 100, -200, -300, 400 ]; + src = new Int64Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 4 ); + src.set( buf ); + arr.set( src, 2 ); + + v = arr.get( 2 ); + expected = new Int64( buf[ 0 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + v = arr.get( 3 ); + expected = new Int64( buf[ 1 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+1 ); + + v = arr.get( 4 ); + expected = new Int64( buf[ 2 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+2 ); + + v = arr.get( 5 ); + expected = new Int64( buf[ 3 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+3 ); + + // Overlapping (no copy), multiple values, no index argument: + buf = [ -25, 35, -45, 55 ]; + src = new Int64Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 4 ); + src.set( buf ); + arr.set( src ); + + v = arr.get( 0 ); + expected = new Int64( buf[ 0 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + v = arr.get( 1 ); + expected = new Int64( buf[ 1 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+1 ); + + // Overlapping (no copy), multiple values, index argument: + buf = [ 105, -205, 305, -405 ]; + src = new Int64Array( ab, byteOffset+(3*arr.BYTES_PER_ELEMENT), 4 ); + src.set( buf ); + arr.set( src, 2 ); + + v = arr.get( 2 ); + expected = new Int64( buf[ 0 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+0 ); + + v = arr.get( 3 ); + expected = new Int64( buf[ 1 ] ); + t.strictEqual( isEqual( v, expected ), true, 'returns expected value for index '+1 ); + + t.end(); +});