From 3a960cf12a1f3fb51846c83a37b5db2bf55dcfdb Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 3 Mar 2026 15:31:51 +0530 Subject: [PATCH 01/11] feat: add initial setup --- .../@stdlib/dstructs/fifo/README.md | 115 +++++++ .../fifo/benchmark/benchmark.every.js | 56 ++++ .../fifo/benchmark/benchmark.every.length.js | 115 +++++++ .../dstructs/fifo/benchmark/benchmark.get.js | 54 ++++ .../dstructs/fifo/benchmark/benchmark.set.js | 55 ++++ .../@stdlib/dstructs/fifo/docs/repl.txt | 118 +++++++- .../dstructs/fifo/docs/types/index.d.ts | 134 ++++++++- .../@stdlib/dstructs/fifo/examples/index.js | 5 + .../@stdlib/dstructs/fifo/lib/main.js | 170 +++++++++++ .../@stdlib/dstructs/fifo/test/test.every.js | 284 ++++++++++++++++++ .../@stdlib/dstructs/fifo/test/test.get.js | 137 +++++++++ .../@stdlib/dstructs/fifo/test/test.set.js | 181 +++++++++++ 12 files changed, 1411 insertions(+), 13 deletions(-) create mode 100644 lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.every.js create mode 100644 lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.every.length.js create mode 100644 lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.get.js create mode 100644 lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js create mode 100644 lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js create mode 100644 lib/node_modules/@stdlib/dstructs/fifo/test/test.get.js create mode 100644 lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js diff --git a/lib/node_modules/@stdlib/dstructs/fifo/README.md b/lib/node_modules/@stdlib/dstructs/fifo/README.md index 380fd643f663..750472c08d6d 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/README.md +++ b/lib/node_modules/@stdlib/dstructs/fifo/README.md @@ -80,6 +80,66 @@ len = queue.length; // returns 0 ``` +##### queue.every( predicate\[, thisArg] ) + +Tests whether all elements in a queue pass a test implemented by a predicate function. + +```javascript +var queue = fifo(); + +// Add values to the queue: +queue.push( 1 ).push( 2 ).push( 3 ); + +// Test whether all elements are greater than 0: +function predicate( v ) { + return v > 0; +} + +var bool = queue.every( predicate ); +// returns true + +// Test whether all elements are even: +function predicate( v ) { + return v % 2 === 0; +} + +bool = queue.every( predicate ); +// returns false +``` + +The `predicate` function is provided three arguments: + +- **value**: current queue element. +- **index**: current queue element index. +- **q**: the queue on which the method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +function predicate( v ) { + this.count += 1; + return v > 0; +} + +// Create a queue: +var queue = fifo(); + +// Add values to the queue: +queue.push( 1 ).push( 2 ).push( 3 ); + +// Define an execution context: +var ctx = { + 'count': 0 +}; + +// Test whether all elements are greater than 0: +var bool = queue.every( predicate, ctx ); +// returns true + +var n = ctx.count; +// returns 3 +``` + ##### queue.first() Returns the "oldest" queue value (i.e., the value which is "first-out"). If the queue is currently empty, the returned value is `undefined`. @@ -96,6 +156,36 @@ var v = queue.first(); // returns 'foo' ``` +##### queue.get( index ) + +Returns a queue element at a specified index using the accessor protocol. + +```javascript +var queue = fifo(); + +// Add values to the queue: +queue.push( 'foo' ).push( 'bar' ).push( 'baz' ); + +// Access elements by index via the accessor protocol: +var v = queue.get( 0 ); +// returns 'foo' + +v = queue.get( 1 ); +// returns 'bar' + +v = queue.get( 2 ); +// returns 'baz' + +// Out-of-bounds indices return undefined: +v = queue.get( 10 ); +// returns undefined + +queue[ 0 ] = 'foo'; +console.log( queue[ 0 ] ); +// => 'foo' + +``` + ##### queue.iterator() Returns an iterator for iterating over a queue. If an environment supports `Symbol.iterator`, the returned iterator is iterable. @@ -201,6 +291,31 @@ v = queue.pop(); // returns 'bar' ``` +##### queue.set( value, index ) + +Sets a queue element at a specified index. + +```javascript +var queue = fifo(); +// returns + +// Add values to the queue: +queue.push( 'foo' ).push( 'bar' ).push( 'baz' ); + +// Set elements by index: +queue.set( 'beep', 0 ); +var v = queue.get( 0 ); +// returns 'beep' + +queue.set( 'boop', 1 ); +v = queue.get( 1 ); +// returns 'boop' + +// Out-of-bounds index throws an error: +queue.set( 'boom', 10 ); +// throws +``` + ##### queue.toArray() Returns an array of queue values. diff --git a/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.every.js b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.every.js new file mode 100644 index 000000000000..e433d2e77244 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.every.js @@ -0,0 +1,56 @@ +/** +* @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 FIFO = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:every', pkg ), function benchmark( b ) { + var bool; + var q; + var i; + + q = new FIFO(); + for ( i = 1; i <= 4; i++ ) { + q.push( i ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = q.every( function predicate( v ) { + return v > 0; + }); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.every.length.js b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.every.length.js new file mode 100644 index 000000000000..e17ed102f58d --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.every.length.js @@ -0,0 +1,115 @@ +/* +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var FIFO = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {boolean} value - array element +* @param {NonNegativeInteger} idx - array element index +* @param {FIFO} q - queue instance +* @returns {boolean} boolean indicating whether a value passes a test +*/ +function predicate( value ) { + return value > 0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - queue length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var q; + var i; + + q = new FIFO(); + for ( i = 0; i < len; i++ ) { + q.push( i ); + } + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = q.every( predicate ); + 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(); + } +} + + +// 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:every:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.get.js b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.get.js new file mode 100644 index 000000000000..673d0092838d --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.get.js @@ -0,0 +1,54 @@ +/** +* @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 FIFO = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:get', pkg ), function benchmark( b ) { + var q; + var v; + var i; + + q = new FIFO(); + for ( i = 1; i <= 4; i++ ) { + q.push( i ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = q.get( i%4 ); + if ( typeof v === 'undefined' ) { + b.fail( 'should return a value' ); + } + } + b.toc(); + if ( typeof v === 'undefined' ) { + b.fail( 'should return a value' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js new file mode 100644 index 000000000000..1a0c9301d4f0 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js @@ -0,0 +1,55 @@ +/** +* @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 FIFO = require( './../lib' ); + + +// MAIN // + + +bench( format( '%s:set', pkg ), function benchmark( b ) { + var q; + var v; + var i; + + q = new FIFO(); + for ( i = 1; i <= 4; i++ ) { + q.push( i ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = q.set( i%4, i%4 ); // value, index + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt index 5ec306f898d5..cc362b5eb5e2 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt @@ -10,10 +10,17 @@ queue.clear: Function Clears the queue. + queue.every: Function + Returns a boolean indicating whether all elements in the queue + pass a test. + queue.first: Function Returns the "oldest" queue value (i.e., the value which is "first-out"). If the queue is empty, the returned value is `undefined`. + queue.get: Function + Returns a queue element at a specified index. + queue.iterator: Function Returns an iterator for iterating over a queue. If an environment supports Symbol.iterator, the returned iterator is iterable. Note that, @@ -36,6 +43,9 @@ queue.push: Function Adds a value to the queue. + queue.set: Function + Sets a queue element at a specified index. + queue.toArray: Function Returns an array of queue values. @@ -45,18 +55,112 @@ Examples -------- > var q = {{alias}}(); - > q.push( 'foo' ).push( 'bar' ); + > q.push( 'foo' ).push( 'bar' ).push( 'baz' ); > q.length - 2 + 3 + > q[0] + 'foo' + > q[1] + 'bar' + > q[2] + 'baz' > q.pop() 'foo' > q.length - 1 - > q.pop() + 2 + + +{{alias}}.prototype.every( predicate[, thisArg] ) + Returns a boolean indicating whether all elements in the queue pass a test. + + The predicate function is provided three arguments: + + - value: current queue element. + - index: current queue element index. + - q: the queue on which the method was called. + + Parameters + ---------- + predicate: Function + Predicate function to test queue elements. Should return a boolean + indicating whether an element passes the test. The function is provided + three arguments: value, index, and q. + + thisArg: Any (optional) + Execution context for the predicate function. + + Returns + ------- + bool: boolean + Boolean indicating whether all elements pass the test. + + Examples + -------- + > var q = {{alias}}(); + > q.push( 1 ).push( 2 ).push( 3 ); + > q.every( function predicate( v ) { return v > 0; } ) + true + > q.every( function predicate( v ) { return v > 2; } ) + false + > q.every( function predicate( v ) { return v % 2 === 0; } ) + false + + +{{alias}}.prototype.get( index ) + Returns a queue element at a specified index. + + if index is out-of-bounds then this will return undefined. + + Parameters + ---------- + index: NonNegativeInteger + Queue element index. + + Returns + ------- + value: Any + Queue element. + + Examples + -------- + > var q = {{alias}}(); + > q.push( 'foo' ).push( 'bar' ).push( 'baz' ); + > q.get( 0 ) + 'foo' + > q.get( 1 ) 'bar' - > q.length - 0 + > q.get( 2 ) + 'baz' + > q.get( 10 ) + undefined - See Also + +{{alias}}.prototype.set( value[, index] ) + Sets one or more queue elements. + + If provided a single argument, the method sets array elements starting at + position (index) `i = 0`. To set elements starting elsewhere in the queue, + provide an index argument `i`. + + Parameters + ---------- + value: Any + Value to set. + + index: Integer (optional) + Queue element index. Default: 0. + + Examples -------- + > var q = {{alias}}(); + > q.push( 'foo' ).push( 'bar' ).push( 'baz' ); + > q.set( 'beep', 0 ); + > q.get( 0 ) + 'beep' + > q.set( 'boop', 1 ); + > q.get( 1 ) + 'boop' + + See Also + -------- diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts index f8d54c6d8376..e0586d505a0b 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts @@ -22,10 +22,59 @@ import { IterableIterator } from '@stdlib/types/iter'; +/** + * Checks whether an element in a queue passes a test. + * + * @param value - current queue element + * @param index - current queue element index + * @param q - queue on which the method was called + * @returns boolean indicating whether an element in a queue passes a test + */ +type NullaryPredicate = ( this: U ) => boolean; + +/** + * Checks whether an element in a queue passes a test. + * + * @param value - current queue element + * @returns boolean indicating whether an element in a queue passes a test + */ +type UnaryPredicate = ( this: U, value: T ) => boolean; + +/** + * Checks whether an element in a queue passes a test. + * + * @param value - current queue element + * @param index - current queue element index + * @returns boolean indicating whether an element in a queue passes a test + */ +type BinaryPredicate = ( this: U, value: T, index: number ) => boolean; + +/** + * Checks whether an element in a queue passes a test. + * + * @param value - current queue element + * @param index - current queue element index + * @param q - queue on which the method was called + * @returns boolean indicating whether an element in a queue passes a test + */ +type TernaryPredicate = ( this: U, value: T, index: number, q: FIFO ) => boolean; + +/** +* Checks whether an element in an queue passes a test. +* +* @param value - current queue element +* @param index - current queue element index +* @param q - queue on which the method was called +* @returns boolean indicating whether an element in a queue passes a test +*/ +type Predicate = NullaryPredicate | UnaryPredicate | BinaryPredicate | TernaryPredicate; + /** * First-in-first-out (FIFO) queue. +* +* @template T - queue element type */ -declare class FIFO { +declare class FIFO { /** * First-in-first-out queue constructor. * @@ -82,6 +131,40 @@ declare class FIFO { */ clear(): FIFO; + /** + * Tests whether all elements in a queue pass a test implemented by a predicate function. + * + * ## Notes + * + * - The method does not change the queue, it returns a boolean indicating whether all elements pass the test. + * - If the queue is empty, the method returns `true`. + * + * @param predicate - predicate function to test queue elements + * @param thisArg - execution context for the predicate function + * @throws first argument must be a function + * @returns boolean indicating whether all elements pass a test + * + * @example + * var queue = new FIFO(); + * + * queue.push( 1 ).push( 2 ).push( 3 ); + * + * function predicate( v ) { + * return v > 0; + * } + * + * var bool = queue.every( predicate ); + * // returns true + * + * function predicate( v ) { + * return v % 2 === 0; + * } + * + * bool = queue.every( predicate ); + * // returns false + */ + every( predicate: Predicate, thisArg?: ThisParameterType> ): boolean; + /** * Returns the "oldest" queue value (i.e., the value which is "first-out"). * @@ -97,7 +180,27 @@ declare class FIFO { * var v = queue.first(); * // returns 'foo' */ - first(): any; + first(): T | void; + + /** + * Returns a queue element. + * + * @param i - element index + * @throws index argument must be a nonnegative integer + * @returns queue element + * + * @example + * var queue = new FIFO(); + * + * queue.push( 'foo' ).push( 'bar' ); + * + * var v = queue.get( 0 ); + * // returns 'foo' + * + * v = queue.get( 1 ); + * // returns 'bar' + */ + get( i: number ): T | void; /** * Returns an iterator for iterating over a queue. @@ -144,7 +247,7 @@ declare class FIFO { * var v = queue.last(); * // returns 'bar' */ - last(): any; + last(): T | void; /** * Queue length. @@ -187,7 +290,7 @@ declare class FIFO { * v = queue.pop(); * // returns 'bar' */ - pop(): any; + pop(): T | void; /** * Adds a value to the queue. @@ -211,7 +314,26 @@ declare class FIFO { * v = queue.pop(); * // returns 'bar' */ - push(): FIFO; + push( value: T ): FIFO; + + /** + * Sets a queue element at a specified index. + * + * @param value - value to set + * @param i - element index (default: 0) + * @throws index argument must be a nonnegative integer + * @throws index argument is out-of-bounds + * @throws target queue lacks sufficient storage to accommodate source values + * + * @example + * var queue = new FIFO(); + * + * queue.push( 'foo' ).push( 'bar' ).set( 'beep', 0 ); + * + * var v = queue.get( 0 ); + * // returns 'beep' + */ + set( value: T, i?: number ): void; /** * Returns an array of queue values. @@ -228,7 +350,7 @@ declare class FIFO { * var vals = queue.toArray(); * // returns [ 'foo', 'bar' ] */ - toArray(): Array; + toArray(): Array; /** * Serializes a queue as JSON. diff --git a/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js b/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js index 5759d4a8bcc1..f1f67d61d101 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js @@ -29,6 +29,11 @@ queue.push( 'bar' ); queue.push( 'beep' ); queue.push( 'boop' ); +// Inspecting accessor-protocol implementation: +queue.set( 'bop', 3 ); +v = queue.get( 3 ); +console.log( 'Value: %s', v ); + // Peek at the first and last queue values: var v = queue.first(); console.log( 'First: %s', v ); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js index 4acb43b20dfd..83f766969192 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js @@ -24,10 +24,31 @@ var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); var iteratorSymbol = require( '@stdlib/symbol/iterator' ); var Node = require( './node.js' ); // eslint-disable-line stdlib/no-redeclare +// FUNCTIONS // + +/** +* Returns a boolean indicating if a value is a `FIFO`. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a `FIFO` +*/ +function isFIFO( value ) { + return ( + typeof value === 'object' && + value !== null && + value.constructor.name === 'FIFO' + ); +} + + // MAIN // /** @@ -103,6 +124,155 @@ setReadOnly( FIFO.prototype, 'clear', function clear() { return this; }); +/** +* Tests whether all elements in a queue pass a test implemented by a predicate function. +* +* ## Notes +* +* - The method does not change the queue; it returns a boolean indicating whether all elements pass the test. +* - If the queue is empty, the method returns `true`. +* - The method creates a "snapshot" of the queue at the time of invocation to handle potential queue mutations during iteration. +* +* @name every +* @memberof FIFO.prototype +* @type {Function} +* @param {Function} predicate - predicate function to test queue elements +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a FIFO +* @throws {TypeError} first argument must be a function +* @returns {boolean} boolean indicating whether all elements pass a test +* +* @example +* var queue = new FIFO(); +* +* queue.push( 1 ).push( 2 ).push( 3 ); +* +* function predicate( v ) { +* return v > 0; +* } +* +* var bool = queue.every( predicate ); +* // returns true +* +* function predicate( v ) { +* return v % 2 === 0; +* } +* +* bool = queue.every( predicate ); +* // returns false +*/ +setReadOnly( FIFO.prototype, 'every', function every( predicate, thisArg ) { + var snapshot; + var i; + + if ( !isFIFO( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + snapshot = this.toArray(); + for ( i = 0; i < snapshot.length; i++ ) { + if ( !predicate.call( thisArg, snapshot[ i ], i, this ) ) { + return false; + } + } + return true; +}); + +/** +* Returns a queue element at a specified index. +* +* @name get +* @memberof FIFO.prototype +* @type {Function} +* @param {NonNegativeInteger} idx - element index +* @throws {TypeError} `this` must be a FIFO +* @throws {TypeError} index argument must be a nonnegative integer +* @returns {(*|void)} queue element or undefined +* +* @example +* var queue = new FIFO(); +* +* queue.push( 'foo' ).push( 'bar' ).push( 'baz' ); +* +* var v = queue.get( 0 ); +* // returns 'foo' +* +* v = queue.get( 1 ); +* // returns 'bar' +* +* v = queue.get( 100 ); +* // returns undefined +*/ +setReadOnly( FIFO.prototype, 'get', function get( idx ) { + var node; + var i; + + if ( !isFIFO( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO.' ); + } + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); + } + if ( idx >= this._length ) { + return; + } + node = this._first; + for ( i = 0; i < idx; i++ ) { + node = node.next; + } + return node.value; +}); + +/** +* Sets a queue element at a specified index. +* +* @name set +* @memberof FIFO.prototype +* @type {Function} +* @param {*} value - value to set +* @param {NonNegativeInteger} idx - element index (default: 0) +* @throws {TypeError} `this` must be a FIFO +* @throws {TypeError} index argument must be a nonnegative integer +* @throws {RangeError} index argument is out-of-bounds +* @returns {void} +* +* @example +* var queue = new FIFO(); +* +* queue.push( 'foo' ).push( 'bar' ).push( 'baz' ); +* +* queue.set( 'beep', 0 ); +* var v = queue.get( 0 ); +* // returns 'beep' +* +* queue.set( 'boop', 1 ); +* v = queue.get( 1 ); +* // returns 'boop' +*/ +setReadOnly( FIFO.prototype, 'set', function set( value ) { + var idx; + var node; + var i; + + if ( !isFIFO( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO.' ); + } + idx = arguments.length > 1 ? arguments[ 1 ] : 0; + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); + } + if ( idx >= this._length ) { + throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); + } + node = this._first; + for ( i = 0; i < idx; i++ ) { + node = node.next; + } + node.value = value; +}); + /** * Returns the "oldest" queue value (i.e., the value which is "first-out"). * diff --git a/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js b/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js new file mode 100644 index 000000000000..d09aa4df5387 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js @@ -0,0 +1,284 @@ +/** +* @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 tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var FIFO = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof FIFO, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `every` method for returning boolean indicating whether all elements pass a test', function test( t ) { + t.strictEqual( hasOwnProp( FIFO.prototype, 'every' ), true, 'has property' ); + t.strictEqual( isFunction( FIFO.prototype.every ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a FIFO instance', function test( t ) { + var values; + var queue; + var i; + + queue = new FIFO(); + queue.push( 'foo' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return queue.every.call( value, predicate ); + }; + } + + function predicate( v ) { + return v === 'foo'; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var queue; + var i; + + queue = new FIFO(); + queue.push( 'foo' ); + queue.push( 'bar' ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return queue.every( value ); + }; + } +}); + +tape( 'the method returns `true` if operating on an empty queue', function test( t ) { + var bool; + var queue; + + queue = new FIFO(); + bool = queue.every( predicate ); + + t.strictEqual( bool, true, 'returns expected value (vacuous truth)' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns `true` if all elements pass a test', function test( t ) { + var bool; + var queue; + + queue = new FIFO(); + queue.push( 2 ); + queue.push( 4 ); + queue.push( 6 ); + queue.push( 8 ); + + bool = queue.every( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return v % 2 === 0; + } +}); + +tape( 'the method returns `false` if one or more elements fail a test', function test( t ) { + var bool; + var queue; + + queue = new FIFO(); + queue.push( 2 ); + queue.push( 4 ); + queue.push( 5 ); + queue.push( 8 ); + + bool = queue.every( predicate ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return v % 2 === 0; + } +}); + +tape( 'the method returns `false` on first element that fails the test', function test( t ) { + var bool; + var queue; + var count; + + queue = new FIFO(); + queue.push( 2 ); + queue.push( 4 ); + queue.push( 5 ); + queue.push( 8 ); + queue.push( 10 ); + + count = 0; + bool = queue.every( predicate ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.strictEqual( count, 3, 'invoked correct number of times (short-circuit)' ); + t.end(); + + function predicate( v ) { + count += 1; + return v % 2 === 0; + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var bool; + var ctx; + var queue; + + ctx = { + 'count': 0 + }; + queue = new FIFO(); + queue.push( 1 ); + queue.push( 2 ); + queue.push( 3 ); + queue.push( 4 ); + + bool = queue.every( predicate, ctx ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected context count' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v > 0; + } +}); + +tape( 'the method provides the element value, index, and queue as arguments to the predicate', function test( t ) { + var queue; + var indices; + var values; + + queue = new FIFO(); + queue.push( 'a' ); + queue.push( 'b' ); + queue.push( 'c' ); + + values = []; + indices = []; + + queue.every( predicate ); + + t.deepEqual( values, [ 'a', 'b', 'c' ], 'passes element values' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'passes indices' ); + + t.end(); + + function predicate( v, i, q ) { + values.push( v ); + indices.push( i ); + t.strictEqual( q, queue, 'passes queue as third argument' ); + return true; + } +}); + +tape( 'the method works with different data types', function test( t ) { + var bool; + var queue; + + queue = new FIFO(); + queue.push( 0 ); + queue.push( 1 ); + queue.push( 2 ); + + bool = queue.every( function( v ) { + return typeof v === 'number'; + }); + + t.strictEqual( bool, true, 'works with numbers' ); + + queue = new FIFO(); + queue.push( 'foo' ); + queue.push( 'bar' ); + queue.push( 'baz' ); + + bool = queue.every( function( v ) { + return typeof v === 'string'; + }); + + t.strictEqual( bool, true, 'works with strings' ); + + queue = new FIFO(); + queue.push( true ); + queue.push( false ); + queue.push( true ); + + bool = queue.every( function( v ) { + return typeof v === 'boolean'; + }); + + t.strictEqual( bool, true, 'works with booleans' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/test/test.get.js b/lib/node_modules/@stdlib/dstructs/fifo/test/test.get.js new file mode 100644 index 000000000000..43534d899742 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/fifo/test/test.get.js @@ -0,0 +1,137 @@ +/* +* @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 tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var FIFO = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof FIFO, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `get` method for returning a queue element', function test( t ) { + t.strictEqual( hasOwnProp( FIFO.prototype, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( FIFO.prototype.get ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a FIFO instance', function test( t ) { + var values; + var q; + var i; + + q = new FIFO(); + q.push( 'foo' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return q.get.call( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is not a nonnegative integer', function test( t ) { + var values; + var q; + var i; + + q = new FIFO(); + q.push( 1 ); + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return q.get( value ); + }; + } +}); + +tape( 'the method returns `undefined` if provided an index which exceeds queue length', function test( t ) { + var q; + var v; + var i; + + q = new FIFO(); + q.push( 'a' ); + q.push( 'b' ); + for ( i = 0; i < q.length; i++ ) { + v = q.get( q.length + i ); + t.strictEqual( v, void 0, 'returns expected value for index '+(q.length+i) ); + } + t.end(); +}); + +tape( 'the method returns a queue element', function test( t ) { + var q; + var v; + var i; + + q = new FIFO(); + q.push( 1 ); + q.push( 2 ); + q.push( 3 ); + + for ( i = 0; i < q.length; i++ ) { + v = q.get( i ); + t.strictEqual( v, i+1, 'returns expected value for index '+i ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js b/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js new file mode 100644 index 000000000000..f10bdafba0c8 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js @@ -0,0 +1,181 @@ +/* +* @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 tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var FIFO = require( './../lib' ); + + +// TESTS // + + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof FIFO, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `set` method for setting one or more queue elements', function test( t ) { + t.strictEqual( hasOwnProp( FIFO.prototype, 'set' ), true, 'has property' ); + t.strictEqual( isFunction( FIFO.prototype.set ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a FIFO instance', function test( t ) { + var values; + var q; + var i; + + q = new FIFO(); + q.push( 'foo' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return q.set.call( value, 'a', 0 ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is not a nonnegative integer', function test( t ) { + var values; + var q; + var i; + + q = new FIFO(); + q.push( 'foo' ); + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return q.set( 'x', value ); + }; + } +}); + +tape( 'the method throws a RangeError if provided an index argument which is out-of-bounds', function test( t ) { + var values; + var q; + var i; + + q = new FIFO(); + q.push( 1 ); + q.push( 2 ); + + values = [ + q.length, + q.length + 1, + q.length + 2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return q.set( 'x', value ); + }; + } +}); + +tape( 'the method sets a queue element (default index)', function test( t ) { + var q; + var v; + + q = new FIFO(); + q.push( 'a' ); + q.push( 'b' ); + + q.set( 'z' ); + v = q.get( 0 ); + t.strictEqual( v, 'z', 'sets first element when no index provided' ); + t.end(); +}); + +tape( 'the method sets a queue element (specified index)', function test( t ) { + var q; + var v; + + q = new FIFO(); + q.push( 'a' ); + q.push( 'b' ); + q.push( 'c' ); + + q.set( 'x', 1 ); + v = q.get( 1 ); + t.strictEqual( v, 'x', 'sets element at index 1' ); + t.end(); +}); + +tape( 'queue instances support numeric indexing (read)', function test( t ) { + var q = new FIFO(); + q.push( 'a' ).push( 'b' ).push( 'c' ); + + t.strictEqual( q.get( 0 ), 'a', 'get(0) matches' ); + t.strictEqual( q.get( 1 ), 'b', 'get(1) matches' ); + t.strictEqual( q.get( 2 ), 'c', 'get(2) matches' ); + t.strictEqual( q.length, 3, 'length property accessible' ); + t.end(); +}); + +tape( 'queue instances support numeric indexing (write)', function test( t ) { + var q = new FIFO(); + q.push( 'a' ).push( 'b' ); + + q.set( 'x', 1 ); + t.strictEqual( q.get( 1 ), 'x', 'set(1) updated element' ); + t.end(); +}); From 318ccef01950556200d76d6640ad228abd5ae9fd Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 4 Mar 2026 17:42:10 +0530 Subject: [PATCH 02/11] chore: clean up --- .../@stdlib/dstructs/fifo/README.md | 20 +- .../dstructs/fifo/benchmark/benchmark.get.js | 44 ++-- .../dstructs/fifo/benchmark/benchmark.set.js | 44 ++-- .../@stdlib/dstructs/fifo/docs/repl.txt | 5 +- .../dstructs/fifo/docs/types/index.d.ts | 16 +- .../@stdlib/dstructs/fifo/examples/index.js | 2 +- .../@stdlib/dstructs/fifo/lib/main.js | 25 +- .../@stdlib/dstructs/fifo/test/test.every.js | 4 +- .../@stdlib/dstructs/fifo/test/test.get.js | 180 ++++++------- .../@stdlib/dstructs/fifo/test/test.set.js | 242 +++++++++--------- 10 files changed, 280 insertions(+), 302 deletions(-) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/README.md b/lib/node_modules/@stdlib/dstructs/fifo/README.md index 750472c08d6d..d4321139b2b5 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/README.md +++ b/lib/node_modules/@stdlib/dstructs/fifo/README.md @@ -85,26 +85,19 @@ len = queue.length; Tests whether all elements in a queue pass a test implemented by a predicate function. ```javascript -var queue = fifo(); - -// Add values to the queue: -queue.push( 1 ).push( 2 ).push( 3 ); - // Test whether all elements are greater than 0: function predicate( v ) { return v > 0; } -var bool = queue.every( predicate ); -// returns true +var queue = fifo(); +// returns -// Test whether all elements are even: -function predicate( v ) { - return v % 2 === 0; -} +// Add values to the queue: +queue.push( 1 ).push( 2 ).push( 3 ); -bool = queue.every( predicate ); -// returns false +var bool = queue.every( predicate ); +// returns true ``` The `predicate` function is provided three arguments: @@ -183,7 +176,6 @@ v = queue.get( 10 ); queue[ 0 ] = 'foo'; console.log( queue[ 0 ] ); // => 'foo' - ``` ##### queue.iterator() diff --git a/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.get.js b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.get.js index 673d0092838d..aeb16a1d9298 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.get.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.get.js @@ -29,26 +29,26 @@ var FIFO = require( './../lib' ); // MAIN // bench( format( '%s:get', pkg ), function benchmark( b ) { - var q; - var v; - var i; - - q = new FIFO(); - for ( i = 1; i <= 4; i++ ) { - q.push( i ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = q.get( i%4 ); - if ( typeof v === 'undefined' ) { - b.fail( 'should return a value' ); - } - } - b.toc(); - if ( typeof v === 'undefined' ) { - b.fail( 'should return a value' ); - } - b.pass( 'benchmark finished' ); - b.end(); + var q; + var v; + var i; + + q = new FIFO(); + for ( i = 1; i <= 4; i++ ) { + q.push( i ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = q.get( i%4 ); + if ( typeof v === 'undefined' ) { + b.fail( 'should return a value' ); + } + } + b.toc(); + if ( typeof v === 'undefined' ) { + b.fail( 'should return a value' ); + } + b.pass( 'benchmark finished' ); + b.end(); }); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js index 1a0c9301d4f0..b791711da983 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js @@ -30,26 +30,26 @@ var FIFO = require( './../lib' ); bench( format( '%s:set', pkg ), function benchmark( b ) { - var q; - var v; - var i; - - q = new FIFO(); - for ( i = 1; i <= 4; i++ ) { - q.push( i ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = q.set( i%4, i%4 ); // value, index - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); + var q; + var v; + var i; + + q = new FIFO(); + for ( i = 1; i <= 4; i++ ) { + q.push( i ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = q.set( i%4, i%4 ); // value, index + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); }); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt index cc362b5eb5e2..25edfc1f31ef 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt @@ -73,6 +73,8 @@ {{alias}}.prototype.every( predicate[, thisArg] ) Returns a boolean indicating whether all elements in the queue pass a test. + If the queue is empty, the method returns `true`. + The predicate function is provided three arguments: - value: current queue element. @@ -109,7 +111,8 @@ {{alias}}.prototype.get( index ) Returns a queue element at a specified index. - if index is out-of-bounds then this will return undefined. + If provided an index outside the queue index range, the method returns + `undefined`. Parameters ---------- diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts index e0586d505a0b..7c4e0a581938 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts @@ -136,7 +136,6 @@ declare class FIFO { * * ## Notes * - * - The method does not change the queue, it returns a boolean indicating whether all elements pass the test. * - If the queue is empty, the method returns `true`. * * @param predicate - predicate function to test queue elements @@ -145,23 +144,16 @@ declare class FIFO { * @returns boolean indicating whether all elements pass a test * * @example - * var queue = new FIFO(); - * - * queue.push( 1 ).push( 2 ).push( 3 ); - * * function predicate( v ) { * return v > 0; * } + * + * var queue = new FIFO(); + * + * queue.push( 1 ).push( 2 ).push( 3 ); * * var bool = queue.every( predicate ); * // returns true - * - * function predicate( v ) { - * return v % 2 === 0; - * } - * - * bool = queue.every( predicate ); - * // returns false */ every( predicate: Predicate, thisArg?: ThisParameterType> ): boolean; diff --git a/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js b/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js index f1f67d61d101..62046b0de5f3 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js @@ -29,7 +29,7 @@ queue.push( 'bar' ); queue.push( 'beep' ); queue.push( 'boop' ); -// Inspecting accessor-protocol implementation: +// Inspect accessor-protocol implementation: queue.set( 'bop', 3 ); v = queue.get( 3 ); console.log( 'Value: %s', v ); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js index 83f766969192..f642448a782a 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js @@ -129,9 +129,7 @@ setReadOnly( FIFO.prototype, 'clear', function clear() { * * ## Notes * -* - The method does not change the queue; it returns a boolean indicating whether all elements pass the test. * - If the queue is empty, the method returns `true`. -* - The method creates a "snapshot" of the queue at the time of invocation to handle potential queue mutations during iteration. * * @name every * @memberof FIFO.prototype @@ -143,26 +141,19 @@ setReadOnly( FIFO.prototype, 'clear', function clear() { * @returns {boolean} boolean indicating whether all elements pass a test * * @example -* var queue = new FIFO(); -* -* queue.push( 1 ).push( 2 ).push( 3 ); -* * function predicate( v ) { * return v > 0; * } * -* var bool = queue.every( predicate ); -* // returns true +* var queue = new FIFO(); * -* function predicate( v ) { -* return v % 2 === 0; -* } +* queue.push( 1 ).push( 2 ).push( 3 ); * -* bool = queue.every( predicate ); -* // returns false +* var bool = queue.every( predicate ); +* // returns true */ setReadOnly( FIFO.prototype, 'every', function every( predicate, thisArg ) { - var snapshot; + var buf; var i; if ( !isFIFO( this ) ) { @@ -171,9 +162,9 @@ setReadOnly( FIFO.prototype, 'every', function every( predicate, thisArg ) { if ( !isFunction( predicate ) ) { throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); } - snapshot = this.toArray(); - for ( i = 0; i < snapshot.length; i++ ) { - if ( !predicate.call( thisArg, snapshot[ i ], i, this ) ) { + buf = this.toArray(); + for ( i = 0; i < buf.length; i++ ) { + if ( !predicate.call( thisArg, buf[ i ], i, this ) ) { return false; } } diff --git a/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js b/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js index d09aa4df5387..7bd72200084c 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js @@ -115,7 +115,7 @@ tape( 'the method returns `true` if operating on an empty queue', function test( queue = new FIFO(); bool = queue.every( predicate ); - t.strictEqual( bool, true, 'returns expected value (vacuous truth)' ); + t.strictEqual( bool, true, 'returns expected value' ); t.end(); function predicate() { @@ -139,7 +139,7 @@ tape( 'the method returns `true` if all elements pass a test', function test( t t.end(); function predicate( v ) { - return v % 2 === 0; + return v > 0; } }); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/test/test.get.js b/lib/node_modules/@stdlib/dstructs/fifo/test/test.get.js index 43534d899742..d5a1ebfd87a2 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/test/test.get.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/test/test.get.js @@ -29,109 +29,109 @@ var FIFO = require( './../lib' ); // TESTS // tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof FIFO, 'function', 'main export is a function' ); - t.end(); + t.ok( true, __filename ); + t.strictEqual( typeof FIFO, 'function', 'main export is a function' ); + t.end(); }); tape( 'attached to the prototype of the main export is a `get` method for returning a queue element', function test( t ) { - t.strictEqual( hasOwnProp( FIFO.prototype, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( FIFO.prototype.get ), true, 'has method' ); - t.end(); + t.strictEqual( hasOwnProp( FIFO.prototype, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( FIFO.prototype.get ), true, 'has method' ); + t.end(); }); tape( 'the method throws an error if invoked with a `this` context which is not a FIFO instance', function test( t ) { - var values; - var q; - var i; - - q = new FIFO(); - q.push( 'foo' ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return q.get.call( value, 0 ); - }; - } + var values; + var q; + var i; + + q = new FIFO(); + q.push( 'foo' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return q.get.call( value, 0 ); + }; + } }); tape( 'the method throws an error if provided an index argument which is not a nonnegative integer', function test( t ) { - var values; - var q; - var i; - - q = new FIFO(); - q.push( 1 ); - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return q.get( value ); - }; - } + var values; + var q; + var i; + + q = new FIFO(); + q.push( 1 ); + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return q.get( value ); + }; + } }); tape( 'the method returns `undefined` if provided an index which exceeds queue length', function test( t ) { - var q; - var v; - var i; - - q = new FIFO(); - q.push( 'a' ); - q.push( 'b' ); - for ( i = 0; i < q.length; i++ ) { - v = q.get( q.length + i ); - t.strictEqual( v, void 0, 'returns expected value for index '+(q.length+i) ); - } - t.end(); + var q; + var v; + var i; + + q = new FIFO(); + q.push( 'a' ); + q.push( 'b' ); + for ( i = 0; i < q.length; i++ ) { + v = q.get( q.length + i ); + t.strictEqual( v, void 0, 'returns expected value for index '+(q.length+i) ); + } + t.end(); }); tape( 'the method returns a queue element', function test( t ) { - var q; - var v; - var i; - - q = new FIFO(); - q.push( 1 ); - q.push( 2 ); - q.push( 3 ); - - for ( i = 0; i < q.length; i++ ) { - v = q.get( i ); - t.strictEqual( v, i+1, 'returns expected value for index '+i ); - } - t.end(); + var q; + var v; + var i; + + q = new FIFO(); + q.push( 1 ); + q.push( 2 ); + q.push( 3 ); + + for ( i = 0; i < q.length; i++ ) { + v = q.get( i ); + t.strictEqual( v, i+1, 'returns expected value for index '+i ); + } + t.end(); }); diff --git a/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js b/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js index f10bdafba0c8..f4c5d199b086 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js @@ -30,152 +30,152 @@ var FIFO = require( './../lib' ); tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof FIFO, 'function', 'main export is a function' ); - t.end(); + t.ok( true, __filename ); + t.strictEqual( typeof FIFO, 'function', 'main export is a function' ); + t.end(); }); tape( 'attached to the prototype of the main export is a `set` method for setting one or more queue elements', function test( t ) { - t.strictEqual( hasOwnProp( FIFO.prototype, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( FIFO.prototype.set ), true, 'has method' ); - t.end(); + t.strictEqual( hasOwnProp( FIFO.prototype, 'set' ), true, 'has property' ); + t.strictEqual( isFunction( FIFO.prototype.set ), true, 'has method' ); + t.end(); }); tape( 'the method throws an error if invoked with a `this` context which is not a FIFO instance', function test( t ) { - var values; - var q; - var i; - - q = new FIFO(); - q.push( 'foo' ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return q.set.call( value, 'a', 0 ); - }; - } + var values; + var q; + var i; + + q = new FIFO(); + q.push( 'foo' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return q.set.call( value, 'a', 0 ); + }; + } }); tape( 'the method throws an error if provided an index argument which is not a nonnegative integer', function test( t ) { - var values; - var q; - var i; - - q = new FIFO(); - q.push( 'foo' ); - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return q.set( 'x', value ); - }; - } + var values; + var q; + var i; + + q = new FIFO(); + q.push( 'foo' ); + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return q.set( 'x', value ); + }; + } }); tape( 'the method throws a RangeError if provided an index argument which is out-of-bounds', function test( t ) { - var values; - var q; - var i; - - q = new FIFO(); - q.push( 1 ); - q.push( 2 ); - - values = [ - q.length, - q.length + 1, - q.length + 2 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return q.set( 'x', value ); - }; - } + var values; + var q; + var i; + + q = new FIFO(); + q.push( 1 ); + q.push( 2 ); + + values = [ + q.length, + q.length + 1, + q.length + 2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return q.set( 'x', value ); + }; + } }); tape( 'the method sets a queue element (default index)', function test( t ) { - var q; - var v; + var q; + var v; - q = new FIFO(); - q.push( 'a' ); - q.push( 'b' ); + q = new FIFO(); + q.push( 'a' ); + q.push( 'b' ); - q.set( 'z' ); - v = q.get( 0 ); - t.strictEqual( v, 'z', 'sets first element when no index provided' ); - t.end(); + q.set( 'z' ); + v = q.get( 0 ); + t.strictEqual( v, 'z', 'sets first element when no index provided' ); + t.end(); }); tape( 'the method sets a queue element (specified index)', function test( t ) { - var q; - var v; - - q = new FIFO(); - q.push( 'a' ); - q.push( 'b' ); - q.push( 'c' ); - - q.set( 'x', 1 ); - v = q.get( 1 ); - t.strictEqual( v, 'x', 'sets element at index 1' ); - t.end(); + var q; + var v; + + q = new FIFO(); + q.push( 'a' ); + q.push( 'b' ); + q.push( 'c' ); + + q.set( 'x', 1 ); + v = q.get( 1 ); + t.strictEqual( v, 'x', 'sets element at index 1' ); + t.end(); }); tape( 'queue instances support numeric indexing (read)', function test( t ) { - var q = new FIFO(); - q.push( 'a' ).push( 'b' ).push( 'c' ); - - t.strictEqual( q.get( 0 ), 'a', 'get(0) matches' ); - t.strictEqual( q.get( 1 ), 'b', 'get(1) matches' ); - t.strictEqual( q.get( 2 ), 'c', 'get(2) matches' ); - t.strictEqual( q.length, 3, 'length property accessible' ); - t.end(); + var q = new FIFO(); + q.push( 'a' ).push( 'b' ).push( 'c' ); + + t.strictEqual( q.get( 0 ), 'a', 'get(0) matches' ); + t.strictEqual( q.get( 1 ), 'b', 'get(1) matches' ); + t.strictEqual( q.get( 2 ), 'c', 'get(2) matches' ); + t.strictEqual( q.length, 3, 'length property accessible' ); + t.end(); }); tape( 'queue instances support numeric indexing (write)', function test( t ) { - var q = new FIFO(); - q.push( 'a' ).push( 'b' ); + var q = new FIFO(); + q.push( 'a' ).push( 'b' ); - q.set( 'x', 1 ); - t.strictEqual( q.get( 1 ), 'x', 'set(1) updated element' ); - t.end(); + q.set( 'x', 1 ); + t.strictEqual( q.get( 1 ), 'x', 'set(1) updated element' ); + t.end(); }); From 9f0582b2b11307cf12ce7162eaff5c005b498c33 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 4 Mar 2026 18:29:26 +0530 Subject: [PATCH 03/11] chore: updating docs --- .../@stdlib/dstructs/fifo/README.md | 37 ++++++++++++++----- .../@stdlib/dstructs/fifo/docs/repl.txt | 3 ++ .../dstructs/fifo/docs/types/index.d.ts | 16 +++++++- .../@stdlib/dstructs/fifo/lib/main.js | 4 ++ 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/README.md b/lib/node_modules/@stdlib/dstructs/fifo/README.md index d4321139b2b5..afca5860285c 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/README.md +++ b/lib/node_modules/@stdlib/dstructs/fifo/README.md @@ -151,7 +151,7 @@ var v = queue.first(); ##### queue.get( index ) -Returns a queue element at a specified index using the accessor protocol. +Returns a queue element located at a nonnegative integer position (index) `i`. ```javascript var queue = fifo(); @@ -168,14 +168,16 @@ v = queue.get( 1 ); v = queue.get( 2 ); // returns 'baz' +``` + +If provided an out-of-bounds index, the method returns `undefined`. + +```javascript +var queue = fifo(); // Out-of-bounds indices return undefined: -v = queue.get( 10 ); +var v = queue.get( 10 ); // returns undefined - -queue[ 0 ] = 'foo'; -console.log( queue[ 0 ] ); -// => 'foo' ``` ##### queue.iterator() @@ -302,10 +304,27 @@ var v = queue.get( 0 ); queue.set( 'boop', 1 ); v = queue.get( 1 ); // returns 'boop' +``` + +By default, the method sets queue elements starting at position (index) `i = 0`. To set elements starting elsewhere in the queue, provide an index argument `i`. + +```javascript +var queue = fifo(); +// returns + +// Add values to the queue: +queue.push( 'foo' ).push( 'bar' ).push( 'baz' ); -// Out-of-bounds index throws an error: -queue.set( 'boom', 10 ); -// throws +// By default, sets element at index 0: +queue.set( 'beep' ); +var v = queue.get( 0 ); +// returns 'beep' + +// Set element at a specified index: +queue.set( 'boop', 1 ); + +v = queue.get( 1 ); +// returns 'boop' ``` ##### queue.toArray() diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt index 25edfc1f31ef..5ea64aea2a21 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt @@ -163,6 +163,9 @@ > q.set( 'boop', 1 ); > q.get( 1 ) 'boop' + > q.set( 'bop' ); + > q.get( 0 ) + 'bop' See Also diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts index 7c4e0a581938..f3f36fbc5c1a 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts @@ -147,7 +147,7 @@ declare class FIFO { * function predicate( v ) { * return v > 0; * } - * + * * var queue = new FIFO(); * * queue.push( 1 ).push( 2 ).push( 3 ); @@ -311,6 +311,10 @@ declare class FIFO { /** * Sets a queue element at a specified index. * + * ## Notes + * + * - If an index argument is not provided, the method sets a value at index `0`. + * * @param value - value to set * @param i - element index (default: 0) * @throws index argument must be a nonnegative integer @@ -324,6 +328,16 @@ declare class FIFO { * * var v = queue.get( 0 ); * // returns 'beep' + * + * queue.set( 'boop', 1 ); + * + * v = queue.get( 1 ); + * // returns 'boop' + * + * queue.set( 'beep' ); + * + * v = queue.get( 0 ); + * // returns 'beep' */ set( value: T, i?: number ): void; diff --git a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js index f642448a782a..8316b7eea1b7 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js @@ -219,6 +219,10 @@ setReadOnly( FIFO.prototype, 'get', function get( idx ) { /** * Sets a queue element at a specified index. * +* ## Notes +* +* - If an index argument is not provided, the method sets a value at index `0`. +* * @name set * @memberof FIFO.prototype * @type {Function} From 9eb6f1a98f789ae31fae9d2b7e5ef1f55fd193d8 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 4 Mar 2026 20:23:31 +0530 Subject: [PATCH 04/11] chore: use consistent description for get method --- lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt | 3 ++- lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/dstructs/fifo/lib/main.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt index 5ea64aea2a21..485c5145559d 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt @@ -109,7 +109,8 @@ {{alias}}.prototype.get( index ) - Returns a queue element at a specified index. + Returns a queue element located at a nonnegative integer + position (index) `i`. If provided an index outside the queue index range, the method returns `undefined`. diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts index f3f36fbc5c1a..c1c4d01b973e 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts @@ -175,7 +175,7 @@ declare class FIFO { first(): T | void; /** - * Returns a queue element. + * Returns a queue element located at a nonnegative integer position (index) `i`. * * @param i - element index * @throws index argument must be a nonnegative integer diff --git a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js index 8316b7eea1b7..4b2cd3ccfcd8 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js @@ -172,7 +172,7 @@ setReadOnly( FIFO.prototype, 'every', function every( predicate, thisArg ) { }); /** -* Returns a queue element at a specified index. +* Returns a queue element located at a nonnegative integer position (index) `i`. * * @name get * @memberof FIFO.prototype From f59f4ad14f31f7ab6742c55324094f7efc515c6b Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Thu, 26 Mar 2026 01:20:16 +0530 Subject: [PATCH 05/11] chore: clean up on every method --- .../@stdlib/dstructs/fifo/lib/main.js | 157 +++++++++--------- .../@stdlib/dstructs/fifo/test/test.every.js | 129 +++++++------- 2 files changed, 143 insertions(+), 143 deletions(-) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js index 4b2cd3ccfcd8..86da95e994bd 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js @@ -153,7 +153,7 @@ setReadOnly( FIFO.prototype, 'clear', function clear() { * // returns true */ setReadOnly( FIFO.prototype, 'every', function every( predicate, thisArg ) { - var buf; + var node; var i; if ( !isFIFO( this ) ) { @@ -162,134 +162,83 @@ setReadOnly( FIFO.prototype, 'every', function every( predicate, thisArg ) { if ( !isFunction( predicate ) ) { throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); } - buf = this.toArray(); - for ( i = 0; i < buf.length; i++ ) { - if ( !predicate.call( thisArg, buf[ i ], i, this ) ) { + node = this._first; + for ( i = 0; i < this._length; i++ ) { + if ( !predicate.call( thisArg, node.value, i, this ) ) { return false; } + node = node.next; } return true; }); /** -* Returns a queue element located at a nonnegative integer position (index) `i`. +* Returns the "oldest" queue value (i.e., the value which is "first-out"). * -* @name get +* @name first * @memberof FIFO.prototype * @type {Function} -* @param {NonNegativeInteger} idx - element index -* @throws {TypeError} `this` must be a FIFO -* @throws {TypeError} index argument must be a nonnegative integer -* @returns {(*|void)} queue element or undefined +* @returns {(*|void)} "oldest" queue value * * @example * var queue = new FIFO(); * -* queue.push( 'foo' ).push( 'bar' ).push( 'baz' ); +* // Add values to the queue: +* queue.push( 'foo' ).push( 'bar' ); * -* var v = queue.get( 0 ); +* // Peek at the first value: +* var v = queue.first(); * // returns 'foo' -* -* v = queue.get( 1 ); -* // returns 'bar' -* -* v = queue.get( 100 ); -* // returns undefined */ -setReadOnly( FIFO.prototype, 'get', function get( idx ) { - var node; - var i; - - if ( !isFIFO( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a FIFO.' ); - } - if ( !isNonNegativeInteger( idx ) ) { - throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); - } - if ( idx >= this._length ) { - return; - } - node = this._first; - for ( i = 0; i < idx; i++ ) { - node = node.next; +setReadOnly( FIFO.prototype, 'first', function first() { + if ( this._length ) { + return this._first.value; } - return node.value; }); /** -* Sets a queue element at a specified index. -* -* ## Notes -* -* - If an index argument is not provided, the method sets a value at index `0`. +* Returns a queue element located at a nonnegative integer position (index) `i`. * -* @name set +* @name get * @memberof FIFO.prototype * @type {Function} -* @param {*} value - value to set -* @param {NonNegativeInteger} idx - element index (default: 0) +* @param {NonNegativeInteger} idx - element index * @throws {TypeError} `this` must be a FIFO * @throws {TypeError} index argument must be a nonnegative integer -* @throws {RangeError} index argument is out-of-bounds -* @returns {void} +* @returns {(*|void)} queue element or undefined * * @example * var queue = new FIFO(); * * queue.push( 'foo' ).push( 'bar' ).push( 'baz' ); * -* queue.set( 'beep', 0 ); * var v = queue.get( 0 ); -* // returns 'beep' +* // returns 'foo' * -* queue.set( 'boop', 1 ); * v = queue.get( 1 ); -* // returns 'boop' +* // returns 'bar' +* +* v = queue.get( 100 ); +* // returns undefined */ -setReadOnly( FIFO.prototype, 'set', function set( value ) { - var idx; +setReadOnly( FIFO.prototype, 'get', function get( idx ) { var node; var i; if ( !isFIFO( this ) ) { throw new TypeError( 'invalid invocation. `this` is not a FIFO.' ); } - idx = arguments.length > 1 ? arguments[ 1 ] : 0; if ( !isNonNegativeInteger( idx ) ) { throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); } if ( idx >= this._length ) { - throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); + return; } node = this._first; for ( i = 0; i < idx; i++ ) { node = node.next; } - node.value = value; -}); - -/** -* Returns the "oldest" queue value (i.e., the value which is "first-out"). -* -* @name first -* @memberof FIFO.prototype -* @type {Function} -* @returns {(*|void)} "oldest" queue value -* -* @example -* var queue = new FIFO(); -* -* // Add values to the queue: -* queue.push( 'foo' ).push( 'bar' ); -* -* // Peek at the first value: -* var v = queue.first(); -* // returns 'foo' -*/ -setReadOnly( FIFO.prototype, 'first', function first() { - if ( this._length ) { - return this._first.value; - } + return node.value; }); /** @@ -544,6 +493,58 @@ setReadOnly( FIFO.prototype, 'push', function push( value ) { return this; }); +/** +* Sets a queue element at a specified index. +* +* ## Notes +* +* - If an index argument is not provided, the method sets a value at index `0`. +* +* @name set +* @memberof FIFO.prototype +* @type {Function} +* @param {*} value - value to set +* @param {NonNegativeInteger} idx - element index (default: 0) +* @throws {TypeError} `this` must be a FIFO +* @throws {TypeError} index argument must be a nonnegative integer +* @throws {RangeError} index argument is out-of-bounds +* @returns {void} +* +* @example +* var queue = new FIFO(); +* +* queue.push( 'foo' ).push( 'bar' ).push( 'baz' ); +* +* queue.set( 'beep', 0 ); +* var v = queue.get( 0 ); +* // returns 'beep' +* +* queue.set( 'boop', 1 ); +* v = queue.get( 1 ); +* // returns 'boop' +*/ +setReadOnly( FIFO.prototype, 'set', function set( value ) { + var idx; + var node; + var i; + + if ( !isFIFO( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO.' ); + } + idx = arguments.length > 1 ? arguments[ 1 ] : 0; + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); + } + if ( idx >= this._length ) { + throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); + } + node = this._first; + for ( i = 0; i < idx; i++ ) { + node = node.next; + } + node.value = value; +}); + /** * Returns an array of queue values. * diff --git a/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js b/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js index 7bd72200084c..41705f5d4f8c 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js @@ -42,11 +42,11 @@ tape( 'attached to the prototype of the main export is an `every` method for ret tape( 'the method throws an error if invoked with a `this` context which is not a FIFO instance', function test( t ) { var values; - var queue; + var q; var i; - queue = new FIFO(); - queue.push( 'foo' ); + q = new FIFO(); + q.push( 'foo' ); values = [ '5', @@ -67,7 +67,7 @@ tape( 'the method throws an error if invoked with a `this` context which is not function badValue( value ) { return function badValue() { - return queue.every.call( value, predicate ); + return q.every.call( value, predicate ); }; } @@ -78,12 +78,12 @@ tape( 'the method throws an error if invoked with a `this` context which is not tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { var values; - var queue; + var q; var i; - queue = new FIFO(); - queue.push( 'foo' ); - queue.push( 'bar' ); + q = new FIFO(); + q.push( 'foo' ); + q.push( 'bar' ); values = [ '5', @@ -103,17 +103,17 @@ tape( 'the method throws an error if provided a first argument which is not a fu function badValue( value ) { return function badValue() { - return queue.every( value ); + return q.every( value ); }; } }); tape( 'the method returns `true` if operating on an empty queue', function test( t ) { var bool; - var queue; + var q; - queue = new FIFO(); - bool = queue.every( predicate ); + q = new FIFO(); + bool = q.every( predicate ); t.strictEqual( bool, true, 'returns expected value' ); t.end(); @@ -125,15 +125,15 @@ tape( 'the method returns `true` if operating on an empty queue', function test( tape( 'the method returns `true` if all elements pass a test', function test( t ) { var bool; - var queue; + var q; - queue = new FIFO(); - queue.push( 2 ); - queue.push( 4 ); - queue.push( 6 ); - queue.push( 8 ); + q = new FIFO(); + q.push( 2 ); + q.push( 4 ); + q.push( 6 ); + q.push( 8 ); - bool = queue.every( predicate ); + bool = q.every( predicate ); t.strictEqual( bool, true, 'returns expected value' ); t.end(); @@ -145,15 +145,15 @@ tape( 'the method returns `true` if all elements pass a test', function test( t tape( 'the method returns `false` if one or more elements fail a test', function test( t ) { var bool; - var queue; + var q; - queue = new FIFO(); - queue.push( 2 ); - queue.push( 4 ); - queue.push( 5 ); - queue.push( 8 ); + q = new FIFO(); + q.push( 2 ); + q.push( 4 ); + q.push( 5 ); + q.push( 8 ); - bool = queue.every( predicate ); + bool = q.every( predicate ); t.strictEqual( bool, false, 'returns expected value' ); t.end(); @@ -165,18 +165,18 @@ tape( 'the method returns `false` if one or more elements fail a test', function tape( 'the method returns `false` on first element that fails the test', function test( t ) { var bool; - var queue; + var q; var count; - queue = new FIFO(); - queue.push( 2 ); - queue.push( 4 ); - queue.push( 5 ); - queue.push( 8 ); - queue.push( 10 ); + q = new FIFO(); + q.push( 2 ); + q.push( 4 ); + q.push( 5 ); + q.push( 8 ); + q.push( 10 ); count = 0; - bool = queue.every( predicate ); + bool = q.every( predicate ); t.strictEqual( bool, false, 'returns expected value' ); t.strictEqual( count, 3, 'invoked correct number of times (short-circuit)' ); @@ -191,18 +191,17 @@ tape( 'the method returns `false` on first element that fails the test', functio tape( 'the method supports providing an execution context', function test( t ) { var bool; var ctx; - var queue; + var q; ctx = { 'count': 0 }; - queue = new FIFO(); - queue.push( 1 ); - queue.push( 2 ); - queue.push( 3 ); - queue.push( 4 ); - - bool = queue.every( predicate, ctx ); + q = new FIFO(); + q.push( 1 ); + q.push( 2 ); + q.push( 3 ); + q.push( 4 ); + bool = q.every( predicate, ctx ); t.strictEqual( bool, true, 'returns expected value' ); t.strictEqual( ctx.count, 4, 'returns expected context count' ); @@ -216,19 +215,19 @@ tape( 'the method supports providing an execution context', function test( t ) { }); tape( 'the method provides the element value, index, and queue as arguments to the predicate', function test( t ) { - var queue; + var q; var indices; var values; - queue = new FIFO(); - queue.push( 'a' ); - queue.push( 'b' ); - queue.push( 'c' ); + q = new FIFO(); + q.push( 'a' ); + q.push( 'b' ); + q.push( 'c' ); values = []; indices = []; - queue.every( predicate ); + q.every( predicate ); t.deepEqual( values, [ 'a', 'b', 'c' ], 'passes element values' ); t.deepEqual( indices, [ 0, 1, 2 ], 'passes indices' ); @@ -238,43 +237,43 @@ tape( 'the method provides the element value, index, and queue as arguments to t function predicate( v, i, q ) { values.push( v ); indices.push( i ); - t.strictEqual( q, queue, 'passes queue as third argument' ); + t.strictEqual( q, q, 'passes queue as third argument' ); return true; } }); tape( 'the method works with different data types', function test( t ) { var bool; - var queue; + var q; - queue = new FIFO(); - queue.push( 0 ); - queue.push( 1 ); - queue.push( 2 ); + q = new FIFO(); + q.push( 0 ); + q.push( 1 ); + q.push( 2 ); - bool = queue.every( function( v ) { + bool = q.every( function( v ) { return typeof v === 'number'; }); t.strictEqual( bool, true, 'works with numbers' ); - queue = new FIFO(); - queue.push( 'foo' ); - queue.push( 'bar' ); - queue.push( 'baz' ); + q = new FIFO(); + q.push( 'foo' ); + q.push( 'bar' ); + q.push( 'baz' ); - bool = queue.every( function( v ) { + bool = q.every( function( v ) { return typeof v === 'string'; }); t.strictEqual( bool, true, 'works with strings' ); - queue = new FIFO(); - queue.push( true ); - queue.push( false ); - queue.push( true ); + q = new FIFO(); + q.push( true ); + q.push( false ); + q.push( true ); - bool = queue.every( function( v ) { + bool = q.every( function( v ) { return typeof v === 'boolean'; }); From 17f1aeecc400a46163b8516c1a64b788550eb260 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 14 Apr 2026 12:45:34 +0530 Subject: [PATCH 06/11] chore: clean up --- .../@stdlib/dstructs/fifo/docs/repl.txt | 13 ++++---- .../dstructs/fifo/docs/types/index.d.ts | 30 +++++++++++++++++-- .../@stdlib/dstructs/fifo/lib/main.js | 4 +-- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt index 485c5145559d..3cec7c2938ea 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt @@ -1,4 +1,3 @@ - {{alias}}() First-in-first-out (FIFO) queue constructor. @@ -58,11 +57,11 @@ > q.push( 'foo' ).push( 'bar' ).push( 'baz' ); > q.length 3 - > q[0] + > q.get( 0 ) 'foo' - > q[1] + > q.get( 1 ) 'bar' - > q[2] + > q.get( 2 ) 'baz' > q.pop() 'foo' @@ -100,11 +99,11 @@ -------- > var q = {{alias}}(); > q.push( 1 ).push( 2 ).push( 3 ); - > q.every( function predicate( v ) { return v > 0; } ) + > q.every( function( v ) { return v > 0; } ) true - > q.every( function predicate( v ) { return v > 2; } ) + > q.every( function( v ) { return v > 2; } ) false - > q.every( function predicate( v ) { return v % 2 === 0; } ) + > q.every( function( v ) { return v % 2 === 0; } ) false diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts index c1c4d01b973e..922c52801c55 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts @@ -74,13 +74,15 @@ type Predicate = NullaryPredicate | UnaryPredicate | BinaryPredic * * @template T - queue element type */ -declare class FIFO { +declare class FIFO { /** * First-in-first-out queue constructor. * * @returns FIFO queue instance * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * // Add values to the queue: @@ -105,6 +107,8 @@ declare class FIFO { * @returns queue instance * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * // Add values to the queue: @@ -144,6 +148,8 @@ declare class FIFO { * @returns boolean indicating whether all elements pass a test * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * function predicate( v ) { * return v > 0; * } @@ -163,6 +169,8 @@ declare class FIFO { * @returns "oldest" queue value * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * // Add values to the queue: @@ -182,6 +190,8 @@ declare class FIFO { * @returns queue element * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * queue.push( 'foo' ).push( 'bar' ); @@ -204,6 +214,8 @@ declare class FIFO { * @returns iterator * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * // Add values to the queue: @@ -230,6 +242,8 @@ declare class FIFO { * @returns "newest" queue value * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * // Add values to the queue: @@ -245,6 +259,8 @@ declare class FIFO { * Queue length. * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * // Examine the initial queue length: @@ -266,6 +282,8 @@ declare class FIFO { * @returns removed value * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * // Add values to the queue: @@ -290,6 +308,8 @@ declare class FIFO { * @returns queue instance * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * // Add values to the queue: @@ -322,6 +342,8 @@ declare class FIFO { * @throws target queue lacks sufficient storage to accommodate source values * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * queue.push( 'foo' ).push( 'bar' ).set( 'beep', 0 ); @@ -347,6 +369,8 @@ declare class FIFO { * @returns queue values * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * // Add values to the queue: @@ -368,6 +392,8 @@ declare class FIFO { * @returns serialized queue * * @example + * var FIFO = require( '@stdlib/dstructs/fifo' ); + * * var queue = new FIFO(); * * // Add values to the queue: @@ -377,7 +403,7 @@ declare class FIFO { * var o = queue.toJSON(); * // returns { 'type': 'fifo', 'data': [ 'foo', 'bar' ] } */ - toJSON(): any; + toJSON(): { type: string; data: Array }; } diff --git a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js index 86da95e994bd..556dbaab0688 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/lib/main.js @@ -524,14 +524,14 @@ setReadOnly( FIFO.prototype, 'push', function push( value ) { * // returns 'boop' */ setReadOnly( FIFO.prototype, 'set', function set( value ) { - var idx; var node; + var idx; var i; if ( !isFIFO( this ) ) { throw new TypeError( 'invalid invocation. `this` is not a FIFO.' ); } - idx = arguments.length > 1 ? arguments[ 1 ] : 0; + idx = ( arguments.length > 1 ) ? arguments[ 1 ] : 0; if ( !isNonNegativeInteger( idx ) ) { throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); } From 9cca594ae0e6ba086baa6b397fce6e38527958ac Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 14 Apr 2026 13:02:27 +0530 Subject: [PATCH 07/11] chore: clean up on docs --- lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt | 4 ++-- .../@stdlib/dstructs/fifo/docs/types/index.d.ts | 2 +- .../@stdlib/dstructs/fifo/examples/index.js | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt index 3cec7c2938ea..edf1a4778712 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt @@ -101,9 +101,9 @@ > q.push( 1 ).push( 2 ).push( 3 ); > q.every( function( v ) { return v > 0; } ) true - > q.every( function( v ) { return v > 2; } ) + > q.every( function( v ) { return v % 1 === 0; } ) false - > q.every( function( v ) { return v % 2 === 0; } ) + > q.every( function( v ) { return v > 2; } ) false diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts index 922c52801c55..92ba979ba4db 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/types/index.d.ts @@ -393,7 +393,7 @@ declare class FIFO { * * @example * var FIFO = require( '@stdlib/dstructs/fifo' ); - * + * * var queue = new FIFO(); * * // Add values to the queue: diff --git a/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js b/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js index 62046b0de5f3..9c373b603857 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/examples/index.js @@ -29,11 +29,6 @@ queue.push( 'bar' ); queue.push( 'beep' ); queue.push( 'boop' ); -// Inspect accessor-protocol implementation: -queue.set( 'bop', 3 ); -v = queue.get( 3 ); -console.log( 'Value: %s', v ); - // Peek at the first and last queue values: var v = queue.first(); console.log( 'First: %s', v ); @@ -41,6 +36,11 @@ console.log( 'First: %s', v ); v = queue.last(); console.log( 'Last: %s', v ); +// Inspect accessor-protocol implementation: +queue.set( 'bop', 3 ); +v = queue.get( 3 ); +console.log( 'Value: %s', v ); + // Inspect the queue length: var len = queue.length; console.log( 'Queue length: %d', len ); From baced2294f435585bf391755898402e2d14dc585 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 14 Apr 2026 13:16:26 +0530 Subject: [PATCH 08/11] chore: update test cases --- .../@stdlib/dstructs/fifo/docs/repl.txt | 6 +----- .../@stdlib/dstructs/fifo/test/test.every.js | 21 ++++++++----------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt index edf1a4778712..e64a06fae6a8 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt @@ -99,12 +99,8 @@ -------- > var q = {{alias}}(); > q.push( 1 ).push( 2 ).push( 3 ); - > q.every( function( v ) { return v > 0; } ) + > q.every( predicate ) true - > q.every( function( v ) { return v % 1 === 0; } ) - false - > q.every( function( v ) { return v > 2; } ) - false {{alias}}.prototype.get( index ) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js b/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js index 41705f5d4f8c..9892ab0759be 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/test/test.every.js @@ -164,9 +164,9 @@ tape( 'the method returns `false` if one or more elements fail a test', function }); tape( 'the method returns `false` on first element that fails the test', function test( t ) { + var count; var bool; var q; - var count; q = new FIFO(); q.push( 2 ); @@ -215,9 +215,9 @@ tape( 'the method supports providing an execution context', function test( t ) { }); tape( 'the method provides the element value, index, and queue as arguments to the predicate', function test( t ) { - var q; var indices; var values; + var q; q = new FIFO(); q.push( 'a' ); @@ -251,9 +251,7 @@ tape( 'the method works with different data types', function test( t ) { q.push( 1 ); q.push( 2 ); - bool = q.every( function( v ) { - return typeof v === 'number'; - }); + bool = q.every( predicate ); t.strictEqual( bool, true, 'works with numbers' ); @@ -262,9 +260,7 @@ tape( 'the method works with different data types', function test( t ) { q.push( 'bar' ); q.push( 'baz' ); - bool = q.every( function( v ) { - return typeof v === 'string'; - }); + bool = q.every( predicate ); t.strictEqual( bool, true, 'works with strings' ); @@ -273,11 +269,12 @@ tape( 'the method works with different data types', function test( t ) { q.push( false ); q.push( true ); - bool = q.every( function( v ) { - return typeof v === 'boolean'; - }); + bool = q.every( predicate ); t.strictEqual( bool, true, 'works with booleans' ); - t.end(); + + function predicate( v ) { + return v !== void 0; + } }); From d7d30371ae23e2602aa069d81cdf1a80d8ca723f Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 14 Apr 2026 13:22:27 +0530 Subject: [PATCH 09/11] chore: add predicate function to repl.txt --- lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt | 1 + lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt index e64a06fae6a8..7619f18e0aab 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt @@ -97,6 +97,7 @@ Examples -------- + > function predicate( v ) { return v > 0; }; > var q = {{alias}}(); > q.push( 1 ).push( 2 ).push( 3 ); > q.every( predicate ) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js b/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js index f4c5d199b086..2d3387adacda 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/test/test.set.js @@ -28,7 +28,6 @@ var FIFO = require( './../lib' ); // TESTS // - tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); t.strictEqual( typeof FIFO, 'function', 'main export is a function' ); From 943d31c03bc4d8941625f14d44d8b4ece3855a0a Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 14 Apr 2026 13:25:22 +0530 Subject: [PATCH 10/11] chore: remove extra line in benchmark --- .../@stdlib/dstructs/fifo/benchmark/benchmark.set.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js index b791711da983..b3359ec9a610 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js +++ b/lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.set.js @@ -28,7 +28,6 @@ var FIFO = require( './../lib' ); // MAIN // - bench( format( '%s:set', pkg ), function benchmark( b ) { var q; var v; From 8d813a871561da720d4e61ffaa0bea30fa0653b8 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 15 Apr 2026 01:04:03 +0530 Subject: [PATCH 11/11] chore: add extra line above alias Signed-off-by: Neeraj Pathak --- lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt index 7619f18e0aab..0993577a8179 100644 --- a/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt +++ b/lib/node_modules/@stdlib/dstructs/fifo/docs/repl.txt @@ -1,3 +1,4 @@ + {{alias}}() First-in-first-out (FIFO) queue constructor.