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
50 changes: 50 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,56 @@ 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.

<a name="method-find-index"></a>

#### 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
```

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

#### Uint64Array.prototype.get( i )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var isUint64 = require( '@stdlib/assert/is-uint64' );
var pkg = require( './../package.json' ).name;
var Uint64Array = require( './../lib' );


// MAIN //

bench( format( '%s:findIndex', pkg ), function benchmark( b ) {
var arr;
var idx;
var i;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
idx = arr.findIndex( predicate );
if ( typeof idx !== 'number' ) {
b.fail( 'should return an integer' );
}
}
b.toc();
if ( !isInteger( idx ) ) {
b.fail( 'should return an integer' );
}
b.pass( 'benchmark finished' );
b.end();

function predicate( v ) {
return isUint64( v );
}
});
Original file line number Diff line number Diff line change
@@ -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 format = require( '@stdlib/string/format' );
var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var Number = require( '@stdlib/number/ctor' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var Uint64Array = require( './../lib' );


// FUNCTIONS //

/**
* Predicate function.
*
* @private
* @param {Uint64} value - array element
* @param {NonNegativeInteger} idx - array element index
* @param {Uint64Array} arr - array instance
* @returns {boolean} boolean indicating whether a value passes a test
*/
function predicate( value ) {
return ( isEven( Number( value ) ) );
}

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var arr;

arr = new Uint64Array( len );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var idx;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
idx = arr.findIndex( predicate );
if ( typeof idx !== 'number' ) {
b.fail( 'should return an integer' );
}
}
b.toc();
if ( !isInteger( idx ) ) {
b.fail( 'should return an integer' );
}
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();
35 changes: 35 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,41 @@
true


{{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}}( {{alias:@stdlib/number/ctor}}( v ) ) ); };
> var arr = new {{alias}}( [ 1, 3, 4, 6 ] )
<Uint64Array>[ 1n, 3n, 4n, 6n ]
> var idx = arr.findIndex( predicate )
2


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

Expand Down
22 changes: 22 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 @@ -459,6 +459,28 @@ declare class Uint64Array implements Uint64ArrayInterface {
*/
entries(): TypedIterator<[number, Uint64]>;

/**
* 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<U = unknown>( predicate: Predicate<U>, thisArg?: ThisParameterType<Predicate<U>> ): number;

/**
* Returns an array element.
*
Expand Down
45 changes: 45 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,51 @@
}
});

/**
* 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 an array element.
*
Expand Down Expand Up @@ -846,7 +891,7 @@
buf[ idx+indices.LOW ] = words[ 1 ];
return;
}
if ( isNonNegativeInteger( value ) || ( isBigInt( value ) && isNonNegativeInteger( Number( value ) ) ) ) {

Check warning on line 894 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 @@ -909,7 +954,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 957 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