Train
![LICENSE](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)
![DEVDEPENDENCY STATUS](http://img.shields.io/david/dev/rootslab/train.svg?style=flat)
![NPM YEARLY](https://img.shields.io/npm/dy/train.svg)
![NPM GRAPH](https://nodei.co/npm/train.png?downloads=true&downloadRank=true&stars=true)
Train, a fast (FIFO) queue with rollback mechanism.
Behind the scenes, it uses 2 arrays, to simulate and perform fast shifting and popping operations, without using the Array#shift() method.
Note:
Array#shift method shows an high loss of performances when the array is very long; for example, on my laptop the bottleneck occurs when I fill an array with more than 2^17 items. It implies that for shorter array lengths, is still possible to use Array#shift.
Test by yourself launching benchmarks or manually tuning the power value p in this bench file.
If you need a simple (LIFO) Stack, try Peela.
Install
$ npm install train [-g]
require:
var Train = require( 'train' );
Run Tests
$ cd train/
$ npm test
Run Benchmarks
$ cd train/
$ npm run bench
Constructor
Create an instance, argument within [ ] is optional.
Train( [ Object opt ] )
new Train( [ Object opt ] )
#Options
Default options are listed.
{
head : []
, xlim : Infinity
, rlim : Infinity
}
Properties
Don't mess with these properties!
Train.length : Number
Train.xlim : Number
Train.rlim : Number
Train.ipos : Number
Train.hpos : Number
Train.rpos : Number
Train.roll : Boolean
Train.qhead : Array
Train.qtail : Array
Train.qroll : Array
Methods
Arguments within [ ] are optional.
Train#get( [ Number index ] ) : Object
Train#cget( [ Number index ] ) : Object
Train#indexOf( Object el [, Number offset ] ) : Object
Train#shift() : Object
Train#pop( [ Number k ] ) : Array
Train#slice( [ Number begin [, Number end ] ] ) : Array
Train#rollUp( [ Boolean on ] ) : Train
Train#rollBack( [ Boolean rollUp ] ) : Train
Train#curr() : Object
Train#next( [ Number index ] ) : Object
Train#push( [ Object obj1 [, Object obj2 .. ] ] ) : Number
Train#xpush( [ Object obj1 [, Object obj2 .. ] ] ) : Number
Train#fpush( [ Object obj ] ) : Number
Train#concat( [ Array array ] ) : Train
Train#xconcat( [ Array array ] ) : Number
Train#melt( [ Array tlist [, Boolean all ] ] ) : Number
Train#size() : Number
Train#flush( [ Boolean bool ] ) : Number
Train#forEach( Function fn [, Object scope ] ) : Train
Train#iterate( Function fn [, Object scope [, Function cback [, Boolean evict ] ] ] ) : Train
MIT License
Copyright (c) 2012-present < Guglielmo Ferri : 44gatti@gmail.com >
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.