Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jul 19, 2024
1 parent 9706edd commit ea0e5df
Show file tree
Hide file tree
Showing 13 changed files with 1,600 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<section class="release" id="unreleased">

## Unreleased (2024-07-18)
## Unreleased (2024-07-19)

<section class="packages">

Expand Down Expand Up @@ -1324,6 +1324,7 @@ This release closes the following issue:

##### Features

- [`cb20ecc`](https://github.com/stdlib-js/stdlib/commit/cb20ecc5555cabbdfa9ad4807e096f8768f9f780) - add `copyWithin`, `entries`, `forEach` to `array/bool` [(#2611)](https://github.com/stdlib-js/stdlib/pull/2611)
- [`7c17308`](https://github.com/stdlib-js/stdlib/commit/7c17308587cd0fbac9812f258e3cd774cbdfc8da) - add `at`, `fill`, `filter`, and `toLocalestring` methods to `array/bool` [(#2607)](https://github.com/stdlib-js/stdlib/pull/2607)
- [`ce3ad9a`](https://github.com/stdlib-js/stdlib/commit/ce3ad9a98468829b294708ca188ec669056e58ed) - add `keys`, `values`, and `with` methods to `array/bool` [(#2590)](https://github.com/stdlib-js/stdlib/pull/2590)
- [`5a66b4b`](https://github.com/stdlib-js/stdlib/commit/5a66b4bb677cdbc4706811ea9f776343297c9f87) - add `join` and `toString` methods to `array/bool` [(#2557)](https://github.com/stdlib-js/stdlib/pull/2557)
Expand Down Expand Up @@ -2437,6 +2438,7 @@ A total of 13 people contributed to this release. Thank you to the following con

<details>

- [`cb20ecc`](https://github.com/stdlib-js/stdlib/commit/cb20ecc5555cabbdfa9ad4807e096f8768f9f780) - **feat:** add `copyWithin`, `entries`, `forEach` to `array/bool` [(#2611)](https://github.com/stdlib-js/stdlib/pull/2611) _(by Jaysukh Makvana, Athan Reines)_
- [`ba35d8f`](https://github.com/stdlib-js/stdlib/commit/ba35d8f2e923d26640828a0f035333bd778389b7) - **refactor:** update paths _(by Athan Reines)_
- [`0406147`](https://github.com/stdlib-js/stdlib/commit/04061476d1036e1b8b786736b1ba1653eddff1ef) - **refactor:** update paths _(by Athan Reines)_
- [`b9703b5`](https://github.com/stdlib-js/stdlib/commit/b9703b569dc2f0a67e604e388a0d188b08138b48) - **refactor:** update paths _(by Athan Reines)_
Expand Down
175 changes: 175 additions & 0 deletions bool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,121 @@ v = arr.at( -100 );
// returns undefined
```

<a name="method-copy-within"></a>

#### BooleanArray.prototype.copyWithin( target, start\[, end] )

Copies a sequence of elements within the array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`.

```javascript
var arr = new BooleanArray( 4 );

arr.set( true, 0 );
arr.set( false, 1 );
arr.set( false, 2 );
arr.set( true, 3 );

var v = arr.get( 0 );
// returns true

v = arr.get( 1 );
// returns false

// Copy the last two elements to the first two elements:
arr.copyWithin( 0, 2 );

v = arr.get( 0 );
// returns false

v = arr.get( 1 );
// returns true
```

By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument.

```javascript
var arr = new BooleanArray( 4 );

arr.set( true, 0 );
arr.set( false, 1 );
arr.set( false, 2 );
arr.set( true, 3 );

var v = arr.get( 2 );
// returns false

v = arr.get( 3 );
// returns true

// Copy the first two elements to the last two elements:
arr.copyWithin( 2, 0, 2 );

v = arr.get( 2 );
// returns true

v = arr.get( 3 );
// returns false
```

When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example:

```javascript
var arr = new BooleanArray( 4 );

arr.set( true, 0 );
arr.set( false, 1 );
arr.set( false, 2 );
arr.set( true, 3 );

var v = arr.get( 2 );
// returns false

v = arr.get( 3 );
// returns true

// Copy the first two elements to the last two elements using negative indices:
arr.copyWithin( -2, -4, -2 );

v = arr.get( 2 );
// returns true

v = arr.get( 3 );
// returns false
```

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

#### BooleanArray.prototype.entries()

Returns an iterator for iterating over array key-value pairs.

```javascript
var arr = new BooleanArray( 3 );

arr.set( true, 0 );
arr.set( false, 1 );
arr.set( true, 2 );

var it = arr.entries();

var v = it.next().value;
// returns [ 0, true ]

v = it.next().value;
// returns [ 1, false ]

v = it.next().value;
// returns [ 2, true ]

var bool = it.next().done;
// returns true
```

The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties:

- **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-every"></a>

#### BooleanArray.prototype.every( predicate\[, thisArg] )
Expand Down Expand Up @@ -746,6 +861,66 @@ var count = context.count;
// returns 3
```

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

#### BooleanArray.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 BooleanArray( 3 );

arr.set( true, 0 );
arr.set( false, 1 );
arr.set( true, 2 );

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

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 BooleanArray( 3 );

var context = {
'count': 0
};

arr.set( true, 0 );
arr.set( false, 1 );
arr.set( true, 2 );

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

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

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

#### BooleanArray.prototype.get( i )
Expand Down
56 changes: 56 additions & 0 deletions bool/benchmark/benchmark.copy_within.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// MAIN //

bench( pkg+':copyWithin', function benchmark( b ) {
var arr;
var buf;
var i;

arr = [];
for ( i = 0; i < 5; i++ ) {
arr.push( i%2 );
}
arr = new BooleanArray( arr );
buf = arr.buffer;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
buf[ 0 ] = i%2;
arr = arr.copyWithin( 1, 0 );
if ( buf[ 0 ] !== i%2 ) {
b.fail( 'unexpected result' );
}
}
b.toc();
if ( buf[ 0 ] !== buf[ 0 ] ) {
b.fail( 'should not be NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
103 changes: 103 additions & 0 deletions bool/benchmark/benchmark.copy_within.length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// FUNCTIONS //

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

arr = [];
for ( i = 0; i < len+1; i++ ) {
arr.push( i%2 );
}
arr = new BooleanArray( arr );
buf = arr.buffer;

return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
buf[ 0 ] = i%2;
arr.copyWithin( 1, 0 );
if ( buf[ 0 ] !== i%2 ) {
b.fail( 'unexpected result' );
}
}
b.toc();
if ( buf[ 0 ] !== buf[ 0 ] ) {
b.fail( 'should not be NaN' );
}
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( pkg+':copyWithin:len='+len, f );
}
}

main();
Loading

0 comments on commit ea0e5df

Please sign in to comment.