Skip to content

gbourel/fifo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FIFO

Javascript FIFO queue implemented using a double linked-list

npm install fifo

build status

Usage is simple

var fifo = require('fifo')();

fifo.push('hello');
fifo.push('world');

console.log(fifo.first()); // prints hello
console.log(fifo.last());  // prints world

console.log(fifo.shift()); // prints hello
console.log(fifo.shift()); // prints world

var node = fifo.push('meh');

fifo.remove(node);     // remove 'meh' from the stack
fifo.unshift('hello'); // insert at the beginning

fifo.removeAll();		// Clear stack

if (!fifo.isEmpty()) {	// Check if stack is empty
	fifo.shift();
}

fifo uses a linked list behind the scene so push, shift, unshift, and remove all run in O(1)

Subscribe to "on push" messages

var fifo = require('fifo')();

fifo.subscribe({ 
    onPush: function(value){
        console.log('Pushed value', value);
    }
});

fifo.push('hello');
fifo.push('world');

License

MIT

About

FIFO queue in Javascript

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%