Skip to content
73 changes: 73 additions & 0 deletions lib/node_modules/@stdlib/array/uint64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,58 @@ var count = context.count;

If a `predicate` function never returns a truthy value, the method returns `-1`.

<a name="method-for-each"></a>

#### Uint64Array.prototype.forEach( callbackFn\[, thisArg] )

Invokes a function once for each array element.

```javascript
function log( v, i ) {
console.log( '%s: %s', i, v.toString() );
}

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

arr.forEach( log );
/* =>
0: 1
1: 2
2: 3
*/
```

The invoked 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
function fcn( v, i ) {
this.count += 1;
console.log( '%s: %s', i, v.toString() );
}

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

var context = {
'count': 0
};

arr.forEach( fcn, context );
/* =>
0: 1
1: 2
2: 3
*/

var count = context.count;
// returns 3
```

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

#### Uint64Array.prototype.get( i )
Expand All @@ -713,6 +765,27 @@ var u = arr.get( 100 );
// returns undefined
```

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

#### Uint64Array.prototype.includes( searchElement\[, fromIndex] )

Returns a boolean indicating whether an array includes a provided value.

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

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

var bool = arr.includes( new Uint64( 3 ) );
// returns true

bool = arr.includes( 3, 3 );
// returns false

bool = arr.includes( 4, -3 );
// returns true
```

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

#### Uint64Array.prototype.set( value\[, i] )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @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 pkg = require( './../package.json' ).name;
var Uint64Array = require( './../lib' );


// MAIN //

bench( format( '%s:forEach', pkg ), function benchmark( b ) {
var count;
var arr;
var N;
var i;

arr = new Uint64Array( 10 );
N = arr.length;
count = 0;

// Benchmark worst case scenario (i.e., the method cannot exit early, so every element is visited)...
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr.forEach( fcn );
if ( count !== N*(i+1) ) {
b.fail( 'unexpected result' );
}
}
b.toc();
if ( count !== N*i ) {
b.fail( 'unexpected result' );
}
b.pass( 'benchmark finished' );
b.end();

function fcn() {
count += 1;
}
});

bench( format( '%s::this_context:forEach', pkg ), function benchmark( b ) {
var count;
var arr;
var N;
var i;

arr = new Uint64Array( 10 );
N = arr.length;
count = 0;

// Benchmark worst case scenario (i.e., the method cannot exit early, so every element is visited)...
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr.forEach( fcn, {} );
if ( count !== N*(i+1) ) {
b.fail( 'unexpected result' );
}
}
b.toc();
if ( count !== N*i ) {
b.fail( 'unexpected result' );
}
b.pass( 'benchmark finished' );
b.end();

function fcn() {
count += 1;
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* @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 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 count;
var arr;

arr = new Uint64Array( len );
count = 0;

return benchmark;

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

count = 0;

// Benchmark worst case scenario (i.e., the method cannot exit early, so every element is visited)...
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr.forEach( fcn );
if ( count !== len*(i+1) ) {
b.fail( 'unexpected result' );
}
}
b.toc();
if ( count !== len*i ) {
b.fail( 'unexpected result' );
}
b.pass( 'benchmark finished' );
b.end();
}

/**
* Callback invoked for each array element.
*
* @private
*/
function fcn() {
count += 1;
}
}


// 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:forEach:len=%d', pkg, len ), f );
}
}

main();
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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Uint64Array = require( './../lib' );


// MAIN //

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

arr = new Uint64Array( 10 );

// Benchmark worst case scenario (i.e., the search element is never present, so the method must scan the entire array)...
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = arr.includes( i+1 );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading
Loading