diff --git a/lib/node_modules/@stdlib/array/uint64/README.md b/lib/node_modules/@stdlib/array/uint64/README.md index 02da19409141..67893b932a53 100644 --- a/lib/node_modules/@stdlib/array/uint64/README.md +++ b/lib/node_modules/@stdlib/array/uint64/README.md @@ -278,6 +278,103 @@ u = arr.at( -100 ); // returns undefined ``` + + +#### Uint64Array.prototype.copyWithin( target, start\[, end] ) + +Copies a sequence of elements within the array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( 4 ); + +// Set the array elements: +arr.set( 1, 0 ); +arr.set( 2, 1 ); +arr.set( 3, 2 ); +arr.set( 4, 3 ); + +// Get the first array element: +var z = arr.get( 0 ); +// returns [ 1n ] + +// Get the second array element: +z = arr.get( 1 ); +// returns [ 2n ] + +// Copy the last two elements to the first two elements: +arr.copyWithin( 0, 2 ); + +// Get the first array element: +z = arr.get( 0 ); +// returns [ 3n ] + +// Get the second array element: +z = arr.get( 1 ); +// returns [ 4n ] +``` + +By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( 4 ); + +// Set the array elements: +arr.set( 1, 0 ); +arr.set( 2, 1 ); +arr.set( 3, 2 ); +arr.set( 4, 3 ); + +// Get the third array element: +var z = arr.get( 2 ); +// returns [ 3n ] + +// Get the last array element: +z = arr.get( 3 ); +// returns [ 4n ] + +// Copy the first two elements to the last two elements: +arr.copyWithin( 2, 0, 2 ); + +// Get the third array element: +z = arr.get( 2 ); +// returns [ 1n ] + +// Get the last array element: +z = arr.get( 3 ); +// returns [ 2n ] +``` + +When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example: + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( [ 1, 2, 3, 4 ] ); + +// Get the third array element: +var z = arr.get( 2 ); +// returns [ 3n ] + +// Get the last array element: +z = arr.get( 3 ); +// returns [ 4n ] + +// Copy the first two elements to the last two elements using negative indices: +arr.copyWithin( -2, -4, -2 ); + +// Get the third array element: +z = arr.get( 2 ); +// returns [ 1n ] + +// Get the last array element: +z = arr.get( 3 ); +// returns [ 2n ] +``` + #### Uint64Array.prototype.entries() @@ -309,6 +406,422 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the - **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. + + +#### Uint64Array.prototype.every( predicate\[, thisArg] ) + +Returns a boolean indicating whether all elements pass a test. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v ) { + return ( isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 2, 4, 6 ] ); + +// Check whether all elements pass a test: +var bool = arr.every( predicate ); +// returns true +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +function predicate( v, i ) { + this.count += 1; + return ( i >= 0 ); +} + +var arr = new Uint64Array( [ 2, 4, 6 ] ); + +var context = { + 'count': 0 +}; + +var bool = arr.every( predicate, context ); +// returns true + +var count = context.count; +// returns 3 +``` + + + +#### Uint64Array.prototype.fill( value\[, start\[, end]] ) + +Returns a modified typed array filled with a fill value. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( 3 ); + +// Set all elements to the same value: +arr.fill( new Uint64( 1 ) ); + +var u = arr.get( 0 ); +// returns [ 1n ] + +u = arr.get( 2 ); +// returns [ 1n ] + +// Fill all elements starting from the second element: +arr.fill( new Uint64( 2 ), 1 ); + +u = arr.get( 1 ); +// returns [ 2n ] + +u = arr.get( 2 ); +// returns [ 2n ] + +// Fill all elements from first element until the second-to-last element: +arr.fill( new Uint64( 3 ), 0, 2 ); + +u = arr.get( 0 ); +// returns [ 3n ] + +u = arr.get( 1 ); +// returns [ 3n ] +``` + +When a `start` and/or `end` index is negative, the respective index is determined relative to the last array element. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( 3 ); + +// Set all array elements, except the last element, to the same value: +arr.fill( new Uint64( 1 ), 0, -1 ); + +var u = arr.get( 0 ); +// returns [ 1n ] + +u = arr.get( arr.length - 1 ); +// returns [ 0n ] +``` + + + +#### Uint64Array.prototype.filter( predicate\[, thisArg] ) + +Returns a new array containing the elements of an array which pass a test implemented by a predicate function. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v ) { + return ( isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 1, 2, 3, 4, 5, 6 ] ); + +var out = arr.filter( predicate ); +// returns [ 2n, 4n, 6n ] + +var len = out.length; +// returns 3 +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v, i ) { + this.count += 1; + return ( i >= 0 && isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 1, 2, 3, 4, 5, 6 ] ); + +var context = { + 'count': 0 +}; + +var out = arr.filter( predicate, context ); +// returns [ 2n, 4n, 6n ] + +var len = out.length; +// returns 3 + +var count = context.count; +// returns 6 +``` + + + +#### Uint64Array.prototype.find( predicate\[, thisArg] ) + +Returns the first element in an array for which a predicate function returns a truthy value. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v ) { + return ( isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 1, 3, 4, 5 ] ); + +var u = arr.find( predicate ); +// returns [ 4n ] +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v, i ) { + this.count += 1; + return ( i >= 0 && isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 1, 3, 4, 5 ] ); + +var context = { + 'count': 0 +}; + +var u = arr.find( predicate, context ); +// returns [ 4n] + +var count = context.count; +// returns 3 +``` + + + +#### Uint64Array.prototype.findIndex( predicate\[, thisArg] ) + +Returns the index of the first element in an array for which a predicate function returns a truthy value. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v ) { + return ( isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 1, 3, 4, 6 ] ); + +var idx = arr.findIndex( predicate ); +// returns 2 +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v, i ) { + this.count += 1; + return ( i >= 0 && isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 1, 3, 5, 7 ] ); + +var context = { + 'count': 0 +}; + +var idx = arr.findIndex( predicate, context ); +// returns -1 + +var count = context.count; +// returns 4 +``` + + + +#### Uint64Array.prototype.findLast( predicate\[, thisArg] ) + +Returns the last element in an array for which a `predicate` function returns a truthy value. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v ) { + return ( isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + +var u = arr.findLast( predicate ); +// returns [ 4n ] +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v ) { + this.count += 1; + return ( isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + +var context = { + 'count': 0 +}; + +var u = arr.findLast( predicate, context ); +// returns [ 4n ] + +var count = context.count; +// returns 2 +``` + +If a `predicate` function never returns a truthy value, the method returns `undefined`. + + + +#### Uint64Array.prototype.findLastIndex( predicate\[, thisArg] ) + +Returns the index of the last element in an array for which a `predicate` function returns a truthy value. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v ) { + return ( isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + +var idx = arr.findLastIndex( predicate ); +// returns 3 +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v ) { + this.count += 1; + return ( isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + +var context = { + 'count': 0 +}; + +var idx = arr.findLastIndex( predicate, context ); +// returns 3 + +var count = context.count; +// returns 2 +``` + +If a `predicate` function never returns a truthy value, the method returns `-1`. + + + +#### Uint64Array.prototype.forEach( callbackFn\[, thisArg] ) + +Invokes a function once for each array element. + +```javascript +function log( v, i ) { + console.log( '%s: %s', i, v.toString() ); +} + +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +arr.forEach( log ); +/* => + 0: 1 + 1: 2 + 2: 3 +*/ +``` + +The invoked function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +function fcn( v, i ) { + this.count += 1; + console.log( '%s: %s', i, v.toString() ); +} + +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var context = { + 'count': 0 +}; + +arr.forEach( fcn, context ); +/* => + 0: 1 + 1: 2 + 2: 3 +*/ + +var count = context.count; +// returns 3 +``` + #### Uint64Array.prototype.get( i ) @@ -335,6 +848,226 @@ var u = arr.get( 100 ); // returns undefined ``` + + +#### Uint64Array.prototype.includes( searchElement\[, fromIndex] ) + +Returns a boolean indicating whether an array includes a provided value. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + +var bool = arr.includes( new Uint64( 3 ) ); +// returns true + +bool = arr.includes( 3, 3 ); +// returns false + +bool = arr.includes( 4, -3 ); +// returns true +``` + + + +#### Uint64Array.prototype.indexOf( searchElement\[, fromIndex] ) + +Returns the first index at which a given element can be found. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( [ 1, 2, 3, 4, 2 ] ); + +var idx = arr.indexOf( new Uint64( 3 ) ); +// returns 2 + +idx = arr.indexOf( 2, 2 ); +// returns 4 + +idx = arr.indexOf( 4, -3 ); +// returns 3 +``` + +If `searchElement` is not present in the array, the method returns `-1`. + +```javascript +var arr = new Uint64Array( [ 1, 2 ] ); + +var idx = arr.indexOf( 3 ); +// returns -1 + +idx = arr.indexOf( 1, 1 ); +// returns -1 +``` + + + +#### Uint64Array.prototype.join( \[separator] ) + +Returns a new string by concatenating all array elements. + +```javascript +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var str = arr.join(); +// returns '1,2,3' +``` + +By default, the method separates serialized array elements with a comma. To use an alternative separator, provide a `separator` string. + +```javascript +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var str = arr.join( '/' ); +// returns '1/2/3' +``` + + +#### Uint64Array.prototype.keys() + +Returns an iterator for iterating over each index key in a typed array. + +```javascript +var arr = new Uint64Array( [ 1, 2 ] ); + +var iter = arr.keys(); + +var v = iter.next().value; +// returns 0 + +v = iter.next().value; +// returns 1 + +var bool = iter.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. + + + +#### Uint64Array.prototype.lastIndexOf( searchElement\[, fromIndex] ) + +Returns the last index at which a given element can be found. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( [ 1, 2, 3, 4, 3 ] ); + +var idx = arr.lastIndexOf( new Uint64( 3 ) ); +// returns 4 + +idx = arr.lastIndexOf( 3, 3 ); +// returns 2 + +idx = arr.lastIndexOf( 2, -3 ); +// returns 1 +``` + +If `searchElement` is not present in the array, the method returns `-1`. + +```javascript +var arr = new Uint64Array( [ 1, 2 ] ); + +var idx = arr.lastIndexOf( 3 ); +// returns -1 + +idx = arr.lastIndexOf( 2, 0 ); +// returns -1 +``` + + + +#### Uint64Array.prototype.map( callbackFn\[, thisArg] ) + +Returns a new array with each element being the result of a provided callback function. + +```javascript +var add = require( '@stdlib/number/uint64/base/add' ); + +function scale( v ) { + return add( v, v ); +} + +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var out = arr.map( scale ); +// returns [ 2n, 4n, 6n ] +``` + +The callback function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +var add = require( '@stdlib/number/uint64/base/add' ); + +function scale( v ) { + this.count += 1; + return add( v, v ); +} + +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var context = { + 'count': 0 +}; + +var out = arr.map( scale, context ); +// returns [ 2n, 4n, 6n ] + +var count = context.count; +// returns 3 +``` + + + +#### Uint64Array.prototype.reduce( reducerFn\[, initialValue] ) + +Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. + +```javascript +var add = require( '@stdlib/number/uint64/base/add' ); + +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var u = arr.reduce( add ); +// returns [ 6n ] +``` + +The reducer function is provided four arguments: + +- **acc**: accumulated result. +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +By default, the function initializes the accumulated result to the first element in the array and passes the second array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the first array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument. + +```javascript +var Number = require( '@stdlib/number/ctor' ); + +function reducer( acc, v ) { + acc += Number( v ); + return acc; +} + +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var sum = arr.reduce( reducer, 2 ); +// returns 8 +``` + #### Uint64Array.prototype.set( value\[, i] ) diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.copy_within.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.copy_within.js new file mode 100644 index 000000000000..d416f14ae33a --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.copy_within.js @@ -0,0 +1,53 @@ +/** +* @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 isUint64Array = require( '@stdlib/assert/is-uint64array' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:copyWithin', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., copying all but one element to an overlapping region)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.copyWithin( 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.copy_within.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.copy_within.length.js new file mode 100644 index 000000000000..80678f6ca5d2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.copy_within.length.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isUint64Array = require( '@stdlib/assert/is-uint64array' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., copying all but one element to an overlapping region)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.copyWithin( 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:copyWithin:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.js new file mode 100644 index 000000000000..83b65c06db2d --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.js @@ -0,0 +1,85 @@ +/** +* @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 isUint64 = require( '@stdlib/assert/is-uint64' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:every', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., the predicate passes for every element, so the method cannot exit early)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.every( predicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return isUint64( v ); + } +}); + +bench( format( '%s::this_context:every', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., the predicate passes for every element, so the method cannot exit early)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.every( predicate, {} ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return isUint64( v ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.length.js new file mode 100644 index 000000000000..a6a74e1f5649 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.length.js @@ -0,0 +1,108 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {Uint64} value - array element +* @returns {boolean} boolean indicating whether a value passes a test +*/ +function predicate( value ) { + return isUint64( value ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var bool; + var i; + + // Benchmark worst case scenario (i.e., the predicate passes for every element, so the method cannot exit early)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.every( predicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:every:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.js new file mode 100644 index 000000000000..57906323120c --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.js @@ -0,0 +1,59 @@ +/** +* @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 isUint64Array = require( '@stdlib/assert/is-uint64array' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:fill', pkg ), function benchmark( b ) { + var values; + var arr; + var out; + var i; + + values = [ + new Uint64( 1 ), + new Uint64( 2 ), + new Uint64( 3 ) + ]; + arr = new Uint64Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.fill( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.length.js new file mode 100644 index 000000000000..ca8e0eefc600 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.length.js @@ -0,0 +1,103 @@ +/** +* @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 isUint64Array = require( '@stdlib/assert/is-uint64array' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var values; + var out; + var i; + + values = [ + new Uint64( 1 ), + new Uint64( 2 ), + new Uint64( 3 ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.fill( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:fill:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.filter.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.filter.js new file mode 100644 index 000000000000..6487efa741e1 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.filter.js @@ -0,0 +1,85 @@ +/** +* @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 isUint64 = require( '@stdlib/assert/is-uint64' ); +var isUint64Array = require( '@stdlib/assert/is-uint64array' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:filter', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., the predicate passes for every element, so every element is copied to the output array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.filter( predicate ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return isUint64( v ); + } +}); + +bench( format( '%s::this_context:filter', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., the predicate passes for every element, so every element is copied to the output array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.filter( predicate, {} ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return isUint64( v ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.filter.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.filter.length.js new file mode 100644 index 000000000000..b68f095a3051 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.filter.length.js @@ -0,0 +1,108 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var isUint64Array = require( '@stdlib/assert/is-uint64array' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {Uint64} value - array element +* @returns {boolean} boolean indicating whether a value passes a test +*/ +function predicate( value ) { + return isUint64( value ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., the predicate passes for every element, so every element is copied to the output array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.filter( predicate ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:filter:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find.js new file mode 100644 index 000000000000..bba78e6b242a --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find.js @@ -0,0 +1,91 @@ +/** +* @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 isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:find', pkg ), function benchmark( b ) { + var arr; + var out; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 1 ); + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.find( predicate ); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( u ) { + return isEqual( u, v ); + } +}); + +bench( format( '%s::this_context:find', pkg ), function benchmark( b ) { + var arr; + var out; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 1 ); + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.find( predicate, {} ); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( u ) { + return isEqual( u, v ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find.length.js new file mode 100644 index 000000000000..2b865eff3136 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find.length.js @@ -0,0 +1,113 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// VARIABLES // + +var SEARCH_VALUE = new Uint64( 1 ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {Uint64} value - array element +* @returns {boolean} boolean indicating whether a value passes a test +*/ +function predicate( value ) { + return isEqual( value, SEARCH_VALUE ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.find( predicate ); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:find:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_index.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_index.js new file mode 100644 index 000000000000..c96ab5efbe29 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_index.js @@ -0,0 +1,91 @@ +/** +* @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 isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:findIndex', pkg ), function benchmark( b ) { + var arr; + var out; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 1 ); + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findIndex( predicate ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( u ) { + return isEqual( u, v ); + } +}); + +bench( format( '%s::this_context:findIndex', pkg ), function benchmark( b ) { + var arr; + var out; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 1 ); + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findIndex( predicate, {} ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( u ) { + return isEqual( u, v ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_index.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_index.length.js new file mode 100644 index 000000000000..bc0299d5f6be --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_index.length.js @@ -0,0 +1,113 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// VARIABLES // + +var SEARCH_VALUE = new Uint64( 1 ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {Uint64} value - array element +* @returns {boolean} boolean indicating whether a value passes a test +*/ +function predicate( value ) { + return isEqual( value, SEARCH_VALUE ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findIndex( predicate ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:findIndex:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last.js new file mode 100644 index 000000000000..87dff9c2b664 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last.js @@ -0,0 +1,91 @@ +/** +* @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 isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:findLast', pkg ), function benchmark( b ) { + var arr; + var out; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 1 ); + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLast( predicate ); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( u ) { + return isEqual( u, v ); + } +}); + +bench( format( '%s::this_context:findLast', pkg ), function benchmark( b ) { + var arr; + var out; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 1 ); + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLast( predicate, {} ); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( u ) { + return isEqual( u, v ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last.length.js new file mode 100644 index 000000000000..9809cfeb1da8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last.length.js @@ -0,0 +1,113 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// VARIABLES // + +var SEARCH_VALUE = new Uint64( 1 ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {Uint64} value - array element +* @returns {boolean} boolean indicating whether a value passes a test +*/ +function predicate( value ) { + return isEqual( value, SEARCH_VALUE ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLast( predicate ); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:findLast:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last_index.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last_index.js new file mode 100644 index 000000000000..1f0163dbaddd --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last_index.js @@ -0,0 +1,91 @@ +/** +* @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 isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:findLastIndex', pkg ), function benchmark( b ) { + var arr; + var out; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 1 ); + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLastIndex( predicate ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( u ) { + return isEqual( u, v ); + } +}); + +bench( format( '%s::this_context:findLastIndex', pkg ), function benchmark( b ) { + var arr; + var out; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 1 ); + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLastIndex( predicate, {} ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( u ) { + return isEqual( u, v ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last_index.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last_index.length.js new file mode 100644 index 000000000000..74892273ac8c --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.find_last_index.length.js @@ -0,0 +1,113 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// VARIABLES // + +var SEARCH_VALUE = new Uint64( 1 ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {Uint64} value - array element +* @returns {boolean} boolean indicating whether a value passes a test +*/ +function predicate( value ) { + return isEqual( value, SEARCH_VALUE ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLastIndex( predicate ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:findLastIndex:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.for_each.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.for_each.js new file mode 100644 index 000000000000..33cb70bb4637 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.for_each.js @@ -0,0 +1,91 @@ +/** +* @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 Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:forEach', pkg ), function benchmark( b ) { + var count; + var arr; + var N; + var i; + + arr = new Uint64Array( 10 ); + N = arr.length; + + count = 0; + + // Benchmark worst case scenario (i.e., the method cannot exit early, so every element is visited)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr.forEach( fcn ); + if ( count !== N*(i+1) ) { + b.fail( 'unexpected result' ); + } + } + b.toc(); + if ( count !== N*i ) { + b.fail( 'unexpected result' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn() { + count += 1; + } +}); + +bench( format( '%s::this_context:forEach', pkg ), function benchmark( b ) { + var count; + var arr; + var N; + var i; + + arr = new Uint64Array( 10 ); + N = arr.length; + + count = 0; + + // Benchmark worst case scenario (i.e., the method cannot exit early, so every element is visited)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr.forEach( fcn, {} ); + if ( count !== N*(i+1) ) { + b.fail( 'unexpected result' ); + } + } + b.toc(); + if ( count !== N*i ) { + b.fail( 'unexpected result' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn() { + count += 1; + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.for_each.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.for_each.length.js new file mode 100644 index 000000000000..1ce29f268488 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.for_each.length.js @@ -0,0 +1,110 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var count; + var arr; + + arr = new Uint64Array( len ); + count = 0; + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + count = 0; + + // Benchmark worst case scenario (i.e., the method cannot exit early, so every element is visited)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr.forEach( fcn ); + if ( count !== len*(i+1) ) { + b.fail( 'unexpected result' ); + } + } + b.toc(); + if ( count !== len*i ) { + b.fail( 'unexpected result' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } + + /** + * Callback invoked for each array element. + * + * @private + */ + function fcn() { + count += 1; + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:forEach:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.get.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.get.js index bee09657497b..def833746eb2 100644 --- a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.get.js +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.get.js @@ -36,8 +36,7 @@ bench( format( '%s:get', pkg ), function benchmark( b ) { var v; var i; - arr = zeroTo( 10, 'generic' ); - arr = new Uint64Array( arr ); + arr = new Uint64Array( zeroTo( 10, 'generic' ) ); N = arr.length; b.tic(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.includes.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.includes.js new file mode 100644 index 000000000000..20895d5c03bd --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.includes.js @@ -0,0 +1,53 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:includes', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., the search element is never present, so the method must scan the entire array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.includes( i+1 ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.includes.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.includes.length.js new file mode 100644 index 000000000000..8a7ac0278d0c --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.includes.length.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var bool; + var i; + + // Benchmark worst case scenario (i.e., the search element is never present, so the method must scan the entire array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.includes( i+1 ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:includes:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.index_of.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.index_of.js new file mode 100644 index 000000000000..2dd119ae7614 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.index_of.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 pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:indexOf', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., the search element is never present, so the method must scan the entire array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.indexOf( i+1 ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.index_of.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.index_of.length.js new file mode 100644 index 000000000000..8eef5b3d97f0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.index_of.length.js @@ -0,0 +1,95 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., the search element is never present, so the method must scan the entire array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.indexOf( i+1 ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:indexOf:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.join.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.join.js new file mode 100644 index 000000000000..7901e28c7f79 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.join.js @@ -0,0 +1,76 @@ +/** +* @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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:join', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., every element must be serialized and concatenated)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.join(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::separator:join', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., every element must be serialized and concatenated)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.join( '/' ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.join.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.join.length.js new file mode 100644 index 000000000000..7376135ed7a6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.join.length.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., every element must be serialized and concatenated)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.join(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:join:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.keys.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.keys.js new file mode 100644 index 000000000000..bdfac60a62a0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.keys.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 isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:keys', pkg ), function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = arr.keys(); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.keys.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.keys.length.js new file mode 100644 index 000000000000..59bdb5907949 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.keys.length.js @@ -0,0 +1,95 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var iter; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = arr.keys(); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:keys:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.js new file mode 100644 index 000000000000..8f97527581e8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.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 pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:lastIndexOf', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., the search element is never present, so the method must scan the entire array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.lastIndexOf( i+1 ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.length.js new file mode 100644 index 000000000000..15a8167d6183 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.last_index_of.length.js @@ -0,0 +1,95 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., the search element is never present, so the method must scan the entire array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.lastIndexOf( i+1 ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:lastIndexOf:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.map.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.map.js new file mode 100644 index 000000000000..bcc51c2ba272 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.map.js @@ -0,0 +1,84 @@ +/** +* @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 isUint64Array = require( '@stdlib/assert/is-uint64array' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:map', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., every element is visited and written to the output array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.map( fcn ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( v ) { + return v; + } +}); + +bench( format( '%s::this_context:map', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., every element is visited and written to the output array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.map( fcn, {} ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( v ) { + return v; + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.map.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.map.length.js new file mode 100644 index 000000000000..56496f47c282 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.map.length.js @@ -0,0 +1,107 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isUint64Array = require( '@stdlib/assert/is-uint64array' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {Uint64} value - array element +* @returns {Uint64} transformed value +*/ +function fcn( value ) { + return value; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., every element is visited and written to the output array)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.map( fcn ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:map:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js new file mode 100644 index 000000000000..b7376999c583 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js @@ -0,0 +1,81 @@ +/** +* @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 isUint64 = require( '@stdlib/assert/is-uint64' ); +var add = require( '@stdlib/number/uint64/base/add' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:reduce', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduce( add ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64( out ) ) { + b.fail( 'should return a 64-bit unsigned integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::initial_value:reduce', pkg ), function benchmark( b ) { + var out; + var arr; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 0 ); + + // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduce( add, v ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64( out ) ) { + b.fail( 'should return a 64-bit unsigned integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.length.js new file mode 100644 index 000000000000..2336da53d722 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.length.js @@ -0,0 +1,97 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var add = require( '@stdlib/number/uint64/base/add' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduce( add ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64( out ) ) { + b.fail( 'should return a 64-bit unsigned integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:reduce:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index c737fc5bf588..408e736c352f 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -252,6 +252,35 @@ [ 2n ] +{{alias}}.prototype.copyWithin( target, start[, end] ) + Copies a sequence of elements within the array starting at `start` and + ending at `end` (non-inclusive) to the position starting at `target`. + + Parameters + ---------- + target: integer + Target start index position. + + start: integer + Source start index position. + + end: integer (optional) + Source end index position. Default: out.length. + + Returns + ------- + out: Uint64Array + Modified array. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3, 4 ] ); + > arr.copyWithin( 0, 2 ) + [ 3n, 4n, 3n, 4n ] + > var z = arr.get( 0 ) + [ 3n ] + + {{alias}}.prototype.entries() Returns an iterator for iterating over array key-value pairs. @@ -275,6 +304,271 @@ true +{{alias}}.prototype.every( predicate[, thisArg] ) + Returns a boolean indicating whether all elements in the array pass a test. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + Parameters + ---------- + predicate: Function + Predicate function which tests array elements. If a predicate function + returns a truthy value, an array element passes; otherwise, an array + element fails. + + thisArg: any (optional) + Execution context. + + Returns + ------- + bool: boolean + Boolean indicating whether all elements pass the test. + + Examples + -------- + > function predicate( v ) {return({{alias:@stdlib/assert/is-uint64}}(v));}; + > var arr = new {{alias}}( [ 2, 4, 6 ] ) + + > var bool = arr.every( predicate ) + true + + +{{alias}}.prototype.fill( value[, start[, end]] ) + Returns a modified typed array filled with a fill value. + + Parameters + ---------- + value: Uint64 + Fill value. + + start: integer (optional) + Start index. If less than zero, the start index is resolved relative to + the last array element. Default: 0. + + end: integer (optional) + End index (non-inclusive). If less than zero, the end index is resolved + relative to the last array element. Default: out.length. + + Returns + ------- + out: Uint64Array + Modified array. + + Examples + -------- + > var arr = new {{alias}}( 3 ); + > arr.fill( 1 ) + [ 1n, 1n, 1n ] + + +{{alias}}.prototype.filter( predicate[, thisArg] ) + Returns a new array containing the elements of an array which pass a test + implemented by a predicate function. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + The returned array has the same data type as the host array. + + Parameters + ---------- + predicate: Function + Predicate function which filters array elements. If a predicate function + returns a truthy value, an array element is included in the output + array; otherwise, an array element is not included in the output array. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: Uint64Array + A new typed array. + + Examples + -------- + > function predicate( v ) { return ( {{alias:@stdlib/assert/is-even}}.isPrimitive( {{alias:@stdlib/number/ctor}}( v ) ) ); }; + > var arr = new {{alias}}( [ 1, 2, 3, 4, 5, 6 ] ); + > var out = arr.filter( predicate ) + returns [ 2n, 4n, 6n ] + > var len = out.length + 3 + + +{{alias}}.prototype.find( predicate[, thisArg] ) + Returns the first element in an array for which a predicate function + returns a truthy value. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + If a predicate function never returns a truthy value, the method returns + `undefined`. + + Parameters + ---------- + predicate: Function + Predicate function which tests array elements. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: Uint64|void + Array element or `undefined`. + + Examples + -------- + > function predicate( v ) { return ( {{alias:@stdlib/assert/is-even}}.isPrimitive( {{alias:@stdlib/number/ctor}}( v ) ) ); }; + > var arr = new {{alias}}( [ 1, 3, 4, 5 ] ); + > var u = arr.find( predicate ) + [ 4n ] + + +{{alias}}.prototype.findIndex( predicate[, thisArg] ) + Returns the index of the first element in an array for which a predicate + function returns a truthy value. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + If a predicate function never returns a truthy value, the method returns + `-1`. + + Parameters + ---------- + predicate: Function + Predicate function which tests array elements. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: integer + Array index or `-1`. + + Examples + -------- + > function predicate( v ) { return ( {{alias:@stdlib/assert/is-even}}.isPrimitive( {{alias:@stdlib/number/ctor}}( v ) ) ); }; + > var arr = new {{alias}}( [ 1, 3, 4, 6 ] ) + [ 1n, 3n, 4n, 6n ] + > var idx = arr.findIndex( predicate ) + 2 + + +{{alias}}.prototype.findLast( predicate[, thisArg] ) + Returns the last element in an array for which a predicate function returns + a truthy value. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + If a predicate function never returns a truthy value, the method returns + `undefined`. + + Parameters + ---------- + predicate: Function + Predicate function which tests array elements. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: Uint64|void + Array element or `undefined`. + + Examples + -------- + > function predicate( v ) { return ( {{alias:@stdlib/assert/is-even}}.isPrimitive( {{alias:@stdlib/number/ctor}}( v ) ) ); }; + > var arr = new {{alias}}( [ 1, 2, 3, 4, 5 ] ) + [ 1n, 2n, 3n, 4n, 5n ] + > var u = arr.findLast( predicate ) + [ 4n ] + + +{{alias}}.prototype.findLastIndex( predicate[, thisArg] ) + Returns the index of the last element in an array for which a predicate + function returns a truthy value. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + If a predicate function never returns a truthy value, the method returns + `-1`. + + Parameters + ---------- + predicate: Function + Predicate function which tests array elements. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: integer + Index or `-1`. + + Examples + -------- + > function predicate( v ) { return ( {{alias:@stdlib/assert/is-even}}.isPrimitive( {{alias:@stdlib/number/ctor}}( v ) ) ); }; + > var arr = new {{alias}}( [ 1, 2, 3, 4, 5 ] ) + [ 1n, 2n, 3n, 4n, 5n ] + > var idx = arr.findLastIndex( predicate ) + 3 + + +{{alias}}.prototype.forEach( clbk[, thisArg] ) + Invokes a function once for each array element. + + A callback function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + Parameters + ---------- + clbk: Function + Function to invoke for each array element. + + thisArg: any (optional) + Execution context. + + Examples + -------- + > var str = '%'; + > function clbk( v ) { str += v.toString() + '%'; }; + > var arr = new {{alias}}( [ 1, 2 ] ) + [ 1n, 2n ] + > arr.forEach( clbk ); + > str + '%1%2%' + + {{alias}}.prototype.get( i ) Returns an array element located at integer position (index) `i`. @@ -299,6 +593,214 @@ [ 2n ] +{{alias}}.prototype.includes( searchElement[, fromIndex] ) + Returns a boolean indicating whether an array includes a provided value. + + Parameters + ---------- + searchElement: Uint64|number|bigint + Search element. + + fromIndex: integer (optional) + Array index at which to start the search. If provided a negative value, + the method resolves the start index relative to the last array element. + Default: 0. + + Returns + ------- + bool: boolean + Boolean indicating whether an array includes a search element. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3, 4 ] ) + [ 1n, 2n, 3n, 4n ] + > var bool = arr.includes( new {{alias:@stdlib/number/uint64/ctor}}( 3 ) ) + true + > bool = arr.includes( 3, 3 ) + false + + +{{alias}}.prototype.indexOf( searchElement[, fromIndex] ) + Returns the first index at which a given element can be found. + + If method does not find a search element, the method returns `-1`. + + Parameters + ---------- + searchElement: Uint64|number|bigint + Search element. + + fromIndex: integer (optional) + Array index at which to start the search. If provided a negative value, + the method resolves the start index relative to the last array element. + Default: 0. + + Returns + ------- + out: integer + Array index or `-1`. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3, 4 ] ) + [ 1n, 2n, 3n, 4n ] + > var idx = arr.indexOf( new {{alias:@stdlib/number/uint64/ctor}}( 3 ) ) + 2 + > idx = arr.indexOf( 3, 3 ) + -1 + + +{{alias}}.prototype.join( [separator] ) + Returns a new string by concatenating all array elements separated by a + separator string. + + Parameters + ---------- + separator: string (optional) + Separator string. Default: ','. + + Returns + ------- + out: string + Array serialized as a string. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3 ] ) + [ 1n, 2n, 3n ] + > var str = arr.join() + '1,2,3' + > str = arr.join( '/' ) + '1/2/3' + + +{{alias}}.prototype.keys() + Returns an iterator for iterating over each index key in a typed array. + + Returns + ------- + iterator: Iterator + Iterator for iterating over array index keys. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2 ] ) + [ 1n, 2n ] + > var it = arr.keys(); + > var v = it.next().value + 0 + > v = it.next().value + 1 + > v = it.next().done + true + + +{{alias}}.prototype.lastIndexOf( searchElement[, fromIndex] ) + Returns the last index at which a given element can be found. + + If method does not find a search element, the method returns `-1`. + + Parameters + ---------- + searchElement: Uint64|number|bigint + Search element. + + fromIndex: integer (optional) + Array index at which to start the search backward. If provided a + negative value, the method resolves the start index relative to the + last array element. Default: -1. + + Returns + ------- + out: integer + Array index or `-1`. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3, 2 ] ) + [ 1n, 2n, 3n, 2n ] + > var idx = arr.lastIndexOf( new {{alias:@stdlib/number/uint64/ctor}}( 2 ) ) + 3 + > idx = arr.lastIndexOf( 2, 2 ) + 1 + + +{{alias}}.prototype.map( clbk[, thisArg] ) + Returns a new array with each element being the result of a provided + callback function. + + A callback function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + The returned array has the same data type as the host array. + + Parameters + ---------- + clbk: Function + Function which maps array elements to elements in the new array. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: Uint64Array + A new typed array. + + Examples + -------- + > function clbk( v ) { return v; }; + > var arr = new {{alias}}( [ 1, 2 ] ) + [ 1n, 2n ] + > var out = arr.map( clbk ) + [ 1n, 2n ] + + +{{alias}}.prototype.reduce( reducerFn[, initialValue] ) + Applies a provided function to each element of the array, in order, passing + in the return value from the calculation on the preceding element and + returning the accumulated result upon completion. + + A reducer function is provided the following arguments: + + - acc: accumulated result. + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + If provided an initial value, the method invokes a provided function with + the initial value as the first argument and the first array element as the + second argument. + + If not provided an initial value, the method invokes a provided function + with the first array element as the first argument and the second array + element as the second argument. + + Parameters + ---------- + reducerFn: Function + Function to apply to each array element. + + initialValue: any (optional) + Initial accumulation value. + + Returns + ------- + out: any + Accumulated result. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3 ] ) + [ 1n, 2n, 3n ] + > var u = arr.reduce( {{alias:@stdlib/number/uint64/base/add}} ) + [ 6n ] + + {{alias}}.prototype.set( v[, i] ) Sets one or more array elements. diff --git a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts index 78b11c503625..a1b1c1f0d09d 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts @@ -426,6 +426,25 @@ declare class Uint64Array implements Uint64ArrayInterface { */ at( i: number ): Uint64 | void; + /** + * Copies a sequence of elements within the array to the position starting at `target`. + * + * @param target - index at which to start copying elements + * @param start - source index at which to copy elements from + * @param end - source index at which to stop copying elements from + * @returns modified array + * + * @example + * var Uint64 = require( '@stdlib/number/uint64/ctor' ); + * + * var arr = new Uint64Array( [ 1, 2, 3, 4 ] ); + * + * // Copy the first two elements to the last two elements: + * arr.copyWithin( 2, 0, 2 ); + * // arr => [ 1n, 2n, 1n, 2n ] + */ + copyWithin( target: number, start: number, end?: number ): Uint64Array; + /** * Returns an iterator for iterating over array key-value pairs. * @@ -454,6 +473,176 @@ declare class Uint64Array implements Uint64ArrayInterface { */ entries(): TypedIterator<[number, Uint64]>; + /** + * Tests whether all elements in an array pass a test implemented by a predicate function. + * + * @param predicate - test function + * @param thisArg - execution context + * @returns boolean indicating whether all elements pass a test + * + * @example + * var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; + * var Number = require( '@stdlib/number/ctor' ); + * + * function predicate( v ) { + * return ( isEven( Number( v ) ) ); + * } + * + * var arr = new Uint64Array( [ 2, 4, 6 ] ); + * + * var bool = arr.every( predicate ); + * // returns true + */ + every( predicate: Predicate, thisArg?: ThisParameterType> ): boolean; + + /** + * Returns a modified typed array filled with a fill value. + * + * @param value - fill value + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @returns modified typed array + * + * @example + * var arr = new Uint64Array( 3 ); + * // returns [ 0n , 0n, 0n ] + * + * arr = arr.fill( 1, 1 ); + * // returns [ 0n, 1n, 1n ] + */ + fill( value: Uint, start?: number, end?: number ): Uint64Array; + + /** + * Returns a new array containing the elements of an array which pass a test implemented by a predicate function. + * + * @param predicate - test function + * @param thisArg - execution context + * @returns new array containing elements which pass a test implemented by a predicate function + * + * @example + * var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; + * var Number = require( '@stdlib/number/ctor' ); + * + * function predicate( v ) { + * return ( isEven( Number( v ) ) ); + * } + * + * var arr = new Uint64Array( [ 1, 2, 3, 4, 5, 6 ] ); + * + * var out = arr.filter( predicate ); + * // returns [ 2n, 4n, 6n ] + * + * var len = out.length; + * // returns 3 + */ + filter( predicate: Predicate, thisArg?: ThisParameterType> ): Uint64Array; + + /** + * Returns the first element in an array for which a predicate function returns a truthy value. + * + * @param predicate - test function + * @param thisArg - execution context + * @returns array element or undefined + * + * @example + * var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; + * var Number = require( '@stdlib/number/ctor' ); + * + * function predicate( v ) { + * return ( isEven( Number( v ) ) ); + * } + * + * var arr = new Uint64Array( [ 1, 3, 4, 6 ] ); + * + * var u = arr.find( predicate ); + * // returns [ 4n ] + */ + find( predicate: Predicate, thisArg?: ThisParameterType> ): Uint64 | void; + + /** + * Returns the index of the first element in an array for which a predicate function returns a truthy value. + * + * @param predicate - test function + * @param thisArg - execution context + * @returns index or -1 + * + * @example + * var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; + * var Number = require( '@stdlib/number/ctor' ); + * + * function predicate( v ) { + * return ( isEven( Number( v ) ) ); + * } + * + * var arr = new Uint64Array( [ 1, 3, 4, 6 ] ); + * + * var idx = arr.findIndex( predicate ); + * // returns 2 + */ + findIndex( predicate: Predicate, thisArg?: ThisParameterType> ): number; + + /** + * Returns the last element in an array for which a predicate function returns a truthy value. + * + * @param predicate - test function + * @param thisArg - predicate function execution context + * @returns array element or undefined + * + * @example + * var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; + * var Number = require( '@stdlib/number/ctor' ); + * + * function predicate( v ) { + * return ( isEven( Number( v ) ) ); + * } + * + * var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + * + * var u = arr.findLast( predicate ); + * // returns [ 4n ] + */ + findLast( predicate: Predicate, thisArg?: ThisParameterType> ): Uint64 | void; + + /** + * Returns the index of the last element in an array for which a predicate function returns a truthy value. + * + * @param predicate - test function + * @param thisArg - predicate function execution context + * @returns index or -1 + * + * @example + * var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; + * var Number = require( '@stdlib/number/ctor' ); + * + * function predicate( v ) { + * return ( isEven( Number( v ) ) ); + * } + * + * var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + * + * var idx = arr.findLastIndex( predicate ); + * // returns 3 + */ + findLastIndex( predicate: Predicate, thisArg?: ThisParameterType> ): number; + + /** + * Invokes a function once for each array element. + * + * @param fcn - function to invoke + * @param thisArg - execution context + * @returns undefined + * + * @example + * function log( v, i ) { + * console.log( '%s: %s', i, v.toString() ); + * } + * + * var arr = new Uint64Array( [ 1, 2, 3 ] ); + * + * arr.forEach( log ); + */ + forEach( fcn: Callback, thisArg?: ThisParameterType> ): void; + /** * Returns an array element. * @@ -477,6 +666,158 @@ declare class Uint64Array implements Uint64ArrayInterface { */ get( i: number ): Uint64 | void; + /** + * Returns a boolean indicating whether an array includes a provided value. + * + * @param searchElement - search element + * @param fromIndex - starting index (inclusive) + * @throws first argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer + * @throws second argument must be an integer + * @returns boolean indicating whether an array includes a provided value + * + * @example + * var Uint64 = require( '@stdlib/number/uint64/ctor' ); + * + * var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + * + * var bool = arr.includes( new Uint64( 3 ) ); + * // returns true + * + * bool = arr.includes( 3, 3 ); + * // returns false + * + * bool = arr.includes( 4n, -3 ); + * // returns true + */ + includes( searchElement: Uint, fromIndex?: number ): boolean; + + /** + * Returns the first index at which a given element can be found. + * + * @param searchElement - element to find + * @param fromIndex - starting index (inclusive) + * @throws first argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer + * @throws second argument must be an integer + * @returns index or -1 + * + * @example + * var Uint64 = require( '@stdlib/number/uint64/ctor' ); + * + * var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + * + * var idx = arr.indexOf( new Uint64( 3 ) ); + * // returns 2 + * + * idx = arr.indexOf( 3, 3 ); + * // returns -1 + * + * idx = arr.indexOf( 4n, -3 ); + * // returns 3 + */ + indexOf( searchElement: Uint, fromIndex?: number ): number; + + /** + * Returns a new string by concatenating all array elements. + * + * @param separator - value separator (default: ',') + * @returns string + * + * @example + * var arr = new Uint64Array( [ 1, 2, 3 ] ); + * + * var str = arr.join(); + * // returns '1,2,3' + * + * str = arr.join( '/' ); + * // returns '1/2/3' + */ + join( separator?: string ): string; + + /** + * Returns an iterator for iterating over each index key in a typed array. + * + * @returns iterator + * + * @example + * var arr = new Uint64Array( [ 1, 2 ] ); + * + * var iter = arr.keys(); + * + * var v = iter.next().value; + * // returns 0 + * + * v = iter.next().value; + * // returns 1 + * + * var bool = iter.next().done; + * // returns true + */ + keys(): TypedIterator; + + /** + * Returns the last index at which a given element can be found. + * + * @param searchElement - element to find + * @param fromIndex - index at which to start searching backward (inclusive) + * @returns index or -1 + * + * @example + * var Uint64 = require( '@stdlib/number/uint64/ctor' ); + * + * var arr = new Uint64Array( [ 1, 2, 3, 4, 3 ] ); + * + * var idx = arr.lastIndexOf( new Uint64( 3 ) ); + * // returns 4 + * + * idx = arr.lastIndexOf( 3, 3 ); + * // returns 2 + * + * idx = arr.lastIndexOf( 5, 3 ); + * // returns -1 + * + * idx = arr.lastIndexOf( 2n, -3 ); + * // returns 1 + */ + lastIndexOf( searchElement: Uint, fromIndex?: number ): number; + + /** + * Returns a new array with each element being the result of a provided callback function. + * + * @param fcn - callback function + * @param thisArg - execution context + * @returns new array containing transformed elements + * + * @example + * var add = require( '@stdlib/number/uint64/base/add' ); + * + * function scale( v ) { + * return add( v, v ); + * } + * + * var arr = new Uint64Array( [ 1, 2, 3 ] ); + * + * var out = arr.map( scale ); + * // returns [ 2n, 4n, 6n ] + */ + map( fcn: MapFcn, thisArg?: ThisParameterType> ): Uint64Array; + + /** + * Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. + * + * @param reducer - callback function + * @param initialValue - initial value + * @returns accumulated result + * + * @example + * var add = require( '@stdlib/number/uint64/base/add' ); + * + * var arr = new Uint64Array( [ 1, 2, 3 ] ); + * + * var u = arr.reduce( add ); + * // returns [ 6n ] + */ + reduce( reducer: Reducer, initialValue?: U ): U; + /** * Sets an array element. * diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 684cb8e4b9bd..2ca2a0a478e4 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -30,6 +30,7 @@ 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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isUint64 = require( '@stdlib/assert/is-uint64' ); var isInteger = require( '@stdlib/math/base/assert/is-integer' ); var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); @@ -597,6 +598,40 @@ setReadOnlyAccessor( Uint64Array.prototype, 'byteOffset', function get() { */ setReadOnly( Uint64Array.prototype, 'BYTES_PER_ELEMENT', Uint64Array.BYTES_PER_ELEMENT ); +/** +* Copies a sequence of elements within the array to the position starting at `target`. +* +* @name copyWithin +* @memberof Uint64Array.prototype +* @type {Function} +* @param {integer} target - index at which to start copying elements +* @param {integer} start - source index at which to copy elements from +* @param {integer} [end] - source index at which to stop copying elements from +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @returns {Uint64Array} modified array +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var arr = new Uint64Array( [ 1, 2, 3, 4 ] ); +* +* // Copy the first two elements to the last two elements: +* arr.copyWithin( 2, 0, 2 ); +* // arr => [ 1n, 2n, 1n, 2n ] +*/ +setReadOnly( Uint64Array.prototype, 'copyWithin', function copyWithin( target, start ) { + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + // FIXME: prefer a functional `copyWithin` implementation which addresses lack of universal browser support (e.g., IE11 and Safari) or ensure that typed arrays are polyfilled + if ( arguments.length === 2 ) { + this._buffer.copyWithin( target*2, start*2 ); + } else { + this._buffer.copyWithin( target*2, start*2, arguments[2]*2 ); + } + return this; +}); + /** * Returns an iterator for iterating over array key-value pairs. * @@ -702,6 +737,394 @@ setReadOnly( Uint64Array.prototype, 'entries', function entries() { } }); +/** +* Tests whether all elements in an array pass a test implemented by a predicate function. +* +* @name every +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} predicate - test function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @returns {boolean} boolean indicating whether all elements pass a test +* +* @example +* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +* var Number = require( '@stdlib/number/ctor' ); +* +* function predicate( v ) { +* return ( isEven( Number( v ) ) ); +* } +* +* var arr = new Uint64Array( [ 2, 4, 6 ] ); +* +* var bool = arr.every( predicate ); +* // returns true +*/ +setReadOnly( Uint64Array.prototype, 'every', function every( predicate, thisArg ) { + var buf; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + if ( !predicate.call( thisArg, getUint64( buf, i ), i, this ) ) { + return false; + } + } + return true; +}); + +/** +* Returns a modified typed array filled with a fill value. +* +* @name fill +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Uint64|bigint|number} value - fill value +* @param {integer} [start=0] - starting index (inclusive) +* @param {integer} [end] - ending index (exclusive) +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer +* @throws {TypeError} second argument must be an integer +* @throws {TypeError} third argument must be an integer +* @returns {Uint64Array} modified array +* +* @example +* var arr = new Uint64Array( 3 ); +* // returns [ 0n , 0n, 0n ] +* +* arr = arr.fill( 1, 1 ); +* // returns [ 0n, 1n, 1n ] +*/ +setReadOnly( Uint64Array.prototype, 'fill', function fill( value, start, end ) { + var words; + var buf; + var len; + var idx; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isUint64( value ) ) { + try { + value = new Uint64( value ); + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new TypeError( format( 'invalid argument. First argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', value ) ); + } + } + buf = this._buffer; + len = this._length; + if ( arguments.length > 1 ) { + if ( !isInteger( start ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', start ) ); + } + if ( start < 0 ) { + start += len; + if ( start < 0 ) { + start = 0; + } + } + if ( arguments.length > 2 ) { + if ( !isInteger( end ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', end ) ); + } + if ( end < 0 ) { + end += len; + if ( end < 0 ) { + end = 0; + } + } + if ( end > len ) { + end = len; + } + } else { + end = len; + } + } else { + start = 0; + end = len; + } + words = [ 0, 0 ]; + toWords( value, words, 1, 0 ); + for ( i = start; i < end; i++ ) { + idx = 2*i; + buf[ idx+indices.HIGH ] = words[ 0 ]; + buf[ idx+indices.LOW ] = words[ 1 ]; + } + return this; +}); + +/** +* Returns a new array containing the elements of an array which pass a test implemented by a predicate function. +* +* @name filter +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} predicate - test function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @returns {Uint64Array} 64-bit unsigned integer array +* +* @example +* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +* var Number = require( '@stdlib/number/ctor' ); +* +* function predicate( v ) { +* return ( isEven( Number( v ) ) ); +* } +* +* var arr = new Uint64Array( [ 1, 2, 3, 4, 5, 6 ] ); +* +* var out = arr.filter( predicate ); +* // returns [ 2n, 4n, 6n ] +* +* var len = out.length; +* // returns 3 +*/ +setReadOnly( Uint64Array.prototype, 'filter', function filter( predicate, thisArg ) { + var buf; + var out; + var i; + var u; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + out = []; + for ( i = 0; i < this._length; i++ ) { + u = getUint64( buf, i ); + if ( predicate.call( thisArg, u, i, this ) ) { + out.push( u ); + } + } + return new this.constructor( out ); +}); + +/** +* Returns the first element in an array for which a predicate function returns a truthy value. +* +* @name find +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} predicate - test function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @returns {(Uint64|void)} array element or undefined +* +* @example +* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +* var Number = require( '@stdlib/number/ctor' ); +* +* function predicate( v ) { +* return ( isEven( Number( v ) ) ); +* } +* +* var arr = new Uint64Array( [ 1, 3, 4, 6 ] ); +* +* var u = arr.find( predicate ); +* // returns [ 4n ] +*/ +setReadOnly( Uint64Array.prototype, 'find', function find( predicate, thisArg ) { + var buf; + var i; + var u; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + u = getUint64( buf, i ); + if ( predicate.call( thisArg, u, i, this ) ) { + return u; + } + } +}); + +/** +* Returns the index of the first element in an array for which a predicate function returns a truthy value. +* +* @name findIndex +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} predicate - test function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @returns {integer} index or -1 +* +* @example +* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +* var Number = require( '@stdlib/number/ctor' ); +* +* function predicate( v ) { +* return ( isEven( Number( v ) ) ); +* } +* +* var arr = new Uint64Array( [ 1, 3, 4, 6 ] ); +* +* var idx = arr.findIndex( predicate ); +* // returns 2 +*/ +setReadOnly( Uint64Array.prototype, 'findIndex', function findIndex( predicate, thisArg ) { + var buf; + var i; + var u; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + u = getUint64( buf, i ); + if ( predicate.call( thisArg, u, i, this ) ) { + return i; + } + } + return -1; +}); + +/** +* Returns the last element in an array for which a predicate function returns a truthy value. +* +* @name findLast +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} predicate - test function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @returns {(Uint64|void)} array element or undefined +* +* @example +* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +* var Number = require( '@stdlib/number/ctor' ); +* +* function predicate( v ) { +* return ( isEven( Number( v ) ) ); +* } +* +* var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); +* +* var u = arr.findLast( predicate ); +* // returns [ 4n ] +*/ +setReadOnly( Uint64Array.prototype, 'findLast', function findLast( predicate, thisArg ) { + var buf; + var u; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = this._length-1; i >= 0; i-- ) { + u = getUint64( buf, i ); + if ( predicate.call( thisArg, u, i, this ) ) { + return u; + } + } +}); + +/** +* Returns the index of the last element in an array for which a predicate function returns a truthy value. +* +* @name findLastIndex +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} predicate - test function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @returns {integer} index or -1 +* +* @example +* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +* var Number = require( '@stdlib/number/ctor' ); +* +* function predicate( v ) { +* return ( isEven( Number( v ) ) ); +* } +* +* var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); +* +* var idx = arr.findLastIndex( predicate ); +* // returns 3 +*/ +setReadOnly( Uint64Array.prototype, 'findLastIndex', function findLastIndex( predicate, thisArg ) { + var buf; + var u; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = this._length-1; i >= 0; i-- ) { + u = getUint64( buf, i ); + if ( predicate.call( thisArg, u, i, this ) ) { + return i; + } + } + return -1; +}); + +/** +* Invokes a function once for each array element. +* +* @name forEach +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} fcn - function to invoke +* @param {*} [thisArg] - function invocation context +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* +* @example +* function log( v, i ) { +* console.log( '%s: %s', i, v.toString() ); +* } +* +* var arr = new Uint64Array( [ 1, 2, 3 ] ); +* +* arr.forEach( log ); +*/ +setReadOnly( Uint64Array.prototype, 'forEach', function forEach( fcn, thisArg ) { + var buf; + var i; + var v; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( fcn ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) ); + } + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + v = getUint64( buf, i ); + fcn.call( thisArg, v, i, this ); + } +}); + /** * Returns an array element. * @@ -740,6 +1163,349 @@ setReadOnly( Uint64Array.prototype, 'get', function get( idx ) { return getUint64( this._buffer, idx ); }); +/** +* Returns a boolean indicating whether an array includes a provided value. +* +* @name includes +* @memberof Uint64Array.prototype +* @type {Function} +* @param {(Uint64|bigint|number)} searchElement - search element +* @param {integer} [fromIndex=0] - starting index (inclusive) +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer +* @throws {TypeError} second argument must be an integer +* @returns {boolean} boolean indicating whether an array includes a provided value +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); +* +* var bool = arr.includes( new Uint64( 3 ) ); +* // returns true +* +* bool = arr.includes( 3, 3 ); +* // returns false +* +* bool = arr.includes( 4n, -3 ); +* // returns true +*/ +setReadOnly( Uint64Array.prototype, 'includes', function includes( searchElement, fromIndex ) { + var words; + var buf; + var idx; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isUint64( searchElement ) ) { + try { + searchElement = new Uint64( searchElement ); + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new TypeError( format( 'invalid argument. First argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', searchElement ) ); + } + } + if ( arguments.length > 1 ) { + if ( !isIntegerPrimitive( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + } + if ( fromIndex < 0 ) { + fromIndex += this._length; + if ( fromIndex < 0 ) { + fromIndex = 0; + } + } + } else { + fromIndex = 0; + } + words = [ 0, 0 ]; + toWords( searchElement, words, 1, 0 ); + buf = this._buffer; + for ( i = fromIndex; i < this._length; i++ ) { + idx = 2 * i; + if ( words[ 0 ] === buf[ idx+indices.HIGH ] && words[ 1 ] === buf[ idx+indices.LOW ] ) { // eslint-disable-line max-len + return true; + } + } + return false; +}); + +/** +* Returns the first index at which a given element can be found. +* +* @name indexOf +* @memberof Uint64Array.prototype +* @type {Function} +* @param {(Uint64|bigint|number)} searchElement - element to find +* @param {integer} [fromIndex=0] - starting index (inclusive) +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer +* @throws {TypeError} second argument must be an integer +* @returns {integer} index or -1 +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); +* +* var idx = arr.indexOf( new Uint64( 3 ) ); +* // returns 2 +* +* idx = arr.indexOf( 3, 3 ); +* // returns -1 +* +* idx = arr.indexOf( 4n, -3 ); +* // returns 3 +*/ +setReadOnly( Uint64Array.prototype, 'indexOf', function indexOf( searchElement, fromIndex ) { + var words; + var buf; + var idx; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isUint64( searchElement ) ) { + try { + searchElement = new Uint64( searchElement ); + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new TypeError( format( 'invalid argument. First argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', searchElement ) ); + } + } + if ( arguments.length > 1 ) { + if ( !isIntegerPrimitive( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + } + if ( fromIndex < 0 ) { + fromIndex += this._length; + if ( fromIndex < 0 ) { + fromIndex = 0; + } + } + } else { + fromIndex = 0; + } + words = [ 0, 0 ]; + toWords( searchElement, words, 1, 0 ); + buf = this._buffer; + for ( i = fromIndex; i < this._length; i++ ) { + idx = 2 * i; + if ( words[ 0 ] === buf[ idx+indices.HIGH ] && words[ 1 ] === buf[ idx+indices.LOW ] ) { // eslint-disable-line max-len + return i; + } + } + return -1; +}); + +/** +* Returns a new string by concatenating all array elements. +* +* @name join +* @memberof Uint64Array.prototype +* @type {Function} +* @param {string} [separator=','] - element separator +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a string +* @returns {string} string representation +* +* @example +* var arr = new Uint64Array( [ 1, 2, 3 ] ); +* +* var str = arr.join(); +* // returns '1,2,3' +* +* str = arr.join( '/' ); +* // returns '1/2/3' +*/ +setReadOnly( Uint64Array.prototype, 'join', function join( separator ) { + var out; + var buf; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( arguments.length > 0 ) { + if ( !isString( separator ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', separator ) ); + } + } else { + separator = ','; + } + buf = this._buffer; + out = []; + for ( i = 0; i < this._length; i++ ) { + out.push( getUint64( buf, i ).toString() ); + } + return out.join( separator ); +}); + +/** +* Returns an iterator for iterating over each index key in a typed array. +* +* @name keys +* @memberof Uint64Array.prototype +* @type {Function} +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @returns {Iterator} iterator +* +* @example +* var arr = new Uint64Array( [ 1, 2 ] ); +* +* var iter = arr.keys(); +* +* var v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 1 +* +* var bool = iter.next().done; +* // returns true +*/ +setReadOnly( Uint64Array.prototype, 'keys', function keys() { + var self; + var iter; + var len; + var FLG; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + self = this; + 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, + '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.keys(); + } +}); + +/** +* Returns the last index at which a given element can be found. +* +* @name lastIndexOf +* @memberof Uint64Array.prototype +* @type {Function} +* @param {(Uint64|bigint|number)} searchElement - element to find +* @param {integer} [fromIndex] - index at which to start searching backward (inclusive) +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer +* @throws {TypeError} second argument must be an integer +* @returns {integer} index or -1 +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var arr = new Uint64Array( [ 1, 2, 3, 4, 3 ] ); +* +* var idx = arr.lastIndexOf( new Uint64( 3 ) ); +* // returns 4 +* +* idx = arr.lastIndexOf( 3, 3 ); +* // returns 2 +* +* idx = arr.lastIndexOf( 5, 3 ); +* // returns -1 +* +* idx = arr.lastIndexOf( 2n, -3 ); +* // returns 1 +*/ +setReadOnly( Uint64Array.prototype, 'lastIndexOf', function lastIndexOf( searchElement, fromIndex ) { + var words; + var buf; + var idx; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isUint64( searchElement ) ) { + try { + searchElement = new Uint64( searchElement ); + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new TypeError( format( 'invalid argument. First argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', searchElement ) ); + } + } + if ( arguments.length > 1 ) { + if ( !isIntegerPrimitive( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + } + if ( fromIndex >= this._length ) { + fromIndex = this._length - 1; + } else if ( fromIndex < 0 ) { + fromIndex += this._length; + } + } else { + fromIndex = this._length - 1; + } + words = [ 0, 0 ]; + toWords( searchElement, words, 1, 0 ); + buf = this._buffer; + for ( i = fromIndex; i >= 0; i-- ) { + idx = 2 * i; + if ( words[ 0 ] === buf[ idx+indices.HIGH ] && words[ 1 ] === buf[ idx+indices.LOW ] ) { // eslint-disable-line max-len + return i; + } + } + return -1; +}); + /** * Number of array elements. * @@ -758,6 +1524,118 @@ setReadOnlyAccessor( Uint64Array.prototype, 'length', function get() { return this._length; }); +/** +* Returns a new array with each element being the result of a provided callback function. +* +* @name map +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} fcn - callback function +* @param {*} [thisArg] - callback function execution context +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @throws {TypeError} callback must return either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer +* @returns {Uint64Array} 64-bit unsigned integer array +* +* @example +* var add = require( '@stdlib/number/uint64/base/add' ); +* +* function scale( v ) { +* return add( v, v ); +* } +* +* var arr = new Uint64Array( [ 1, 2, 3 ] ); +* +* var out = arr.map( scale ); +* // returns [ 2n, 4n, 6n ] +*/ +setReadOnly( Uint64Array.prototype, 'map', function map( fcn, thisArg ) { + var outbuf; + var words; + var buf; + var out; + var idx; + var i; + var v; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( fcn ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) ); + } + buf = this._buffer; + out = new this.constructor( this._length ); + outbuf = out._buffer; // eslint-disable-line no-underscore-dangle + words = [ 0, 0 ]; + for ( i = 0; i < this._length; i++ ) { + v = fcn.call( thisArg, getUint64( buf, i ), i, this ); + if ( !isUint64( v ) ) { + try { + v = new Uint64( v ); + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new TypeError( format( 'invalid argument. Callback must return either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', v ) ); + } + } + toWords( v, words, 1, 0 ); + idx = 2 * i; + outbuf[ idx+indices.HIGH ] = words[ 0 ]; + outbuf[ idx+indices.LOW ] = words[ 1 ]; + } + return out; +}); + +/** +* Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. +* +* @name reduce +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} reducer - callback function +* @param {*} [initialValue] - initial value +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @throws {Error} if not provided an initial value, the array must have at least one element +* @returns {*} accumulated result +* +* @example +* var add = require( '@stdlib/number/uint64/base/add' ); +* +* var arr = new Uint64Array( [ 1, 2, 3 ] ); +* +* var u = arr.reduce( add ); +* // returns [ 6n ] +*/ +setReadOnly( Uint64Array.prototype, 'reduce', function reduce( reducer, initialValue ) { + var buf; + var acc; + var len; + var v; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( reducer ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); + } + buf = this._buffer; + len = this._length; + if ( arguments.length > 1 ) { + acc = initialValue; + i = 0; + } else { + if ( len === 0 ) { + throw new Error( 'invalid operation. If not provided an initial value, an array must contain at least one element.' ); + } + acc = getUint64( buf, 0 ); + i = 1; + } + for ( ; i < len; i++ ) { + v = getUint64( buf, i ); + acc = reducer( acc, v, i, this ); + } + return acc; +}); + /** * Sets an array element. * diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.copy_within.js b/lib/node_modules/@stdlib/array/uint64/test/test.copy_within.js new file mode 100644 index 000000000000..d1d4ce4b4918 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.copy_within.js @@ -0,0 +1,257 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `copyWithin` method for copying a sequence of array elements within a 64-bit unsigned integer array', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'copyWithin' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.copyWithin ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.copyWithin.call( value, 3, 0 ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance (end)', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.copyWithin.call( value, 3, 0, 5 ); + }; + } +}); + +tape( 'the method copies a sequence of elements within an array', function test( t ) { + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + + arr.copyWithin( 0, 3 ); + + // Overwritten: + t.strictEqual( isEqual( arr.get( 0 ), new Uint64( 3 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 1 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + // Remain the same: + t.strictEqual( isEqual( arr.get( 2 ), new Uint64( 2 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 3 ), new Uint64( 3 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 4 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative target)', function test( t ) { + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + + arr.copyWithin( -arr.length, 3 ); + + // Overwritten: + t.strictEqual( isEqual( arr.get( 0 ), new Uint64( 3 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 1 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + // Remain the same: + t.strictEqual( isEqual( arr.get( 2 ), new Uint64( 2 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 3 ), new Uint64( 3 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 4 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative start)', function test( t ) { + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + + arr.copyWithin( 0, -2 ); + + // Overwritten: + t.strictEqual( isEqual( arr.get( 0 ), new Uint64( 3 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 1 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + // Remain the same: + t.strictEqual( isEqual( arr.get( 2 ), new Uint64( 2 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 3 ), new Uint64( 3 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 4 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (end=length)', function test( t ) { + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + + arr.copyWithin( 0, 3, arr.length ); + + // Overwritten: + t.strictEqual( isEqual( arr.get( 0 ), new Uint64( 3 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 1 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + // Remain the same: + t.strictEqual( isEqual( arr.get( 2 ), new Uint64( 2 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 3 ), new Uint64( 3 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 4 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (non-inclusive end)', function test( t ) { + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + + arr.copyWithin( 2, 0, 2 ); + + // Remain the same: + t.strictEqual( isEqual( arr.get( 0 ), new Uint64( 0 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 1 ), new Uint64( 1 ) ), true, 'returns expected value' ); + + // Overwritten: + t.strictEqual( isEqual( arr.get( 2 ), new Uint64( 0 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 3 ), new Uint64( 1 ) ), true, 'returns expected value' ); + + // Remain the same: + t.strictEqual( isEqual( arr.get( 4 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative end)', function test( t ) { + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + + arr.copyWithin( 2, 0, -3 ); + + // Remain the same: + t.strictEqual( isEqual( arr.get( 0 ), new Uint64( 0 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 1 ), new Uint64( 1 ) ), true, 'returns expected value' ); + + // Overwritten: + t.strictEqual( isEqual( arr.get( 2 ), new Uint64( 0 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 3 ), new Uint64( 1 ) ), true, 'returns expected value' ); + + // Remain the same: + t.strictEqual( isEqual( arr.get( 4 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (target >= length)', function test( t ) { + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + + arr.copyWithin( arr.length, 3 ); + + // Remain the same: + t.strictEqual( isEqual( arr.get( 0 ), new Uint64( 0 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 1 ), new Uint64( 1 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 2 ), new Uint64( 2 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 3 ), new Uint64( 3 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 4 ), new Uint64( 4 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (target > start)', function test( t ) { + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + + arr.copyWithin( 2, 0 ); + + // Remain the same: + t.strictEqual( isEqual( arr.get( 0 ), new Uint64( 0 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 1 ), new Uint64( 1 ) ), true, 'returns expected value' ); + + // Overwritten: + t.strictEqual( isEqual( arr.get( 2 ), new Uint64( 0 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 3 ), new Uint64( 1 ) ), true, 'returns expected value' ); + t.strictEqual( isEqual( arr.get( 4 ), new Uint64( 2 ) ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.every.js b/lib/node_modules/@stdlib/array/uint64/test/test.every.js new file mode 100644 index 000000000000..27db5e4914d3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.every.js @@ -0,0 +1,175 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var isFunction = require( '@stdlib/assert/is-function' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `every` method for returning boolean indicating whether all elements pass a test', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'every' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.every ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + 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 arr.every.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + values = [ + '5', + 3.14, + 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.every( value ); + }; + } +}); + +tape( 'the method returns `true` if operating on an empty 64-bit unsigned integer array', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array(); + bool = arr.every( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns `true` if all elements pass a test', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 2, 2, 2, 2 ] ); + bool = arr.every( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method returns `false` if one or more elements fail a test', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 2, 4, 5, 7 ] ); + bool = arr.every( predicate ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var bool; + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Uint64Array( [ 2, 4, 6 ] ); + bool = arr.every( predicate, ctx ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( isEven( Number( v ) ) ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.fill.js b/lib/node_modules/@stdlib/array/uint64/test/test.fill.js new file mode 100644 index 000000000000..7f8701cc2d63 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.fill.js @@ -0,0 +1,282 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `fill` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'fill' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.fill ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + 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 arr.fill.call( value, new Uint64( 1 ) ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a nonnegative integer, nonnegative bigint, 64-bit unsigned integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + 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 arr.fill( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.fill( new Uint64( 1 ), value ); + }; + } +}); + +tape( 'the method throws an error if provided a third argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.fill( new Uint64( 1 ), 0, value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + var out; + + arr = new Uint64Array(); + out = arr.fill( new Uint64( 1 ) ); + + t.strictEqual( out instanceof Uint64Array, true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Uint64Array( 10 ); + out = arr.fill( new Uint64( 1 ) ); + + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'if called with one argument, the method sets each array element to the provided value', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( 3 ); + expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + arr.fill( new Uint64( 1 ) ); + + t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); + t.end(); +}); + +// tape( 'if called with two arguments, the method sets each array element to the provided value starting from a start index (inclusive)', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), 1 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); + +// tape( 'if called with three arguments, the method sets each array element to the provided value starting from a start index (inclusive) until a specified end index (exclusive)', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), 0, 2 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); + +// tape( 'the method supports negative indices', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), -3, -1 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); + +// tape( 'if a provided start index resolves to a negative index, the method fills an array starting from the first element', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), -10 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); + +// tape( 'if a provided end index resolves to an index exceeding the last array element index, the method fills an array until the last element (inclusive)', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), 1, 10 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); + +// tape( 'if a provided start index resolves to an index which is greater than or equal to a resolved end index, the method does not fill an array', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), 2, 1 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.find.js b/lib/node_modules/@stdlib/array/uint64/test/test.find.js new file mode 100644 index 000000000000..0e486138edbc --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.find.js @@ -0,0 +1,177 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var isFunction = require( '@stdlib/assert/is-function' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `find` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'find' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.find ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + 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 arr.find.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + values = [ + '5', + 3.14, + 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.find( value ); + }; + } +}); + +tape( 'the method returns `undefined` if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + var u; + + arr = new Uint64Array(); + u = arr.find( predicate ); + + t.strictEqual( u, void 0, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the first element which passes a test', function test( t ) { + var arr; + var u; + + arr = new Uint64Array( [ 1, 3, 4, 5 ] ); + u = arr.find( predicate ); + + t.strictEqual( isEqual( u, new Uint64( 4 ) ), true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { + var arr; + var u; + + arr = new Uint64Array( [ 1, 3, 5, 7, 9 ] ); + u = arr.find( predicate ); + + t.strictEqual( u, void 0, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var u; + + ctx = { + 'count': 0 + }; + arr = new Uint64Array( [ 1, 3, 4, 5 ] ); + u = arr.find( predicate, ctx ); + + t.strictEqual( isEqual( u, new Uint64( 4 ) ), true, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( isEven( Number( v ) ) ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.find_index.js b/lib/node_modules/@stdlib/array/uint64/test/test.find_index.js new file mode 100644 index 000000000000..134622ec12d7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.find_index.js @@ -0,0 +1,175 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var isFunction = require( '@stdlib/assert/is-function' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `findIndex` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'findIndex' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.findIndex ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + 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 arr.findIndex.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + values = [ + '5', + 3.14, + 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.findIndex( value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array(); + idx = arr.findIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the index of the first element which passes a test', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 3, 4, 6 ] ); + idx = arr.findIndex( predicate ); + + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method returns `-1` if all elements fail a test', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 3, 5, 7 ] ); + idx = arr.findIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var idx; + + ctx = { + 'count': 0 + }; + arr = new Uint64Array( [ 1, 3, 4, 6 ] ); + idx = arr.findIndex( predicate, ctx ); + + t.strictEqual( idx, 2, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( isEven( Number( v ) ) ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.find_last.js b/lib/node_modules/@stdlib/array/uint64/test/test.find_last.js new file mode 100644 index 000000000000..3960b34d107f --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.find_last.js @@ -0,0 +1,177 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var isFunction = require( '@stdlib/assert/is-function' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `findLast` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'findLast' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.findLast ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + 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 arr.findLast.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + values = [ + '5', + 3.14, + 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.findLast( value ); + }; + } +}); + +tape( 'the method returns `undefined` if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + var u; + + arr = new Uint64Array(); + u = arr.findLast( predicate ); + + t.strictEqual( u, void 0, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the last element which passes a test', function test( t ) { + var arr; + var u; + + arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + u = arr.findLast( predicate ); + + t.strictEqual( isEqual( u, new Uint64( 4 ) ), true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { + var arr; + var u; + + arr = new Uint64Array( [ 1, 3, 5 ] ); + u = arr.findLast( predicate ); + + t.strictEqual( u, void 0, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var u; + + ctx = { + 'count': 0 + }; + arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + u = arr.findLast( predicate, ctx ); + + t.strictEqual( isEqual( u, new Uint64( 4 ) ), true, 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( isEven( Number( v ) ) ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.find_last_index.js b/lib/node_modules/@stdlib/array/uint64/test/test.find_last_index.js new file mode 100644 index 000000000000..21057fc91da7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.find_last_index.js @@ -0,0 +1,175 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var isFunction = require( '@stdlib/assert/is-function' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `findLastIndex` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'findLastIndex' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.findLastIndex ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + 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 arr.findLastIndex.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + values = [ + '5', + 3.14, + 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.findLastIndex( value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array(); + idx = arr.findLastIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the index of the last element which passes a test', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + idx = arr.findLastIndex( predicate ); + + t.strictEqual( idx, 3, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method returns `-1` if all elements fail a test', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 3, 5 ] ); + idx = arr.findLastIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var idx; + + ctx = { + 'count': 0 + }; + arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + idx = arr.findLastIndex( predicate, ctx ); + + t.strictEqual( idx, 3, 'returns expected value' ); + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( isEven( Number( v ) ) ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.for_each.js b/lib/node_modules/@stdlib/array/uint64/test/test.for_each.js new file mode 100644 index 000000000000..69ac83d3f213 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.for_each.js @@ -0,0 +1,201 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `forEach` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'forEach' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.forEach ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + 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 arr.forEach.call( value, fcn ); + }; + } + + function fcn( v ) { + if ( !isUint64( v ) ) { + t.fail( 'should be a 64-bit unsigned integer' ); + } + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + values = [ + '5', + 3.14, + 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.forEach( value ); + }; + } +}); + +tape( 'the method should not invoke a provided callback function if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + + arr = new Uint64Array(); + arr.forEach( fcn ); + + t.end(); + + function fcn() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns `undefined`', function test( t ) { + var arr; + var out; + + arr = new Uint64Array( [ 1, 2, 3, 4 ] ); + out = arr.forEach( fcn ); + + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); + + function fcn( v ) { + if ( !isUint64( v ) ) { + t.fail( 'should be a 64-bit unsigned integer' ); + } + } +}); + +// tape( 'the method invokes a provided function for each element in an array', function test( t ) { // TODO: use isSameUint64Array +// var expected; +// var indices; +// var values; +// var arrays; +// var arr; +// var i; + +// indices = []; +// values = []; +// arrays = []; + +// expected = [ +// new Uint64( 1 ), +// new Uint64( 2 ), +// new Uint64( 3 ), +// new Uint64( 4 ) +// ]; +// arr = new Uint64Array( expected ); +// arr.forEach( fcn ); + +// t.strictEqual( values.length, expected.length, 'returns expected value' ); +// for ( i = 0; i < expected.length; i++ ) { +// t.strictEqual( isUint64( values[ i ] ), true, 'returns expected value' ); +// t.strictEqual( isEqual( values[ i ], expected[ i ] ), true, 'returns expected value' ); +// } +// t.deepEqual( indices, [ 0, 1, 2, 3 ], 'returns expected value' ); +// t.strictEqual( arrays[ 0 ], arr, 'returns expected value' ); +// t.strictEqual( arrays[ 1 ], arr, 'returns expected value' ); +// t.strictEqual( arrays[ 2 ], arr, 'returns expected value' ); +// t.strictEqual( arrays[ 3 ], arr, 'returns expected value' ); + +// t.end(); + +// function fcn( v, i, arr ) { +// values.push( v ); +// indices.push( i ); +// arrays.push( arr ); +// } +// }); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Uint64Array( [ 1, 2, 3 ] ); + arr.forEach( fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function fcn() { + this.count += 1; // eslint-disable-line no-invalid-this + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.includes.js b/lib/node_modules/@stdlib/array/uint64/test/test.includes.js new file mode 100644 index 000000000000..2729a86c3980 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.includes.js @@ -0,0 +1,262 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = 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 Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `includes` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'includes' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.includes ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.includes.call( value, new Uint64( 1 ) ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + '5', + 3.14, + -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.includes( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.includes( new Uint64( 1 ), value ); + }; + } +}); + +tape( 'the method returns `false` if operating on an empty 64-bit unsigned integer array', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array(); + bool = arr.includes( new Uint64( 1 ) ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `false` if a 64-bit unsigned integer is not found', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + bool = arr.includes( new Uint64( 6 ) ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `true` if an array contains a specified 64-bit unsigned integer', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 1, 2, 3, 2 ] ); + bool = arr.includes( new Uint64( 2 ) ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports providing a search element which is a nonnegative integer', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + + bool = arr.includes( 2 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( 4 ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports providing a search element which is a bigint', opts, function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + + bool = arr.includes( BigInt( 2 ) ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( BigInt( 4 ) ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `false` if provided a second argument which exceeds the input array length', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( 10 ); + bool = arr.includes( new Uint64( 0 ), 20 ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + + bool = arr.includes( new Uint64( 2 ), 0 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( new Uint64( 2 ), 2 ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = arr.includes( new Uint64( 3 ), 3 ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index (negative)', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + + bool = arr.includes( new Uint64( 2 ), -5 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( new Uint64( 3 ), -2 ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 1, 2, 3, 4, 5 ] ); + + bool = arr.includes( new Uint64( 2 ), -10 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( new Uint64( 6 ), -10 ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.index_of.js b/lib/node_modules/@stdlib/array/uint64/test/test.index_of.js new file mode 100644 index 000000000000..afe13e499310 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.index_of.js @@ -0,0 +1,265 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = 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 Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `indexOf` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'indexOf' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.indexOf ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.indexOf.call( value, new Uint64( 1 ) ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + '5', + 3.14, + -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.indexOf( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.indexOf( new Uint64( 1 ), value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array(); + idx = arr.indexOf( new Uint64( 1 ) ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if a 64-bit unsigned integer is not found', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( 10 ); + idx = arr.indexOf( new Uint64( 1 ) ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns the index of the first match if an array contains a specified 64-bit unsigned integer', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2 ] ); + idx = arr.indexOf( new Uint64( 2 ) ); + + t.strictEqual( idx, 1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports providing a search element which is a nonnegative integer', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + + idx = arr.indexOf( 2 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( 4 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports providing a search element which is a bigint', opts, function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + + idx = arr.indexOf( BigInt( 2 ) ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( BigInt( 4 ) ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if provided a second argument which exceeds the input array length', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( 10 ); + idx = arr.indexOf( new Uint64( 0 ), 20 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2 ] ); + + idx = arr.indexOf( new Uint64( 2 ), 0 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( new Uint64( 2 ), 2 ); + t.strictEqual( idx, 3, 'returns expected value' ); + + idx = arr.indexOf( new Uint64( 3 ), 3 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index (negative)', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2, 2 ] ); + + idx = arr.indexOf( new Uint64( 2 ), -5 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( new Uint64( 2 ), -2 ); + t.strictEqual( idx, 3, 'returns expected value' ); + + idx = arr.indexOf( new Uint64( 4 ), -2 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2, 2 ] ); + + idx = arr.indexOf( new Uint64( 2 ), -10 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( new Uint64( 4 ), -10 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.join.js b/lib/node_modules/@stdlib/array/uint64/test/test.join.js new file mode 100644 index 000000000000..9dbd1185bc04 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.join.js @@ -0,0 +1,161 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `join` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'join' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.join ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.join.call( value ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `separator` argument which is not a string', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + 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.join( value ); + }; + } +}); + +tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { + var str; + var arr; + + arr = new Uint64Array(); + str = arr.join(); + + t.strictEqual( str, '', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a 64-bit unsigned integer array with elements separated by a separator', function test( t ) { + var expected; + var str; + var arr; + + arr = new Uint64Array( [ 1, 2, 3, 4 ] ); + expected = '1@2@3@4'; + + str = arr.join( '@' ); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a 64-bit unsigned integer array with elements separated by a separator (single element)', function test( t ) { + var expected; + var str; + var arr; + + arr = new Uint64Array( [ 1 ] ); + expected = '1'; + + str = arr.join(); + + t.strictEqual( str, expected, 'returns expected value' ); + + arr = new Uint64Array( [ 1 ] ); + expected = '1'; + + str = arr.join( '@' ); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if method invoked without a separator argument, the method returns a string representation of a 64-bit unsigned integer array with elements separated by a comma', function test( t ) { + var expected; + var str; + var arr; + + arr = new Uint64Array( [ 1, 2, 3, 4 ] ); + expected = '1,2,3,4'; + + str = arr.join(); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.keys.js b/lib/node_modules/@stdlib/array/uint64/test/test.keys.js new file mode 100644 index 000000000000..34f00bc61596 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.keys.js @@ -0,0 +1,256 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `keys` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'keys' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.keys ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.keys.call( value ); + }; + } +}); + +tape( 'the method returns an iterator protocol-compliant object', function test( t ) { + var expected; + var arr; + var it; + var i; + var r; + var e; + + arr = new Uint64Array( [ 1, 2 ] ); + expected = [ + { + 'value': 0, + 'done': false + }, + { + 'value': 1, + 'done': false + }, + { + 'done': true + } + ]; + it = arr.keys(); + + t.strictEqual( typeof it, 'object', 'returns expected value' ); + t.strictEqual( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < expected.length; i++ ) { + r = it.next(); + e = expected[ i ]; + if ( e.value === void 0 ) { + t.deepEqual( r, e, 'returns expected value' ); + } else { + t.strictEqual( r.value, e.value, 'returns expected value' ); + t.strictEqual( r.done, e.done, 'returns expected value' ); + } + } + + t.end(); +}); + +tape( 'the method returns an iterator which does not iterate over empty arrays', function test( t ) { + var expected; + var arr; + var it; + var i; + var v; + + arr = new Uint64Array( [] ); + expected = [ + { + 'done': true + }, + { + 'done': true + }, + { + 'done': true + } + ]; + it = arr.keys(); + + t.strictEqual( typeof it, 'object', 'returns expected value' ); + t.strictEqual( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < expected.length; i++ ) { + v = it.next(); + t.deepEqual( v, expected[ i ], 'returns expected value' ); + } + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var arr; + var it; + var v; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + it = arr.keys(); + + v = it.next(); + t.strictEqual( v.value, 0, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, 1, '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' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var arr; + var it; + var v; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + it = arr.keys(); + + v = it.next(); + t.strictEqual( v.value, 0, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, 1, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.return( 'beep' ); + t.strictEqual( v.value, 'beep', '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 Uint64Array; + var arr; + var it1; + var it2; + var v1; + var v2; + var i; + + Uint64Array = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + arr = new Uint64Array( [ 1, 2, 3, 4 ] ); + + it1 = arr.keys(); + 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( v1, v2, '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 Uint64Array; + var arr; + var it; + + Uint64Array = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + arr = new Uint64Array( [ 1, 2, 3, 4 ] ); + + it = arr.keys(); + t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.last_index_of.js b/lib/node_modules/@stdlib/array/uint64/test/test.last_index_of.js new file mode 100644 index 000000000000..a34a4d837f9d --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.last_index_of.js @@ -0,0 +1,251 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = 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 Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `lastIndexOf` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'lastIndexOf' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.lastIndexOf ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.lastIndexOf.call( value, new Uint64( 1 ) ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + '5', + 3.14, + -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.lastIndexOf( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.lastIndexOf( new Uint64( 1 ), value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array(); + idx = arr.lastIndexOf( new Uint64( 1 ) ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if a 64-bit unsigned integer is not found', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( 10 ); + idx = arr.lastIndexOf( new Uint64( 1 ) ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns the index of the first match when searching from the end of the array if a search element is found', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2 ] ); + idx = arr.lastIndexOf( new Uint64( 2 ) ); + + t.strictEqual( idx, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports providing a search element which is a nonnegative integer', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2 ] ); + + idx = arr.lastIndexOf( 2 ); + t.strictEqual( idx, 3, 'returns expected value' ); + + idx = arr.lastIndexOf( 4 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports providing a search element which is a bigint', opts, function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2 ] ); + + idx = arr.lastIndexOf( BigInt( 2 ) ); + t.strictEqual( idx, 3, 'returns expected value' ); + + idx = arr.lastIndexOf( BigInt( 4 ) ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2, 3 ] ); + + idx = arr.lastIndexOf( new Uint64( 2 ), 4 ); + t.strictEqual( idx, 3, 'returns expected value' ); + + idx = arr.lastIndexOf( new Uint64( 2 ), 2 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.lastIndexOf( new Uint64( 3 ), 1 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index (negative)', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2, 2 ] ); + + idx = arr.lastIndexOf( new Uint64( 2 ), -3 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.lastIndexOf( new Uint64( 3 ), -1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'when the method is provided a starting index which resolves to an index which exceeds the maximum array index, the method searches from the last array element', function test( t ) { + var arr; + var idx; + + arr = new Uint64Array( [ 1, 2, 3, 2, 2 ] ); + + idx = arr.lastIndexOf( new Uint64( 2 ), 10 ); + t.strictEqual( idx, 4, 'returns expected value' ); + + idx = arr.lastIndexOf( new Uint64( 4 ), 10 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.map.js b/lib/node_modules/@stdlib/array/uint64/test/test.map.js new file mode 100644 index 000000000000..9a2e3f9f7f18 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.map.js @@ -0,0 +1,270 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var identity = require( '@stdlib/utils/identity-function' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var add = require( '@stdlib/number/uint64/base/add' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = 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 Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `map` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'map' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.map ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.map.call( value, identity ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.map( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + var out; + + arr = new Uint64Array(); + out = arr.map( identity ); + + t.strictEqual( instanceOf( out, Uint64Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.notEqual( out, arr, 'returns a new instance' ); + t.end(); +}); + +tape( 'the method returns a new 64-bit unsigned integer array containing elements which are the result of a callback function', function test( t ) { + var expected; + var actual; + var arr; + var i; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = [ 2, 4, 6 ]; + actual = arr.map( scale ); + + t.strictEqual( instanceOf( actual, Uint64Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.notEqual( actual, arr, 'returns a new instance' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isEqual( actual.get( i ), new Uint64( expected[ i ] ) ), true, 'returns expected value' ); + } + t.end(); + + function scale( v ) { + return add( v, v ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var expected; + var actual; + var arr; + var ctx; + var i; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = [ 2, 4, 6 ]; + ctx = { + 'count': 0 + }; + actual = arr.map( scale, ctx ); + + t.strictEqual( instanceOf( actual, Uint64Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isEqual( actual.get( i ), new Uint64( expected[ i ] ) ), true, 'returns expected value' ); + } + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); + + function scale( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return add( v, v ); + } +}); + +tape( 'the method supports a map function which returns a nonnegative integer', function test( t ) { + var expected; + var actual; + var arr; + var i; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = [ 2, 4, 6 ]; + actual = arr.map( scale ); + + t.strictEqual( instanceOf( actual, Uint64Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isEqual( actual.get( i ), new Uint64( expected[ i ] ) ), true, 'returns expected value' ); + } + t.end(); + + function scale( v ) { + return Number( v ) * 2; + } +}); + +tape( 'the method supports a map function which returns a bigint', opts, function test( t ) { + var expected; + var actual; + var arr; + var i; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = [ 2, 4, 6 ]; + actual = arr.map( scale ); + + t.strictEqual( instanceOf( actual, Uint64Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isEqual( actual.get( i ), new Uint64( expected[ i ] ) ), true, 'returns expected value' ); + } + t.end(); + + function scale( v ) { + return BigInt( Number( v ) * 2 ); + } +}); + +tape( 'the method throws an error if provided a map function which does not return either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer', function test( t ) { + var clbks; + var arr; + var i; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + clbks = [ + clbk1, + clbk2, + clbk3, + clbk4, + clbk5 + ]; + for ( i = 0; i < clbks.length; i++ ) { + t.throws( badValue( clbks[i] ), TypeError, 'throws an error when provided callback '+i ); + } + t.end(); + + function badValue( clbk ) { + return function badValue() { + return arr.map( clbk ); + }; + } + + function clbk1() { + return -1; + } + + function clbk2() { + return 3.14; + } + + function clbk3() { + return '5'; + } + + function clbk4() { + return {}; + } + + function clbk5() { + return []; + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.reduce.js b/lib/node_modules/@stdlib/array/uint64/test/test.reduce.js new file mode 100644 index 000000000000..07d31060422a --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.reduce.js @@ -0,0 +1,204 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var add = require( '@stdlib/number/uint64/base/add' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `reduce` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'reduce' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.reduce ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.reduce.call( value, add ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 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.reduce( value ); + }; + } +}); + +tape( 'the method throws an error if not provided an initial value when operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + + arr = new Uint64Array( 0 ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + arr.reduce( add ); + } +}); + +tape( 'the method uses the first element of the array as the initial value when an initial value is not provided', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + accArray = [ 1, 3 ]; + valueArray = [ 2, 3 ]; + expected = new Uint64( 6 ); + actual = arr.reduce( reducer ); + + t.strictEqual( isUint64( actual ), true, 'returns expected value' ); + t.strictEqual( isEqual( actual, expected ), true, 'returns expected value' ); + + t.end(); + + function reducer( acc, value, index ) { + var ind = index - 1; + t.strictEqual( isUint64( acc ), true, 'returns expected value' ); + t.strictEqual( isEqual( acc, new Uint64( accArray[ ind ] ) ), true, 'returns expected value' ); + t.strictEqual( isUint64( value ), true, 'returns expected value' ); + t.strictEqual( isEqual( value, new Uint64( valueArray[ ind ] ) ), true, 'returns expected value' ); + return add( acc, value ); + } +}); + +tape( 'the method supports providing an initial value as the second argument', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + accArray = [ 2, 3, 5 ]; + valueArray = [ 1, 2, 3 ]; + expected = new Uint64( 8 ); + actual = arr.reduce( reducer, new Uint64( 2 ) ); + + t.strictEqual( isUint64( actual ), true, 'returns expected value' ); + t.strictEqual( isEqual( actual, expected ), true, 'returns expected value' ); + + t.end(); + + function reducer( acc, value, index ) { + t.strictEqual( isUint64( acc ), true, 'returns expected value' ); + t.strictEqual( isEqual( acc, new Uint64( accArray[ index ] ) ), true, 'returns expected value' ); + t.strictEqual( isUint64( value ), true, 'returns expected value' ); + t.strictEqual( isEqual( value, new Uint64( valueArray[ index ] ) ), true, 'returns expected value' ); + return add( acc, value ); + } +}); + +tape( 'the method returns the accumulated result', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = new Uint64( 6 ); + actual = arr.reduce( add ); + + t.strictEqual( isUint64( actual ), true, 'returns expected value' ); + t.strictEqual( isEqual( actual, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports returning real-valued results', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = 6; + actual = arr.reduce( reducer, 0 ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value ) { + return acc + Number( value ); + } +});