Skip to content

Commit 1bebb2c

Browse files
committed
Auto-generated commit
1 parent bcb5292 commit 1bebb2c

9 files changed

+470
-7
lines changed

CHANGELOG.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`9db1815`](https://github.com/stdlib-js/stdlib/commit/9db181520dc74f28aab70a73aac64202cf7560ce) - add `indexOf` method to `array/fixed-endian-factory` [(#3279)](https://github.com/stdlib-js/stdlib/pull/3279)
1314
- [`1d217ba`](https://github.com/stdlib-js/stdlib/commit/1d217bad1d35210a57d65c8be67c596815589082) - add `map` method to `array/fixed-endian-factory` [(#3270)](https://github.com/stdlib-js/stdlib/pull/3270)
1415
- [`2df0e9b`](https://github.com/stdlib-js/stdlib/commit/2df0e9bb08b8ad1c573b7c2383ef39e492dd5436) - add `some` method to `array/fixed-endian-factory` [(#3241)](https://github.com/stdlib-js/stdlib/pull/3241)
1516
- [`e3a2173`](https://github.com/stdlib-js/stdlib/commit/e3a2173a24bd8634f333cace626fc2d71740ebd3) - add `every` method to `array/fixed-endian-factory` [(#3200)](https://github.com/stdlib-js/stdlib/pull/3200)
@@ -25,9 +26,9 @@
2526

2627
### Closed Issues
2728

28-
A total of 4 issues were closed in this release:
29+
A total of 5 issues were closed in this release:
2930

30-
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138), [#3150](https://github.com/stdlib-js/stdlib/issues/3150), [#3155](https://github.com/stdlib-js/stdlib/issues/3155)
31+
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138), [#3146](https://github.com/stdlib-js/stdlib/issues/3146), [#3150](https://github.com/stdlib-js/stdlib/issues/3150), [#3155](https://github.com/stdlib-js/stdlib/issues/3155)
3132

3233
</section>
3334

@@ -39,6 +40,7 @@ A total of 4 issues were closed in this release:
3940

4041
<details>
4142

43+
- [`9db1815`](https://github.com/stdlib-js/stdlib/commit/9db181520dc74f28aab70a73aac64202cf7560ce) - **feat:** add `indexOf` method to `array/fixed-endian-factory` [(#3279)](https://github.com/stdlib-js/stdlib/pull/3279) _(by Aditya Sapra, Athan Reines)_
4244
- [`1d217ba`](https://github.com/stdlib-js/stdlib/commit/1d217bad1d35210a57d65c8be67c596815589082) - **feat:** add `map` method to `array/fixed-endian-factory` [(#3270)](https://github.com/stdlib-js/stdlib/pull/3270) _(by Aayush Khanna, Athan Reines)_
4345
- [`2df0e9b`](https://github.com/stdlib-js/stdlib/commit/2df0e9bb08b8ad1c573b7c2383ef39e492dd5436) - **feat:** add `some` method to `array/fixed-endian-factory` [(#3241)](https://github.com/stdlib-js/stdlib/pull/3241) _(by Kshitij-Dale, Athan Reines)_
4446
- [`abb0dc3`](https://github.com/stdlib-js/stdlib/commit/abb0dc38783210623e67f19a5bb95b3998f75ff7) - **docs:** update examples and descriptions _(by Athan Reines)_
@@ -60,9 +62,10 @@ A total of 4 issues were closed in this release:
6062

6163
### Contributors
6264

63-
A total of 3 people contributed to this release. Thank you to the following contributors:
65+
A total of 4 people contributed to this release. Thank you to the following contributors:
6466

6567
- Aayush Khanna
68+
- Aditya Sapra
6669
- Athan Reines
6770
- Kshitij-Dale
6871

CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Karthik Prakash <116057817+skoriop@users.noreply.github.com>
4848
Khaldon <kahmd1444@gmail.com>
4949
Kohantika Nath <145763549+kohantikanath@users.noreply.github.com>
5050
Krishnendu Das <86651039+itskdhere@users.noreply.github.com>
51+
Kshitij-Dale <152467202+Kshitij-Dale@users.noreply.github.com>
5152
Lovelin <100030865+lovelindhoni@users.noreply.github.com>
5253
Manik Sharma <maniksharma.rke@gmail.com>
5354
Marcus Fantham <mfantham@users.noreply.github.com>

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,38 @@ var v = arr.get( 100 );
516516
// returns undefined
517517
```
518518

519+
<a name="method-index-of"></a>
520+
521+
#### TypedArrayFE.prototype.indexOf( searchElement\[, fromIndex] )
522+
523+
Returns the first index at which a given element can be found.
524+
525+
```javascript
526+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
527+
528+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );
529+
530+
var idx = arr.indexOf( 2.0 );
531+
// returns 1
532+
533+
idx = arr.indexOf( 2.0, 2 );
534+
// returns 4
535+
536+
idx = arr.indexOf( 2.0, -4 );
537+
// returns 1
538+
```
539+
540+
If `searchElement` is not present in the array, the method returns `-1`.
541+
542+
```javascript
543+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
544+
545+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );
546+
547+
var idx = arr.indexOf( 5.0 );
548+
// returns -1
549+
```
550+
519551
<a name="method-map"></a>
520552

521553
#### TypedArray.prototype.map( callbackFn\[, thisArg] )

benchmark/benchmark.index_of.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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-harness' );
24+
var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
25+
var factory = require( './../lib' );
26+
var pkg = require( './../package.json' ).name;
27+
28+
29+
// VARIABLES //
30+
31+
var Float64ArrayFE = factory( 'float64' );
32+
33+
34+
// MAIN //
35+
36+
bench( pkg+':indexOf', function benchmark( b ) {
37+
var arr;
38+
var idx;
39+
var i;
40+
41+
arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
42+
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
idx = arr.indexOf( 5.0, 0 );
46+
if ( typeof idx !== 'number' ) {
47+
b.fail( 'should return an integer' );
48+
}
49+
}
50+
b.toc();
51+
if ( !isInteger( idx ) ) {
52+
b.fail( 'should return an integer' );
53+
}
54+
b.pass( 'benchmark finished' );
55+
b.end();
56+
});
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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-harness' );
24+
var pow = require( '@stdlib/math-base-special-pow' );
25+
var zeroTo = require( '@stdlib/array-zero-to' );
26+
var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
27+
var factory = require( './../lib' );
28+
var pkg = require( './../package.json' ).name;
29+
30+
31+
// VARIABLES //
32+
33+
var Float64ArrayFE = factory( 'float64' );
34+
35+
36+
// FUNCTIONS //
37+
38+
/**
39+
* Creates a benchmark function.
40+
*
41+
* @private
42+
* @param {PositiveInteger} len - array length
43+
* @returns {Function} benchmark function
44+
*/
45+
function createBenchmark( len ) {
46+
var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) );
47+
return benchmark;
48+
49+
/**
50+
* Benchmark function.
51+
*
52+
* @private
53+
* @param {Benchmark} b - benchmark instance
54+
*/
55+
function benchmark( b ) {
56+
var idx;
57+
var v;
58+
var i;
59+
60+
v = len - 1;
61+
62+
b.tic();
63+
for ( i = 0; i < b.iterations; i++ ) {
64+
idx = arr.indexOf( v );
65+
if ( typeof idx !== 'number' ) {
66+
b.fail( 'should return an integer' );
67+
}
68+
}
69+
b.toc();
70+
if ( !isInteger( idx ) ) {
71+
b.fail( 'should return an integer' );
72+
}
73+
b.pass( 'benchmark finished' );
74+
b.end();
75+
}
76+
}
77+
78+
79+
// MAIN //
80+
81+
/**
82+
* Main execution sequence.
83+
*
84+
* @private
85+
*/
86+
function main() {
87+
var len;
88+
var min;
89+
var max;
90+
var f;
91+
var i;
92+
93+
min = 1; // 10^min
94+
max = 6; // 10^max
95+
96+
for ( i = min; i <= max; i++ ) {
97+
len = pow( 10, i );
98+
f = createBenchmark( len );
99+
bench( pkg+':indexOf:len='+len, f );
100+
}
101+
}
102+
103+
main();

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/main.js

+42
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,48 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
634634
return this._buffer[ GETTER ]( idx*BYTES_PER_ELEMENT, this._isLE );
635635
});
636636

637+
/**
638+
* Returns the index of the first occurrence of a given element.
639+
*
640+
* @private
641+
* @name indexOf
642+
* @memberof TypedArray.prototype
643+
* @type {Function}
644+
* @param {*} searchElement - element to search for
645+
* @param {integer} [fromIndex=0] - starting index (inclusive)
646+
* @throws {TypeError} `this` must be a typed array instance
647+
* @throws {TypeError} second argument must be an integer
648+
* @returns {integer} index or -1
649+
*/
650+
setReadOnly( TypedArray.prototype, 'indexOf', function indexOf( searchElement, fromIndex ) {
651+
var buf;
652+
var i;
653+
654+
if ( !isTypedArray( this ) ) {
655+
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
656+
}
657+
if ( arguments.length > 1 ) {
658+
if ( !isInteger( fromIndex ) ) {
659+
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
660+
}
661+
if ( fromIndex < 0 ) {
662+
fromIndex += this._length;
663+
if ( fromIndex < 0 ) {
664+
fromIndex = 0;
665+
}
666+
}
667+
} else {
668+
fromIndex = 0;
669+
}
670+
buf = this._buffer;
671+
for ( i = fromIndex; i < this._length; i++ ) {
672+
if ( buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ) === searchElement ) {
673+
return i;
674+
}
675+
}
676+
return -1;
677+
});
678+
637679
/**
638680
* Number of array elements.
639681
*

0 commit comments

Comments
 (0)