Skip to content

Commit 27c19a0

Browse files
committed
Auto-generated commit
1 parent bd83d3a commit 27c19a0

8 files changed

Lines changed: 528 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`cfe86c9`](https://github.com/stdlib-js/stdlib/commit/cfe86c904c8444366325368310ff1b032af7f47b) - add `findIndex` method to `array/uint64` [(#14298)](https://github.com/stdlib-js/stdlib/pull/14298)
1314
- [`2e62f0a`](https://github.com/stdlib-js/stdlib/commit/2e62f0a06fdcc2be4edb82b137eff0b635cdedc6) - add `find` method to `array/uint64` [(#14270)](https://github.com/stdlib-js/stdlib/pull/14270)
1415
- [`fe61b90`](https://github.com/stdlib-js/stdlib/commit/fe61b90b220779f628444d8cefd9ef0d7751faae) - add `filter` method to `array/uint64` [(#14251)](https://github.com/stdlib-js/stdlib/pull/14251)
1516
- [`21f4296`](https://github.com/stdlib-js/stdlib/commit/21f4296680152d58a4372c021b66a91bd566c304) - add `fill` method to `array/uint64` [(#14173)](https://github.com/stdlib-js/stdlib/pull/14173)
@@ -113,6 +114,7 @@ A total of 2 issues were closed in this release:
113114

114115
<details>
115116

117+
- [`cfe86c9`](https://github.com/stdlib-js/stdlib/commit/cfe86c904c8444366325368310ff1b032af7f47b) - **feat:** add `findIndex` method to `array/uint64` [(#14298)](https://github.com/stdlib-js/stdlib/pull/14298) _(by Divit Jain, Athan Reines)_
116118
- [`2e62f0a`](https://github.com/stdlib-js/stdlib/commit/2e62f0a06fdcc2be4edb82b137eff0b635cdedc6) - **feat:** add `find` method to `array/uint64` [(#14270)](https://github.com/stdlib-js/stdlib/pull/14270) _(by Divit Jain, Athan Reines)_
117119
- [`fe61b90`](https://github.com/stdlib-js/stdlib/commit/fe61b90b220779f628444d8cefd9ef0d7751faae) - **feat:** add `filter` method to `array/uint64` [(#14251)](https://github.com/stdlib-js/stdlib/pull/14251) _(by Divit Jain, Athan Reines)_
118120
- [`21f4296`](https://github.com/stdlib-js/stdlib/commit/21f4296680152d58a4372c021b66a91bd566c304) - **feat:** add `fill` method to `array/uint64` [(#14173)](https://github.com/stdlib-js/stdlib/pull/14173) _(by Divit Jain, Athan Reines)_

‎uint64/README.md‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,56 @@ var count = context.count;
533533
// returns 3
534534
```
535535

536+
<a name="method-find-index"></a>
537+
538+
#### Uint64Array.prototype.findIndex( predicate\[, thisArg] )
539+
540+
Returns the index of the first element in an array for which a predicate function returns a truthy value.
541+
542+
```javascript
543+
var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
544+
var Number = require( '@stdlib/number/ctor' );
545+
546+
function predicate( v ) {
547+
return ( isEven( Number( v ) ) );
548+
}
549+
550+
var arr = new Uint64Array( [ 1, 3, 4, 6 ] );
551+
552+
var idx = arr.findIndex( predicate );
553+
// returns 2
554+
```
555+
556+
The `predicate` function is provided three arguments:
557+
558+
- **value**: current array element.
559+
- **index**: current array element index.
560+
- **arr**: the array on which this method was called.
561+
562+
To set the function execution context, provide a `thisArg`.
563+
564+
```javascript
565+
var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
566+
var Number = require( '@stdlib/number/ctor' );
567+
568+
function predicate( v, i ) {
569+
this.count += 1;
570+
return ( i >= 0 && isEven( Number( v ) ) );
571+
}
572+
573+
var arr = new Uint64Array( [ 1, 3, 5, 7 ] );
574+
575+
var context = {
576+
'count': 0
577+
};
578+
579+
var idx = arr.findIndex( predicate, context );
580+
// returns -1
581+
582+
var count = context.count;
583+
// returns 4
584+
```
585+
536586
<a name="method-get"></a>
537587

538588
#### Uint64Array.prototype.get( i )
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' );
25+
var Uint64 = require( '@stdlib/number/uint64/ctor' );
26+
var format = require( '@stdlib/string/format' );
27+
var pkg = require( './../package.json' ).name;
28+
var Uint64Array = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( format( '%s:findIndex', pkg ), function benchmark( b ) {
34+
var arr;
35+
var out;
36+
var v;
37+
var i;
38+
39+
arr = new Uint64Array( 10 );
40+
v = new Uint64( 1 );
41+
42+
// Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)...
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
out = arr.findIndex( predicate );
46+
if ( out !== -1 ) {
47+
b.fail( 'should return -1' );
48+
}
49+
}
50+
b.toc();
51+
if ( out !== -1 ) {
52+
b.fail( 'should return -1' );
53+
}
54+
b.pass( 'benchmark finished' );
55+
b.end();
56+
57+
function predicate( u ) {
58+
return isEqual( u, v );
59+
}
60+
});
61+
62+
bench( format( '%s::this_context:findIndex', pkg ), function benchmark( b ) {
63+
var arr;
64+
var out;
65+
var v;
66+
var i;
67+
68+
arr = new Uint64Array( 10 );
69+
v = new Uint64( 1 );
70+
71+
// Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)...
72+
b.tic();
73+
for ( i = 0; i < b.iterations; i++ ) {
74+
out = arr.findIndex( predicate, {} );
75+
if ( out !== -1 ) {
76+
b.fail( 'should return -1' );
77+
}
78+
}
79+
b.toc();
80+
if ( out !== -1 ) {
81+
b.fail( 'should return -1' );
82+
}
83+
b.pass( 'benchmark finished' );
84+
b.end();
85+
86+
function predicate( u ) {
87+
return isEqual( u, v );
88+
}
89+
});
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' );
26+
var Uint64 = require( '@stdlib/number/uint64/ctor' );
27+
var format = require( '@stdlib/string/format' );
28+
var pkg = require( './../package.json' ).name;
29+
var Uint64Array = require( './../lib' );
30+
31+
32+
// VARIABLES //
33+
34+
var SEARCH_VALUE = new Uint64( 1 );
35+
36+
37+
// FUNCTIONS //
38+
39+
/**
40+
* Predicate function.
41+
*
42+
* @private
43+
* @param {Uint64} value - array element
44+
* @returns {boolean} boolean indicating whether a value passes a test
45+
*/
46+
function predicate( value ) {
47+
return isEqual( value, SEARCH_VALUE );
48+
}
49+
50+
/**
51+
* Creates a benchmark function.
52+
*
53+
* @private
54+
* @param {PositiveInteger} len - array length
55+
* @returns {Function} benchmark function
56+
*/
57+
function createBenchmark( len ) {
58+
var arr = new Uint64Array( len );
59+
return benchmark;
60+
61+
/**
62+
* Benchmark function.
63+
*
64+
* @private
65+
* @param {Benchmark} b - benchmark instance
66+
*/
67+
function benchmark( b ) {
68+
var out;
69+
var i;
70+
71+
// Benchmark worst case scenario (i.e., the predicate never passes, so the method must visit every element)...
72+
b.tic();
73+
for ( i = 0; i < b.iterations; i++ ) {
74+
out = arr.findIndex( predicate );
75+
if ( out !== -1 ) {
76+
b.fail( 'should return -1' );
77+
}
78+
}
79+
b.toc();
80+
if ( out !== -1 ) {
81+
b.fail( 'should return -1' );
82+
}
83+
b.pass( 'benchmark finished' );
84+
b.end();
85+
}
86+
}
87+
88+
89+
// MAIN //
90+
91+
/**
92+
* Main execution sequence.
93+
*
94+
* @private
95+
*/
96+
function main() {
97+
var len;
98+
var min;
99+
var max;
100+
var f;
101+
var i;
102+
103+
min = 1; // 10^min
104+
max = 6; // 10^max
105+
106+
for ( i = min; i <= max; i++ ) {
107+
len = pow( 10, i );
108+
f = createBenchmark( len );
109+
bench( format( '%s:findIndex:len=%d', pkg, len ), f );
110+
}
111+
}
112+
113+
main();

‎uint64/docs/repl.txt‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,40 @@
434434
<Uint64>[ 4n ]
435435

436436

437+
{{alias}}.prototype.findIndex( predicate[, thisArg] )
438+
Returns the index of the first element in an array for which a predicate
439+
function returns a truthy value.
440+
441+
A predicate function is provided the following arguments:
442+
443+
- value: current array element.
444+
- index: current array element index.
445+
- arr: the array on which the method was called.
446+
447+
If a predicate function never returns a truthy value, the method returns
448+
`-1`.
449+
450+
Parameters
451+
----------
452+
predicate: Function
453+
Predicate function which tests array elements.
454+
455+
thisArg: any (optional)
456+
Execution context.
457+
458+
Returns
459+
-------
460+
out: integer
461+
Array index or `-1`.
462+
463+
Examples
464+
--------
465+
> function predicate( v ) { return ( {{alias:@stdlib/assert/is-even}}.isPrimitive( {{alias:@stdlib/number/ctor}}( v ) ) ); };
466+
> var arr = new {{alias}}( [ 1, 3, 4, 6 ] );
467+
> var idx = arr.findIndex( predicate )
468+
2
469+
470+
437471
{{alias}}.prototype.get( i )
438472
Returns an array element located at integer position (index) `i`.
439473

‎uint64/docs/types/index.d.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,28 @@ declare class Uint64Array implements Uint64ArrayInterface {
557557
*/
558558
find<U = unknown>( predicate: Predicate<U>, thisArg?: ThisParameterType<Predicate<U>> ): Uint64 | void;
559559

560+
/**
561+
* Returns the index of the first element in an array for which a predicate function returns a truthy value.
562+
*
563+
* @param predicate - test function
564+
* @param thisArg - execution context
565+
* @returns index or -1
566+
*
567+
* @example
568+
* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
569+
* var Number = require( '@stdlib/number/ctor' );
570+
*
571+
* function predicate( v ) {
572+
* return ( isEven( Number( v ) ) );
573+
* }
574+
*
575+
* var arr = new Uint64Array( [ 1, 3, 4, 6 ] );
576+
*
577+
* var idx = arr.findIndex( predicate );
578+
* // returns 2
579+
*/
580+
findIndex<U = unknown>( predicate: Predicate<U>, thisArg?: ThisParameterType<Predicate<U>> ): number;
581+
560582
/**
561583
* Returns an array element.
562584
*

‎uint64/lib/main.js‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,49 @@ setReadOnly( Uint64Array.prototype, 'find', function find( predicate, thisArg )
949949
}
950950
});
951951

952+
/**
953+
* Returns the index of the first element in an array for which a predicate function returns a truthy value.
954+
*
955+
* @name findIndex
956+
* @memberof Uint64Array.prototype
957+
* @type {Function}
958+
* @param {Function} predicate - test function
959+
* @param {*} [thisArg] - predicate function execution context
960+
* @throws {TypeError} `this` must be a 64-bit unsigned integer array
961+
* @throws {TypeError} first argument must be a function
962+
* @returns {integer} index or -1
963+
*
964+
* @example
965+
* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
966+
* var Number = require( '@stdlib/number/ctor' );
967+
*
968+
* function predicate( v ) {
969+
* return ( isEven( Number( v ) ) );
970+
* }
971+
*
972+
* var arr = new Uint64Array( [ 1, 3, 4, 6 ] );
973+
*
974+
* var idx = arr.findIndex( predicate );
975+
* // returns 2
976+
*/
977+
setReadOnly( Uint64Array.prototype, 'findIndex', function findIndex( predicate, thisArg ) {
978+
var buf;
979+
var i;
980+
if ( !isUint64Array( this ) ) {
981+
throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' );
982+
}
983+
if ( !isFunction( predicate ) ) {
984+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
985+
}
986+
buf = this._buffer;
987+
for ( i = 0; i < this._length; i++ ) {
988+
if ( predicate.call( thisArg, getUint64( buf, i ), i, this ) ) {
989+
return i;
990+
}
991+
}
992+
return -1;
993+
});
994+
952995
/**
953996
* Returns an array element.
954997
*

0 commit comments

Comments
 (0)