Skip to content
Merged
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
39 changes: 37 additions & 2 deletions lib/node_modules/@stdlib/array/uint64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ var arr = Uint64Array.from( [ 1, 2 ], mapFcn );
A callback function is provided two arguments:

- **value**: source value.
- **index**: source index..
- **index**: source index.

To set the callback execution context, provide a `thisArg`.

Expand Down Expand Up @@ -243,6 +243,41 @@ var arr = Uint64Array.of( 1, 2 );
// returns <Uint64Array>[ 1n, 2n ]
```

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

#### Uint64Array.prototype.at( i )

Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer positions.

```javascript
var arr = new Uint64Array( 10 );

// Set the first, second, and last elements:
arr.set( 1, 0 );
arr.set( 2, 1 );
arr.set( 9, 9 );

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

// Get the last element:
z = arr.at( -1 );
// returns <Uint64>[ 9n ]
```

If provided an out-of-bounds index, the method returns `undefined`.

```javascript
var arr = new Uint64Array( 10 );

var z = arr.at( 100 );
// returns undefined

z = arr.at( -100 );
// returns undefined
```

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

#### Uint64Array.prototype.get( i )
Expand Down Expand Up @@ -391,7 +426,7 @@ var arr = [
out = new Uint64Array( arr );
logEach( '%s', out );

// Create a 64-bit unsigned integer array from an typed array:
// Create a 64-bit unsigned integer array from a typed array:
arr = new Uint32Array( [ 1, 2, 3, 4 ] );
out = new Uint64Array( arr );
logEach( '%s', out );
Expand Down
87 changes: 87 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.at.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* @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 isUint64 = require( '@stdlib/assert/is-uint64' );
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var pkg = require( './../package.json' ).name;
var Uint64Array = require( './../lib' );


// MAIN //

bench( format( '%s::nonnegative_indices:at', pkg ), function benchmark( b ) {
var arr;
var N;
var u;
var i;

arr = [];
for ( i = 0; i < 10; i++ ) {
arr.push( new Uint64( i ) );
}
arr = new Uint64Array( arr );
N = arr.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
u = arr.at( i%N );
if ( typeof u !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isUint64( u ) ) {
b.fail( 'should return a 64-bit unsigned integer' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::negative_indices:at', pkg ), function benchmark( b ) {
var arr;
var N;
var u;
var i;

arr = [];
for ( i = 0; i < 10; i++ ) {
arr.push( new Uint64( i ) );
}
arr = new Uint64Array( arr );
N = arr.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
u = arr.at( -(i%N)-1 );
if ( typeof u !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isUint64( u ) ) {
b.fail( 'should return a 64-bit unsigned integer' );
}
b.pass( 'benchmark finished' );
b.end();
});
25 changes: 25 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,31 @@
5


{{alias}}.prototype.at( i )
Returns an array element located at integer position (index) `i`, with
support for both nonnegative and negative integer positions.

If provided an index outside the array index range, the method returns
`undefined`.

Parameters
----------
i: integer
Element index.

Returns
-------
out: Uint64|void
Array element or `undefined`.

Examples
--------
> var arr = new {{alias}}( [ 1, 2 ] )
<Uint64Array>[ 1n, 2n ]
> var z = arr.at( 1 )
<Uint64>[ 2n ]


{{alias}}.prototype.get( i )
Returns an array element located at integer position (index) `i`.

Expand Down
27 changes: 27 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 @@ -399,6 +399,33 @@ declare class Uint64Array implements Uint64ArrayInterface {
*/
readonly length: number;

/**
* Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer indices.
*
* @param i - element index
* @throws index argument must be an integer
* @returns array element
*
* @example
* var arr = new Uint64Array( 10 );
*
* var u = arr.at( 0 );
* // returns <Uint64>[ 0n ]
*
* arr.set( 1, 0 );
* arr.set( 9, 9 );
*
* u = arr.at( -1 );
* // returns <Uint64>[ 9n ]
*
* u = arr.at( 100 );
* // returns undefined
*
* u = arr.at( -100 );
* // returns undefined
*/
at( i: number ): Uint64 | void;

/**
* Returns an array element.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/array/uint64/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var arr = [
out = new Uint64Array( arr );
logEach( '%s', out );

// Create a 64-bit unsigned integer array from an typed array:
// Create a 64-bit unsigned integer array from a typed array:
arr = new Uint32Array( [ 1, 2, 3, 4 ] );
out = new Uint64Array( arr );
logEach( '%s', out );
Expand Down
49 changes: 49 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,55 @@
return new this( args );
});

/**
* Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer indices.
*
* @name at
* @memberof Uint64Array.prototype
* @type {Function}
* @param {integer} idx - element index
* @throws {TypeError} `this` must be a 64-bit unsigned integer array
* @throws {TypeError} must provide an integer
* @returns {(Uint64|void)} array element
*
* @example
* var arr = new Uint64Array( 10 );
*
* var u = arr.at( 0 );
* // returns <Uint64>[ 0n ]
*
* arr.set( 1, 0 );
* arr.set( 2, 1 );
* arr.set( 9, 9 );
*
* u = arr.at( 0 );
* // returns <Uint64>[ 1n ]
*
* u = arr.at( -1 );
* // returns <Uint64>[ 9n ]
*
* u = arr.at( 100 );
* // returns undefined
*
* u = arr.at( -100 );
* // returns undefined
*/
setReadOnly( Uint64Array.prototype, 'at', function at( idx ) {
if ( !isUint64Array( this ) ) {
throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' );
}
if ( !isInteger( idx ) ) {
throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) );
}
if ( idx < 0 ) {
idx += this._length;
}
if ( idx < 0 || idx >= this._length ) {
return;
}
return getUint64( this._buffer, idx );
});

/**
* Pointer to the underlying data buffer.
*
Expand Down Expand Up @@ -685,7 +734,7 @@
buf[ idx+indices.LOW ] = words[ 1 ];
return;
}
if ( isNonNegativeInteger( value ) || ( isBigInt( value ) && isNonNegativeInteger( Number( value ) ) ) ) {

Check warning on line 737 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 Expand Up @@ -748,7 +797,7 @@
// We need to copy source values...
tmp = new Uint32Array( sbuf.length );
for ( i = 0; i < sbuf.length; i++ ) {
tmp[ i ] = sbuf[ i ]; // TODO: handle accessor arrays

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

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: handle accessor arrays'
}
sbuf = tmp;
}
Expand Down
Loading