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

linkedlist-js

v1.3.0

Published

A Doubly Linked List Implementation in Javascript

Downloads

300

Readme

#LinkedList.js A simple doubly linked list implementation in Javascript.

Installation

npm install linkedlist-js

Usage

require the module...

var List = require('linkedlist-js').List;

instantiate a List object...

var list = new List();

// PUSH!
list.push('HUEHUE');

Traversing the List

with each(callback)

list.each(function (index, node) {
    console.log(index + ': ' + node.value());
});

like a badass

var node = list.head();

while (node != null) {
    console.log(node.value());
    node = node.next();
}

List API

Adding Nodes

push(value)

Creates a node with the value specified, adds it to the end of the list and returns the Node object.

var a = list.push('A');
a.value(); //'A'

unshift(value)

Creates a node with the value specified, adds it to the beginning of the list and returns the Node object.

var b = list.unshift('B');
b.value(); //'B'

Accessing Nodes

pop

Returns the tail Node and removes it from the list.

var list = new List();
list.push('A');
list.push('B');

list.pop().value(); //'B'

shift

Returns the head Node and removes it from the list.

var list = new List();
list.push('A');
list.push('B');

list.shift().value(); //'A'

get(index)

Returns the Node at the specified index. (Linear Lookup, not very performant)

var list = new List();
list.push('A');
list.push('B');
list.push('C');

list.get(1).value(); //'B'

Peeking

head()

Returns the head Node or null in list is empty

var list = new List();
var node_a = list.push('A');
var node_b = list.push('B');

list.head() === node_a; // true

tail()

Returns the tail Node or null in list is empty

var list = new List();
var node_a = list.push('A');
var node_b = list.push('B');

list.tail() === node_b; // true

Searching

find(value)

Find the node with the specified value and returns it. (Linear search, not very performant)

var list = new List();
list.push('A');
var node_b = list.push('B');

list.find('B') === node_b; // true

Misc

set(index, value)

Sets the value of the Node at the specifiec index.

var list = new List();
list.push('A');

list.set(0, 'B');
list.head().value(); // 'B'

count()

Returns the number of Nodes in the list.

var list = new List();
list.push('A');
list.push('B');

list.count(); // 2

isEmpty()

Returns true if list has no Nodes and false if otherwise.

var list = new List();
list.isEmpty(); // true

list.push('A');
list.isEmpty(); // false

truncateTo(length)

Truncates the list to the specified size.

var list = new List();
list.push('A');
list.push('B');

list.truncateTo(1);
list.count(); // 1

empty()

Same as calling truncateTo(0). Empties the list.

var list = new List();
list.push('A');
list.push('B');

list.empty();

list.count();   // 0
list.isEmpty(); // true

asArray()

Returns the list as an Array.

var list = new List();
list.push('A');
list.push('B');

list.asArray(); // ['A', 'B']

Node API

Getters

value()

Returns the value of the Node

previous()

Returns the previous Node in the list of null if the node is the forst Node.

next()

Returns the next Node in the list of null if the node is the last Node.

Setters

set(value)

Sets the value of the node

var node = new Node();
node.set('A');

node.value(); // 'A'

setPrevious(Node node)

Sets the previous pointer of the Node

var node_a = new Node();
var node_b = new Node();
node_b.setPrevious(node_a);

node_b.previous() === node_a; // true

setNext(Node node)

Sets the next pointer of the Node

var node_a = new Node();
var node_b = new Node();
node_a.setNext(node_b);

node_a.next() === node_b; // true

Misc

isHead()

Retunrs true if the node is the first node in the list.

var list = new List();
list.push('A');
list.push('B');

list.head().isHead(); // true

isTail()

Retunrs true if the node is the last node in the list.

var list = new List();
list.push('A');
list.push('B');

list.tail().isTail(); // true

Running Tests

npm test

if you have mocha installed, you may also run

mocha tests