npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

linked-queue

v1.0.3

Published

Queues using linked list, faster than array.shift(), support enqueue,dequeue,enqueue all, dequeue all, clear, forEach, first, last

Downloads

1,549

Readme

lqueue

Create queue using linked list. Support forEach, enqueue,dequeue,clear,enqueue All, dequeueAll A Simple Queue using Linked Link Datastructure

When I was using javascript Array and calling array.shift() method to get first element and It was terrible if array contains more than 100,000 elements.

var start = new Date().getTime()
for(var i = 0; i< 100000; i++){
 array.shift();
}
var duration = new Date().getTime() - start;// duration is so large, greater than 3 minutes

I used Linked List to improve performance, and apply it for 1000,000 elements.

var start = new Date().getTime()
for(var i = 0; i< 1000000; i++){
 queue.dequeue();
}
var duration = new Date().getTime() - start;// duration  = 8 for 1000000 elements

Example: Queues using linked list. Visit here to test: https://tonicdev.com/5788a641565456130014d2c1/5788a641565456130014d2c2

var LQueue = require('linked-queue')
var queue = new LQueue()
queue.length === 0 //=> true
queue.enqueue(10)
queue.length  //=> 1
queue.first() ; // => 10
queue.last() ; // => 10
queue.enqueueAll([11,12]); // queues elements: 10,11,12
queue.fist(); //=> 10
queue.last();// => 12
queue.length;// => 3

queue.dequeue()// return 10, queus elements: 11,12
queue.forEach(function(data){
    console.log(data);
});
//=> print: 11 12
queue.dequeueAll(function(data){
    console.log(data);
});
//=> print: 11 12
queue.length //return 0
queue.isEmpty(); //return true;
queue.enqueueAll([1,2]);
queue.length;//return 2
queue.clear();
queue.length// return 0

API

queue = new LQueue()

queue.enqueue(value)

Push a value on the end.

queue.enqueueAll(array)

Push all values of array on the end of queue.

value = queue.dequeue()

Remove a value off the beginning.

queue.dequeueAll(callbackfn)

Remove all values off the beginning. Each dequeued data will be call by callbackFn(data)

queue.length

return size of queue.

value = deque.forEach(callbackfn)

Get all values of queues without removing. Each data will be call by callbackFn(data)

value = queue.last()

Examine the value of the end without removing it.

value = queue.first()

Examine the value of the beginning without removing it.

queue.clear()

Remove all entries.

About the Code

I was convinced by a blog posting