nv-data-fixed-queue
v1.0.0
Published
fixed-queue from nodejs lib/internal/fixed_queue.js
Downloads
13
Maintainers
Readme
nv-data-fixed-queue
- nv-data-fixed-queue
- wrap of https://github.com/nodejs/node/blob/178e52a7ead2ef9ffb6eb5e17be167f17beb45a8/lib/internal/fixed_queue.js
install
- npm install nv-data-fixed-queue
usage
- the code is from nodejs lib/internal/fixed_queue.js
- this structure is used in nodejs as a task-queue
- its useful when you modify nodejs
example
var {FixedCircularBuffer} = require("nv-data-fixed-queue")
var cir = new FixedCircularBuffer(4)
/*
> cir
FixedCircularBuffer {
bottom: 0,
top: 0,
list: [ <4 empty items> ],
next: null
}
> cir.push('a')
undefined
> cir
FixedCircularBuffer {
bottom: 0,
top: 1,
list: [ 'a', <3 empty items> ],
| |
bot top
next: null
}
>
> cir.push('b')
undefined
> cir
FixedCircularBuffer {
bottom: 0,
top: 2,
list: [ 'a', 'b', <2 empty items> ],
| |
bot top
next: null
}
> cir.shift()
'a'
>
> cir
FixedCircularBuffer {
bottom: 1,
top: 2,
list: [ undefined, 'b', <2 empty items> ],
| |
bot top
next: null
}
>
> cir.shift()
'b'
>
> cir
FixedCircularBuffer {
bottom: 2,
top: 2,
list: [ undefined, undefined, <2 empty items> ],
next: null
}
>
> cir.isEmpty()
true
>
*/
/*
var cir = new FixedCircularBuffer(4)
> cir
FixedCircularBuffer {
bottom: 0,
top: 3,
list: [ 'a', 'b', 'c', <1 empty item> ],
|
4 -1 =3 means full
next: null
}
> cir.isFull() ----------> extra-slot
true
>
*/
var {FixedQueue} = require("nv-data-fixed-queue")
var queue = new FixedQueue(4)
/*
> queue
FixedQueue {
tail: FixedCircularBuffer {
bottom: 0,
top: 0,
list: [ <4 empty items> ],
next: null
},
head: FixedCircularBuffer {
bottom: 0,
top: 0,
list: [ <4 empty items> ],
next: null
}
}
> queue.push('a')
undefined
> queue.push('b')
undefined
> queue.push('c')
undefined
> queue
FixedQueue {
tail: FixedCircularBuffer {
bottom: 0,
top: 3,
list: [ 'a', 'b', 'c', <1 empty item> ],
next: null
},
head: FixedCircularBuffer {
bottom: 0,
top: 3,
list: [ 'a', 'b', 'c', <1 empty item> ],
next: null
}
}
> queue.push('d')
undefined
> queue
FixedQueue {
tail: FixedCircularBuffer {
bottom: 0,
top: 3,
list: [ 'a', 'b', 'c', <1 empty item> ],
next: FixedCircularBuffer {
bottom: 0,
top: 1,
list: [Array],
next: null
}
},
head: FixedCircularBuffer {
bottom: 0,
top: 1,
list: [ 'd', <3 empty items> ],
next: null
}
}
> queue.push('e')
undefined
> queue
FixedQueue {
tail: FixedCircularBuffer {
bottom: 0,
top: 3,
list: [ 'a', 'b', 'c', <1 empty item> ],
next: FixedCircularBuffer {
bottom: 0,
top: 2,
list: [Array],
next: null
}
},
head: FixedCircularBuffer {
bottom: 0,
top: 2,
list: [ 'd', 'e', <2 empty items> ],
next: null
}
}
> queue.shift()
'a'
> queue.shift()
'b'
> queue
FixedQueue {
tail: FixedCircularBuffer {
bottom: 2,
top: 3,
list: [ undefined, undefined, 'c', <1 empty item> ],
next: FixedCircularBuffer {
bottom: 0,
top: 2,
list: [Array],
next: null
}
},
head: FixedCircularBuffer {
bottom: 0,
top: 2,
list: [ 'd', 'e', <2 empty items> ],
next: null
}
}
> queue.shift()
'c'
> queue
FixedQueue {
tail: FixedCircularBuffer {
bottom: 0,
top: 2,
list: [ 'd', 'e', <2 empty items> ],
next: null
},
head: FixedCircularBuffer {
bottom: 0,
top: 2,
list: [ 'd', 'e', <2 empty items> ],
next: null
}
}
> queue.shift()
'd'
> queue.shift()
'e'
> queue
FixedQueue {
tail: FixedCircularBuffer {
bottom: 2,
top: 2,
list: [ undefined, undefined, <2 empty items> ],
next: null
},
head: FixedCircularBuffer {
bottom: 2,
top: 2,
list: [ undefined, undefined, <2 empty items> ],
next: null
}
}
>
*/
API
- FixedCircularBuffer(kSize =2048)
- FixedQueue(kSize =2048)
LICENSE
- ISC