-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add accessor array protocol for dstructs/fifo
#11460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Neerajpathak07
wants to merge
11
commits into
stdlib-js:develop
Choose a base branch
from
Neerajpathak07:feat/fifo-accessor-array
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3a960cf
feat: add initial setup
Neerajpathak07 318ccef
chore: clean up
Neerajpathak07 9f0582b
chore: updating docs
Neerajpathak07 9eb6f1a
chore: use consistent description for get method
Neerajpathak07 f59f4ad
chore: clean up on every method
Neerajpathak07 17f1aee
chore: clean up
Neerajpathak07 9cca594
chore: clean up on docs
Neerajpathak07 baced22
chore: update test cases
Neerajpathak07 d7d3037
chore: add predicate function to repl.txt
Neerajpathak07 943d31c
chore: remove extra line in benchmark
Neerajpathak07 8d813a8
chore: add extra line above alias
Neerajpathak07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.every.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move predicate to a declaration, not an inline expression. |
||
| 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(); | ||
| }); | ||
115 changes: 115 additions & 0 deletions
115
lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.every.length.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); |
54 changes: 54 additions & 0 deletions
54
lib/node_modules/@stdlib/dstructs/fifo/benchmark/benchmark.get.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should index be optional here?