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 Jun 12, 2024
1 parent e1db195 commit 284db42
Show file tree
Hide file tree
Showing 10 changed files with 583 additions and 2 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ This release closes the following issue:

##### Features

- [`d71d044`](https://github.com/stdlib-js/stdlib/commit/d71d04433120ab3096fb01c546d96c60c7684681) - add `sort` method to `array/bool` [(#2363)](https://github.com/stdlib-js/stdlib/pull/2363)
- [`40da309`](https://github.com/stdlib-js/stdlib/commit/40da3097c6ffaed4cd9284d6cdeff8bf11786553) - add `map` method to `array/bool` [(#2292)](https://github.com/stdlib-js/stdlib/pull/2292)
- [`5d53c2d`](https://github.com/stdlib-js/stdlib/commit/5d53c2de22e6899dc3970b4714c0c4e228562f92) - add initial TypeScript declarations
- [`e221398`](https://github.com/stdlib-js/stdlib/commit/e2213984af7a95af1b439aae8e2122968892c55d) - add `array/bool`
Expand Down Expand Up @@ -1354,6 +1355,28 @@ This release closes the following issue:

<!-- /.package -->

<section class="package" id="array-next-dtype-unreleased">

#### [@stdlib/array/next-dtype](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/next-dtype)

<details>

<section class="features">

##### Features

- [`1b80190`](https://github.com/stdlib-js/stdlib/commit/1b8019023cc1e56fc6ae46fba1825503c03c48a1) - add boolean dtype support in `array/next-dtype` [(#2362)](https://github.com/stdlib-js/stdlib/pull/2362)

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="array-one-to-unreleased">

#### [@stdlib/array/one-to](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/one-to)
Expand Down Expand Up @@ -1726,6 +1749,8 @@ A total of 13 people contributed to this release. Thank you to the following con

<details>

- [`d71d044`](https://github.com/stdlib-js/stdlib/commit/d71d04433120ab3096fb01c546d96c60c7684681) - **feat:** add `sort` method to `array/bool` [(#2363)](https://github.com/stdlib-js/stdlib/pull/2363) _(by Jaysukh Makvana)_
- [`1b80190`](https://github.com/stdlib-js/stdlib/commit/1b8019023cc1e56fc6ae46fba1825503c03c48a1) - **feat:** add boolean dtype support in `array/next-dtype` [(#2362)](https://github.com/stdlib-js/stdlib/pull/2362) _(by Jaysukh Makvana)_
- [`ce961d9`](https://github.com/stdlib-js/stdlib/commit/ce961d921bc120e3c45c3df1381793072febf721) - **feat:** add `array/base/assert/is-booleanarray` [(#2357)](https://github.com/stdlib-js/stdlib/pull/2357) _(by Jaysukh Makvana)_
- [`0be04fe`](https://github.com/stdlib-js/stdlib/commit/0be04fed0838ee8603018267ca47e8cbf20556b0) - **feat:** add boolean dtype support in `array/same-kind-casts` [(#2354)](https://github.com/stdlib-js/stdlib/pull/2354) _(by Jaysukh Makvana, Athan Reines)_
- [`84dcb69`](https://github.com/stdlib-js/stdlib/commit/84dcb6972ff346a53f596de5ccc490489c9425ad) - **feat:** add boolean dtype support in `array/safe-casts` [(#2353)](https://github.com/stdlib-js/stdlib/pull/2353) _(by Jaysukh Makvana, Athan Reines)_
Expand Down
49 changes: 49 additions & 0 deletions bool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,55 @@ A few notes:
- If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error.
- If provided a [typed array][@stdlib/array/typed] which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range.

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

#### BooleanArray.prototype.sort( \[compareFcn] )

Sorts an array in-place.

```javascript
function compare( a, b ) {
if ( a === false ) {
if ( b === false ) {
return 0;
}
return 1;
}
if ( b === true ) {
return 0;
}
return -1;
}

var arr = new BooleanArray( 3 );

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

arr.sort( compare );

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

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

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

The `compareFcn` determines the order of the elements. The function is called with the following arguments:

- **a**: the first boolean value for comparison.
- **b**: the second boolean value for comparison.

The function should return a number where:

- a negative value indicates that `a` should come before `b`.
- a positive value indicates that `a` should come after `b`.
- zero or `NaN` indicates that `a` and `b` are considered equal.

</section>

<!-- /.usage -->
Expand Down
75 changes: 75 additions & 0 deletions bool/benchmark/benchmark.sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @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 isBooleanArray = require( '@stdlib/assert/is-booleanarray' );
var pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// FUNCTIONS //

/**
* Comparison function.
*
* @private
* @param {boolean} a - first boolean value for comparison
* @param {boolean} b - second boolean value for comparison
* @returns {number} comparison result
*/
function compareFcn( a, b ) {
if ( a === true ) {
if ( b === true ) {
return 0;
}
return 1;
}
if ( b === false ) {
return 0;
}
return -1;
}


// MAIN //

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

arr = new BooleanArray( [ true, false, false, true, true, false ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.sort( compareFcn );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isBooleanArray( out ) ) {
b.fail( 'should return a BooleanArray' );
}
b.pass( 'benchmark finished' );
b.end();
});
124 changes: 124 additions & 0 deletions bool/benchmark/benchmark.sort.length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* @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 Boolean = require( '@stdlib/boolean/ctor' );
var isBooleanArray = require( '@stdlib/assert/is-booleanarray' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// FUNCTIONS //

/**
* Comparison function.
*
* @private
* @param {boolean} a - first boolean value for comparison
* @param {boolean} b - second boolean value for comparison
* @returns {number} comparison result
*/
function compareFcn( a, b ) {
if ( a === true ) {
if ( b === true ) {
return 0;
}
return 1;
}
if ( b === false ) {
return 0;
}
return -1;
}

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

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

return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.sort( compareFcn );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isBooleanArray( out ) ) {
b.fail( 'should return a BooleanArray' );
}
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+':sort:len='+len, f );
}
}

main();
48 changes: 48 additions & 0 deletions bool/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ type TernaryMapFcn<U> = ( this: U, value: boolean, index: number, arr: BooleanAr
*/
type MapFcn<U> = NullaryMapFcn<U> | UnaryMapFcn<U> | BinaryMapFcn<U> | TernaryMapFcn<U>;

/**
* Comparator function.
*
* @param a - first boolean value for comparison
* @param b - second boolean value for comparison
* @returns number indicating comparison result
*/
type CompareFcn = ( a: boolean, b: boolean ) => number;

/**
* Class for creating a Boolean array.
*/
Expand Down Expand Up @@ -312,6 +321,45 @@ declare class BooleanArray implements BooleanArrayInterface {
* // returns true
*/
set( value: ArrayLike<any> | any, i?: number ): void;

/**
* Sorts an array in-place.
*
* @param compareFcn - comparison function
* @returns sorted array
*
* @example
* function compare( a, b ) {
* if ( a === false ) {
* if ( b === false ) {
* return 0;
* }
* return 1;
* }
* if ( b === true ) {
* return 0;
* }
* return -1;
* }
*
* var arr = new BooleanArray( 3 );
*
* arr.set( true, 0 );
* arr.set( false, 1 );
* arr.set( true, 2 );
*
* arr.sort( compare );
*
* var v = arr.get( 0 );
* // returns true
*
* v = arr.get( 1 );
* // returns true
*
* v = arr.get( 2 );
* // returns false
*/
sort( compareFcn: CompareFcn ): BooleanArray;
}

/**
Expand Down
Loading

0 comments on commit 284db42

Please sign in to comment.