diff --git a/lib/node_modules/@stdlib/array/uint64/README.md b/lib/node_modules/@stdlib/array/uint64/README.md index 02da19409141..70d98f9523af 100644 --- a/lib/node_modules/@stdlib/array/uint64/README.md +++ b/lib/node_modules/@stdlib/array/uint64/README.md @@ -335,6 +335,19 @@ var u = arr.get( 100 ); // returns undefined ``` + + +#### Uint64Array.prototype.reverse() + +Reverses an array in-place. + +```javascript +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var out = arr.reverse(); +// returns [ 3n, 2n, 1n ] +``` + #### Uint64Array.prototype.set( value\[, i] ) diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reverse.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reverse.js new file mode 100644 index 000000000000..729efcf03205 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reverse.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:reverse', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., every element pair is swapped in-place)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reverse(); + 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.reverse.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reverse.length.js new file mode 100644 index 000000000000..1e1a73a043b9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reverse.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., every element pair is swapped in-place)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reverse(); + 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:reverse:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index c737fc5bf588..02b7370db81f 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -299,6 +299,23 @@ [ 2n ] +{{alias}}.prototype.reverse() + Reverses the array *in-place*. + + This method mutates the array on which the method is invoked. + + Returns + ------- + out: Uint64Array + Modified array. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3 ] ); + > arr.reverse() + [ 3n, 2n, 1n ] + + {{alias}}.prototype.set( v[, i] ) Sets one or more array elements. diff --git a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts index 78b11c503625..dffaca90c398 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 @@ -477,6 +477,19 @@ declare class Uint64Array implements Uint64ArrayInterface { */ get( i: number ): Uint64 | void; + /** + * Reverses an array in-place. + * + * @returns reversed array + * + * @example + * var arr = new Uint64Array( [ 1, 2, 3 ] ); + * + * var out = arr.reverse(); + * // returns [ 3n, 2n, 1n ] + */ + reverse(): Uint64Array; + /** * Sets an array element. * diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 684cb8e4b9bd..cfabe0e55228 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -32,6 +32,7 @@ var isObject = require( '@stdlib/assert/is-object' ); var isFunction = require( '@stdlib/assert/is-function' ); var isUint64 = require( '@stdlib/assert/is-uint64' ); var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +var floor = require( '@stdlib/math/base/special/floor' ); var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); @@ -758,6 +759,46 @@ setReadOnlyAccessor( Uint64Array.prototype, 'length', function get() { return this._length; }); +/** +* Reverses an array in-place. +* +* @name reverse +* @memberof Uint64Array.prototype +* @type {Function} +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @returns {Uint64Array} reversed array +* +* @example +* var arr = new Uint64Array( [ 1, 2, 3 ] ); +* +* var out = arr.reverse(); +* // returns [ 3n, 2n, 1n ] +*/ +setReadOnly( Uint64Array.prototype, 'reverse', function reverse() { + var buf; + var tmp; + var len; + var N; + var i; + var j; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + len = this._length; + buf = this._buffer; + N = floor( len / 2 ); + for ( i = 0; i < N; i++ ) { + j = len - i - 1; + tmp = buf[ (2*i)+indices.HIGH ]; + buf[ (2*i)+indices.HIGH ] = buf[ (2*j)+indices.HIGH ]; + buf[ (2*j)+indices.HIGH ] = tmp; + tmp = buf[ (2*i)+indices.LOW ]; + buf[ (2*i)+indices.LOW ] = buf[ (2*j)+indices.LOW ]; + buf[ (2*j)+indices.LOW ] = tmp; + } + return this; +}); + /** * Sets an array element. * diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.reverse.js b/lib/node_modules/@stdlib/array/uint64/test/test.reverse.js new file mode 100644 index 000000000000..78c248bc4543 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.reverse.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `reverse` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'reverse' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.reverse ), 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.reverse.call( 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.reverse(); + + t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method reverses elements of a 64-bit unsigned integer array in-place', function test( t ) { + var expected; + var arr; + var out; + var i; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = [ 3, 2, 1 ]; + out = arr.reverse(); + + t.strictEqual( instanceOf( arr, Uint64Array ), true, 'returns expected value' ); + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( isEqual( arr.get( i ), new Uint64( expected[ i ] ) ), true, '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.reverse(); + + t.strictEqual( out.length, 10, 'returns expected value' ); + t.end(); +});