Socket
Socket
Sign inDemoInstall

dequeue

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dequeue - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

17

lib/dequeue.js

@@ -29,3 +29,3 @@

Dequeue.prototype.shift = function(){
if (this.head.next = this.head) return
if (this.head.next === this.head) return
var n = this.head.next.remove()

@@ -36,2 +36,17 @@ this.length -= 1

Dequeue.prototype.empty = function(){
if (this.length === 0 ) return
//no node points to head; not necessary for GC, but it makes me feel better.
this.head.next.prev = null
this.head.prev.next = null
//head only points to itself; as a fresh node would
this.head.next = this.head
this.head.prev = this.head
this.length = 0
return
}
function Node(d) {

@@ -38,0 +53,0 @@ this.data = d

2

package.json
{
"name" : "dequeue"
, "main" : "./lib/index.js"
, "version" : "1.0.2"
, "version" : "1.0.3"
, "description" : "A simple double ended queue datastructure"

@@ -6,0 +6,0 @@ , "keywords" : ["datastructure", "queue", "double ended queue", "fifo", "FIFO", "linked list"]

A Simple Double Ended Queue Datastructure
=========================================
I was using a javascript array as a FIFO. Somewhere between 100,000 and
Dequeue is implemented as a doubly linked circular list with a titular head
node. By "titular head node", I mean an empty node to designate the beginning
and end of the circularly linked list. I first saw this construction in the
linux kernel source and it seem simple and elegant. I added the `.length`
property to use it like I was using an Array.
I was using a javascript Array as a FIFO. Somewhere between 100,000 and
200,000 entries the program performance went to hell (dev host is a MBP

@@ -9,9 +15,6 @@ w/8GB RAM). 15 minutes later, I implemented a simple dequeue and my FIFO

It is a dropin replacement for javascript-arrays-as-fifo.
It is a drop-in replacement for javascript-arrays-as-fifo.
I was convinced by [a blog posting](http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding) [by Issac Z. Schlueter](http://blog.izs.me/) that I don't need
semicolons. So I don't use them.
## Example: Dequeue as a replacement for an Array as a FIFO
## So here is the API:
var Dequeue = require('dequeue')

@@ -36,1 +39,31 @@

fifo.length === 1 //=> true; only d3 is in the dequeue
## API
### `deque = new Dequeue()`
### `deque.push(value)`
Push a value on the end.
### `value = deque.pop()`
Remove a value off the end.
### `deque.unshift(value)`
Push a value on the beginning.
### `value = deque.shift()`
Remove a value off the beginning.
### `deque.empty()`
Remove all entries. This is NOT a test for an empty dequeue; use `deque.length`
for that.
## Future Development
Something this simple does not really need a roadmap. However, I am thinking
of adding APIs to facilitate walking the Linked List via an iterator. It will
be simple and fully backward compatible.
## About the Code
I was convinced by [a blog posting](http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding) [by Issac Z. Schlueter](http://blog.izs.me/) that I don't need
semicolons. So I don't use them.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc