Skip to content
97 changes: 97 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,103 @@ u = arr.at( -100 );
// returns undefined
```

<a name="method-copy-within"></a>

#### Uint64Array.prototype.copyWithin( target, start\[, end] )

Copies a sequence of elements within the array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`.

```javascript
var Uint64 = require( '@stdlib/number/uint64/ctor' );

var arr = new Uint64Array( 4 );

// Set the array elements:
arr.set( 1, 0 );
arr.set( 2, 1 );
arr.set( 3, 2 );
arr.set( 4, 3 );

// Get the first array element:
var z = arr.get( 0 );
// returns <Uint64>[ 1n ]

// Get the second array element:
z = arr.get( 1 );
// returns <Uint64>[ 2n ]

// Copy the last two elements to the first two elements:
arr.copyWithin( 0, 2 );

// Get the first array element:
z = arr.get( 0 );
// returns <Uint64>[ 3n ]

// Get the second array element:
z = arr.get( 1 );
// returns <Uint64>[ 4n ]
```

By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument.

```javascript
var Uint64 = require( '@stdlib/number/uint64/ctor' );

var arr = new Uint64Array( 4 );

// Set the array elements:
arr.set( 1, 0 );
arr.set( 2, 1 );
arr.set( 3, 2 );
arr.set( 4, 3 );

// Get the third array element:
var z = arr.get( 2 );
// returns <Uint64>[ 3n ]

// Get the last array element:
z = arr.get( 3 );
// returns <Uint64>[ 4n ]

// Copy the first two elements to the last two elements:
arr.copyWithin( 2, 0, 2 );

// Get the third array element:
z = arr.get( 2 );
// returns <Uint64>[ 1n ]

// Get the last array element:
z = arr.get( 3 );
// returns <Uint64>[ 2n ]
```

When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example:

```javascript
var Uint64 = require( '@stdlib/number/uint64/ctor' );

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

// Get the third array element:
var z = arr.get( 2 );
// returns <Uint64>[ 3n ]

// Get the last array element:
z = arr.get( 3 );
// returns <Uint64>[ 4n ]

// Copy the first two elements to the last two elements using negative indices:
arr.copyWithin( -2, -4, -2 );

// Get the third array element:
z = arr.get( 2 );
// returns <Uint64>[ 1n ]

// Get the last array element:
z = arr.get( 3 );
// returns <Uint64>[ 2n ]
```

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

#### Uint64Array.prototype.entries()
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: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();
});
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., 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();
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
29 changes: 29 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,35 @@
<Uint64>[ 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 )
<Uint64Array>[ 3n, 4n, 3n, 4n ]
> var z = arr.get( 0 )
<Uint64>[ 3n ]


{{alias}}.prototype.entries()
Returns an iterator for iterating over array key-value pairs.

Expand Down
19 changes: 19 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 @@ -426,6 +426,25 @@
*/
at( i: number ): Uint64 | void;

/**
* Copies a sequence of elements within the array to the position starting at `target`.
*
* @param target - index at which to start copying elements
* @param start - source index at which to copy elements from
* @param end - source index at which to stop copying elements from
* @returns modified array
*
* @example
* var Uint64 = require( '@stdlib/number/uint64/ctor' );
*
* var arr = new Uint64Array( [ 1, 2, 3, 4 ] );
*
* // Copy the first two elements to the last two elements:
* arr.copyWithin( 2, 0, 2 );
* // arr => <Uint64Array>[ 1n, 2n, 1n, 2n ]
*/
copyWithin( target: number, start: number, end?: number ): Uint64Array;

/**
* Returns an iterator for iterating over array key-value pairs.
*
Expand Down
34 changes: 34 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,40 @@
*/
setReadOnly( Uint64Array.prototype, 'BYTES_PER_ELEMENT', Uint64Array.BYTES_PER_ELEMENT );

/**
* Copies a sequence of elements within the array to the position starting at `target`.
*
* @name copyWithin
* @memberof Uint64Array.prototype
* @type {Function}
* @param {integer} target - index at which to start copying elements
* @param {integer} start - source index at which to copy elements from
* @param {integer} [end] - source index at which to stop copying elements from
* @throws {TypeError} `this` must be a 64-bit unsigned integer array
* @returns {Uint64Array} modified array
*
* @example
* var Uint64 = require( '@stdlib/number/uint64/ctor' );
*
* var arr = new Uint64Array( [ 1, 2, 3, 4 ] );
*
* // Copy the first two elements to the last two elements:
* arr.copyWithin( 2, 0, 2 );
* // arr => <Uint64Array>[ 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

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

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: prefer a functional `copyWithin`...'
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.
*
Expand Down Expand Up @@ -839,7 +873,7 @@
buf[ idx+indices.LOW ] = words[ 1 ];
return;
}
if ( isNonNegativeInteger( value ) || ( isBigInt( value ) && isNonNegativeInteger( Number( value ) ) ) ) {

Check warning on line 876 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
Loading
Loading