nv-data-simple-fifo
v1.0.2
Published
nv-data-simple-fifo ======================= - fixed size fifo - simple-and-faster version of nv-data-fifo - its also slightly faster than nv-data-fixed-queue(which is a circular buffer)
Downloads
4
Readme
nv-data-simple-fifo
- fixed size fifo
- simple-and-faster version of nv-data-fifo
- its also slightly faster than nv-data-fixed-queue(which is a circular buffer)
install
- npm install nv-data-simple-fifo
usage
const x = require("nv-data-simple-fifo");
x : (max-count@le(2**26), empty-value=undefined ) -> Fifo
x.psuh : (<js-value #0>, callback_if_fifo_is_full:( #0 )->void) -> Boolean
x.shift : ( ) -> <js-value>
example
var fifo = x(6,null) // (max-count, empty-value)
const back_pressure_cb = (val)=> {
console.log("full",val,"NOT pushed")
}
push
/*
fifo.push("aa",back_pressure_cb)
fifo.push("bb",back_pressure_cb)
fifo.push("cc",back_pressure_cb)
fifo.push("dd",back_pressure_cb)
fifo.shift()
fifo.push('ee',back_pressure_cb)
fifo.push('ff',back_pressure_cb)
fifo.push('gg',back_pressure_cb)
*/
> fifo.push("aa",back_pressure_cb)
true
> fifo.push("bb",back_pressure_cb)
true
> fifo.datas_
[
null, // the slot 0 is unused, its value is meaning-less
'aa',
'bb',
null,
null,
null,
null
]
>
> fifo.fst_
'aa'
> fifo.lst_
'bb'
>
> fifo.push("cc",back_pressure_cb)
true
>
> fifo.push("dd",back_pressure_cb)
true
>
> fifo.fst_
'aa'
> fifo.lst_
'dd'
>
shift
> fifo.shift()
'aa'
>
> fifo.fst_
'bb'
> fifo.lst_
'dd'
> fifo.used_
3
> fifo.lefted_
3
>
> fifo.to_ary()
[ 'bb', 'cc', 'dd' ]
>
push
> fifo.push('ee',back_pressure_cb)
true
> fifo.push('ff',back_pressure_cb)
true
> fifo.push('gg',back_pressure_cb)
true
> fifo.datas_
[
null, 'gg',
'bb', 'cc',
'dd', 'ee',
'ff'
]
> fifo.fst_
'bb'
> fifo.lst_
'gg'
>
push when full
> fifo.push('hh',back_pressure_cb)
full hh NOT pushed
false
>
> fifo.datas_
[
'gg', 'aa',
'bb', 'cc',
'dd', 'ee',
'ff'
]
>
> fifo.push('hh',back_pressure_cb)
full gg NOT pushed
false
>
#shift > fifo.shift() 'bb' > fifo.shift() 'cc' > fifo.shift() 'dd' > fifo.shift() 'ee' > fifo.shift() 'ff' > fifo.shift() 'gg' > fifo.datas_ [ null, null, null, null, null, null, null ] >
shift when empty
> fifo.shift()
null
> fifo.is_empty_val(fifo.shift())
true
>
> fifo
Fifo [
{"used":0,"lefted":6}
empty=null;
list-view:
null -> ...... -> null
] {}
>
METHODS
APIS
fifo.constructor fifo.datas_ fifo.empty_ fifo.fst_ fifo.is_empty fifo.is_empty_at fifo.is_empty_val
fifo.is_full fifo.lefted_ fifo.lst_ fifo.max_cnt_ fifo.push fifo.rbs_ fifo.reset
fifo.shift fifo.show fifo.to_ary fifo.used_
LICENSE
- ISC