Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,19 @@ var u = arr.get( 100 );
// returns undefined
```

<a name="method-reverse"></a>

#### Uint64Array.prototype.reverse()

Reverses an array in-place.

```javascript
var arr = new Uint64Array( [ 1, 2, 3 ] );

var out = arr.reverse();
// returns <Uint64Array>[ 3n, 2n, 1n ]
```

<a name="method-set"></a>

#### Uint64Array.prototype.set( value\[, i] )
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
});
Original file line number Diff line number Diff line change
@@ -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();
17 changes: 17 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,23 @@
<Uint64>[ 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()
<Uint64Array>[ 3n, 2n, 1n ]


{{alias}}.prototype.set( v[, i] )
Sets one or more array elements.

Expand Down
13 changes: 13 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import ArrayBuffer = require( '@stdlib/array/buffer' );

// Define a union type representing both iterable and non-iterable iterators:
type Iterator = Iter | IterableIterator;

Check failure on line 31 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'Iterator' is defined but never used

// Define a type representing a value from which a 64-bit unsigned integer can be derived:
type Uint = Uint64 | bigint | number;
Expand All @@ -36,7 +36,7 @@
/**
* Locale-specific configuration options.
*/
interface LocaleOptions<T = unknown> {

Check failure on line 39 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'LocaleOptions' is defined but never used
/**
* Configuration property.
*/
Expand Down Expand Up @@ -118,7 +118,7 @@
* @param arr - array on which the method was called
* @returns boolean indicating whether an element in an array passes a test
*/
type Predicate<U> = NullaryPredicate<U> | UnaryPredicate<U> | BinaryPredicate<U> | TernaryPredicate<U>;

Check failure on line 121 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'Predicate' is defined but never used

/**
* Callback invoked for each element in an array.
Expand Down Expand Up @@ -162,7 +162,7 @@
* @param arr - array on which the method was called
* @returns undefined
*/
type Callback<U> = NullaryCallback<U> | UnaryCallback<U> | BinaryCallback<U> | TernaryCallback<U>;

Check failure on line 165 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'Callback' is defined but never used

/**
* Callback invoked for each element in an array.
Expand Down Expand Up @@ -206,7 +206,7 @@
* @param arr - array on which the method was called
* @returns transformed value
*/
type MapFcn<U> = NullaryMapFcn<U> | UnaryMapFcn<U> | BinaryMapFcn<U> | TernaryMapFcn<U>;

Check failure on line 209 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'MapFcn' is defined but never used

/**
* Reducer function invoked for each element in an array.
Expand Down Expand Up @@ -260,7 +260,7 @@
* @param arr - array on which the method was called
* @returns accumulated result
*/
type Reducer<U> = NullaryReducer<U> | UnaryReducer<U> | BinaryReducer<U> | TernaryReducer<U> | QuaternaryReducer<U>;

Check failure on line 263 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'Reducer' is defined but never used

/**
* Comparator function.
Expand All @@ -269,7 +269,7 @@
* @param b - second value for comparison
* @returns number indicating comparison result
*/
type CompareFcn = ( a: Uint64, b: Uint64 ) => number;

Check failure on line 272 in lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'CompareFcn' is defined but never used

/**
* Class for creating a 64-bit unsigned integer array.
Expand Down Expand Up @@ -477,6 +477,19 @@
*/
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 <Uint64Array>[ 3n, 2n, 1n ]
*/
reverse(): Uint64Array;

/**
* Sets an array element.
*
Expand Down
41 changes: 41 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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' );
Expand Down Expand Up @@ -758,6 +759,46 @@
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 <Uint64Array>[ 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.
*
Expand Down Expand Up @@ -839,7 +880,7 @@
buf[ idx+indices.LOW ] = words[ 1 ];
return;
}
if ( isNonNegativeInteger( value ) || ( isBigInt( value ) && isNonNegativeInteger( Number( value ) ) ) ) {

Check warning on line 883 in lib/node_modules/@stdlib/array/uint64/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 110. Maximum allowed is 80
if ( idx >= this._length ) {
throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) );
}
Expand Down
116 changes: 116 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/test/test.reverse.js
Original file line number Diff line number Diff line change
@@ -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();
});
Loading