diff --git a/lib/node_modules/@stdlib/array/uint64/README.md b/lib/node_modules/@stdlib/array/uint64/README.md index 02da19409141..c7e6bff808b1 100644 --- a/lib/node_modules/@stdlib/array/uint64/README.md +++ b/lib/node_modules/@stdlib/array/uint64/README.md @@ -278,6 +278,40 @@ 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 arr = new Uint64Array( [ 1, 2, 3, 4 ] ); + +// Copy the last two elements to the first two elements: +arr.copyWithin( 0, 2 ); +// arr => [ 3n, 4n, 3n, 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 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 ] +``` + +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 arr = new Uint64Array( [ 1, 2, 3, 4 ] ); + +// Copy the first two elements to the last two elements using negative indices: +arr.copyWithin( -2, -4, -2 ); +// arr => [ 1n, 2n, 1n, 2n ] +``` + #### Uint64Array.prototype.entries() @@ -309,6 +343,298 @@ 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]] ) + +Fills an array from a `start` index to an `end` index (non-inclusive) with a provided `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 ) ); +// arr => [ 1n, 1n, 1n ] + +// Fill all elements starting from the second element: +arr.fill( new Uint64( 2 ), 1 ); +// arr => [ 1n, 2n, 2n ] + +// Fill all elements from first element until the second-to-last element: +arr.fill( new Uint64( 3 ), 0, 2 ); +// arr => [ 3n, 3n, 2n ] +``` + +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 ); +// arr => [ 1n, 1n, 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.get( 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.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/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index c737fc5bf588..c62b58cce074 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -252,6 +252,33 @@ [ 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 ] + + {{alias}}.prototype.entries() Returns an iterator for iterating over array key-value pairs. @@ -275,6 +302,206 @@ 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-even}}.isPrimitive( {{alias:@stdlib/number/ctor}}( v ) ) ); }; + > var arr = new {{alias}}( [ 2, 4, 6 ] ); + > var bool = arr.every( predicate ) + true + + +{{alias}}.prototype.fill( value[, start[, end]] ) + Fills an array from a start index to an end index (non-inclusive) with a + provided 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 ) + [ 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 ] ); + > 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 ] ); + > var u = arr.findLast( predicate ) + [ 4n ] + + {{alias}}.prototype.get( i ) Returns an array element located at integer position (index) `i`. 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..850e9cbc8282 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,23 @@ declare class Uint64Array implements Uint64ArrayInterface { */ at( i: number ): Uint64 | void; + /** + * Copies a sequence of elements within the array starting at `start` and ending at `end` (non-inclusive) 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 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 +471,136 @@ 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; + + /** + * Fills an array from a `start` index to an `end` index (non-inclusive) with a provided `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 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..05d2bc8e94d0 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -597,6 +597,38 @@ setReadOnlyAccessor( Uint64Array.prototype, 'byteOffset', function get() { */ setReadOnly( Uint64Array.prototype, 'BYTES_PER_ELEMENT', Uint64Array.BYTES_PER_ELEMENT ); +/** +* Copies a sequence of elements within the array starting at `start` and ending at `end` (non-inclusive) 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 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 +734,310 @@ 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; +}); + +/** +* Fills an array from a `start` index to an `end` index (non-inclusive) with a provided `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; + var v; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + v = scalarToUint64( value ); + if ( v instanceof Error ) { + 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( v, 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 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..e30f8d4cbda2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.copy_within.js @@ -0,0 +1,206 @@ +/** +* @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 isEqualUint64Array = require( '@stdlib/assert/is-equal-uint64array' ); +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 `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 expected; + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + expected = new Uint64Array( [ 3, 4, 2, 3, 4 ] ); + + arr.copyWithin( 0, 3 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative target)', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + expected = new Uint64Array( [ 3, 4, 2, 3, 4 ] ); + + arr.copyWithin( -arr.length, 3 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative start)', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + expected = new Uint64Array( [ 3, 4, 2, 3, 4 ] ); + + arr.copyWithin( 0, -2 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (end=length)', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + expected = new Uint64Array( [ 3, 4, 2, 3, 4 ] ); + + arr.copyWithin( 0, 3, arr.length ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (non-inclusive end)', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + expected = new Uint64Array( [ 0, 1, 0, 1, 4 ] ); + + arr.copyWithin( 2, 0, 2 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative end)', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + expected = new Uint64Array( [ 0, 1, 0, 1, 4 ] ); + + arr.copyWithin( 2, 0, -3 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (target >= length)', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + expected = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + + arr.copyWithin( arr.length, 3 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (target > start)', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( [ 0, 1, 2, 3, 4 ] ); + expected = new Uint64Array( [ 0, 1, 0, 1, 2 ] ); + + arr.copyWithin( 2, 0 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), 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..329f52a8d0b9 --- /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 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.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..e5a77714a41d --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.fill.js @@ -0,0 +1,318 @@ +/** +* @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 isEqualUint64Array = require( '@stdlib/assert/is-equal-uint64array' ); +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 `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 Uint64Array( [ 1, 1, 1 ] ); + + arr.fill( new Uint64( 1 ) ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports providing a fill value which is a nonnegative integer', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( 3 ); + expected = new Uint64Array( [ 1, 1, 1 ] ); + + arr.fill( 1 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports providing a fill value which is a bigint', opts, function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( 3 ); + expected = new Uint64Array( [ 1, 1, 1 ] ); + + arr.fill( BigInt( 1 ) ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, '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 Uint64Array( [ 0, 1, 1 ] ); + + arr.fill( new Uint64( 1 ), 1 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, '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 Uint64Array( [ 1, 1, 0 ] ); + + arr.fill( new Uint64( 1 ), 0, 2 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports negative indices', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( 3 ); + expected = new Uint64Array( [ 1, 1, 0 ] ); + + arr.fill( new Uint64( 1 ), -3, -1 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, '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 Uint64Array( [ 1, 1, 1 ] ); + + arr.fill( new Uint64( 1 ), -10 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, '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 Uint64Array( [ 0, 1, 1 ] ); + + arr.fill( new Uint64( 1 ), 1, 10 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, '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 Uint64Array( [ 0, 0, 0 ] ); + + arr.fill( new Uint64( 1 ), 2, 1 ); + + t.strictEqual( isEqualUint64Array( arr, expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.filter.js b/lib/node_modules/@stdlib/array/uint64/test/test.filter.js new file mode 100644 index 000000000000..6b9c72dc6885 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.filter.js @@ -0,0 +1,185 @@ +/** +* @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 isEqualUint64Array = require( '@stdlib/assert/is-equal-uint64array' ); +var isEven = require( '@stdlib/assert/is-even' ).isPrimitive; +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +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 `filter` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'filter' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.filter ), 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.filter.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( 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.filter( 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.filter( predicate ); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method returns a new 64-bit unsigned integer array containing only those elements which satisfy a test condition', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3, 4, 5, 6 ] ); + expected = new Uint64Array( [ 2, 4, 6 ] ); + actual = arr.filter( predicate ); + + t.strictEqual( instanceOf( actual, Uint64Array ), true, 'returns expected value' ); + t.strictEqual( isEqualUint64Array( actual, expected ), true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method copies all elements to a new array if all elements satisfy a test condition', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 2, 4, 6 ] ); + expected = new Uint64Array( [ 2, 4, 6 ] ); + actual = arr.filter( predicate ); + + t.strictEqual( instanceOf( actual, Uint64Array ), true, 'returns expected value' ); + t.notEqual( actual, arr, 'returns a new instance' ); + t.strictEqual( isEqualUint64Array( actual, expected ), true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var expected; + var actual; + var arr; + var ctx; + + arr = new Uint64Array( [ 1, 2, 3, 4, 5, 6 ] ); + expected = new Uint64Array( [ 2, 4, 6 ] ); + ctx = { + 'count': 0 + }; + actual = arr.filter( predicate, ctx ); + + t.strictEqual( instanceOf( actual, Uint64Array ), true, 'returns expected value' ); + t.strictEqual( isEqualUint64Array( actual, expected ), true, 'returns expected value' ); + t.strictEqual( ctx.count, 6, '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.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 ) ) ); + } +});