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

node-linkedlist

v0.1.4

Published

Double linked list features

Downloads

5

Readme

An implementation of the concept of double linked lists.

Quick example to get an instance of the linked list:

  var LinkedList = require('node-linkedlist')
    , User = require('../Object/User')
    , list = LinkedList.Create(User);
     
    ... 
  var user = User.Create();
  list.add(user, function(err, listObj) {
    ... 
    ... 
  });

The number of nodes linked to each other in a row.

Example

var list = require("node-linkedlist").Create()
...
  console.log(list.size);

You are not fixed to use ''LinkedList'' as it is with the internal standard node. You can use it to chain your own business objects too. The only thing you have to do is to extend the standard node object and publish the constructor of you class to the ''LinkedList'' instance. To publish your own node class without inherit from the standard node you only have to implement the methods that are described at the bottom of the documentation under List node Arguments

  • dataType (constructor) - The constructor of the class extending the standard node object.
  • return (LinkedList) - The list itself is returned.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create()
  , User = require('<path>/User');

  list.setDataType(User);

Alternatively you can publish the constructor directly on create the ''LinkedList'' instance.

var LinkedList = require("node-linkedlist")
  , User = require('<path>/User')
  , list = LinkedList.Create(User);

  ...
  ...

It is important to know that if you publish a constructor to the ''LinkedList'' instance after adding nodes all of them are lost because publishing requires to set a new first node of the published constructor. It is planned to realize a mixed-mode of nodes which have implemented a standard interface.

Add a new node to the end of the list. Arguments

  • data (string) - The data to add to the list. It can be a node object too.
  • callback (function) - The callback function with parameter err and listObj.
  • return (listObj) - The LinkedList instance itself.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create()
  , node = list.node;

  ...
  list.add('FirstName', function(err, listObj) {
    if (err) console.log(err);
    else {
      console.log(listObj.size);
    }
  });

Search a node by one of its properties. If the list contains extended standard nodes it is required to implement a getter method like ''getFirstName'' or ''getFirstname''. Arguments

  • property (string) - The nodes property to search in the value.
  • value (*) - The value to search in the given property.
  • return (node) - The node you searched or null if it can't be found.

Example

var LinkedList = require("node-linkedlist")
  , User = require('<path>/User')
  , list = LinkedList.Create(User);

  ...
  list.searchBy('FirstName', "Warden");

Get a node by a given position. Arguments

  • position (number) - The position of the node that is wanted. If the position less equal '0' or higher than the list size the first or last node is returned.
  • raw (boolean) - A flag to get the node itself instead of the value only. Default is false to get only the value.
  • return (Node) - The node at the position or first/last node if the position is less/equal 0 or higher than list size.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();

  ...
  var node = list.get(54, true);

Delete a node from given position. Arguments

  • position (number) - The position of the node which has to be removed.
  • return (LinkedList) - The list itself is returned.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();

  ...
  list.delete(54, true);

Get the first node of the list. Arguments

  • return (node) - The first node in the list.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();

  ...
  var firstNode = list.first();

Get the last node of the list. Arguments

  • return (node) - The last node in the list.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();

  ...
  var firstNode = list.last();

Check if a node is an instance of the internal standard node. Arguments

  • node (object) - The node that will be compared with the constructor of the standard node.
  • return (boolean) - True if the given node is a standard node. Otherwise false is returned.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();

  ...
  var node = ...;
  if (list.isStdNode(node)) {
    ...
    ...
  }

Removes all nodes from the list. Arguments

  • return (LinkedList) - The list itself is returned.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();

  ...
  list.clean();

Converts the list into an array. Arguments

  • return (Array) - All nodes in an array.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();

  ...
  var nodes = list.toArray();
  ...

Get the next node in the list.

Check the existence of a next node.

Get the previous node in the list.

Check the existence of a previous node.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create()
 ,  node = null;
  // Traversing forwards 
  for(node = list.first(); list.hasNext(); node = list.next()) {
   ... 
   ... 
  }
  
  // or backwards
  for(node = list.last(); list.hasPrevious(); node.previous()) {
   ... 
   ... 
  }

The list node is the standard node object used by the linked list internally if no other node constructor is offered. You can get it via the property 'node' of the linked list object. Arguments

  • No arguments

Example

var list = require("node-linkedlist").Create()
  , node = list.node;

var newNode = node.Create();

Set another node object as next node to the current one. Arguments

  • nextNode (object) - A node which has to be referenced as next node.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();
... 
var last = list.last()
  , node = list.node.Create();

node.setValue({
  field1: true, 
  field2: 123, 
  field3: {success: true}, 
  field4: "Everything's fine."
});
  
last.setNext(node);
...

Get the next node that is referenced to the current node. Arguments

  • No argument

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();
... 
var node = list.first()
...
node = node.next();
...

Check the existence of a next nodes reference. Arguments

  • No argument

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();
... 
var node = list.first()
...
if (node.hasNext())
  node = node.next();
...

Set another node object as previous node to the current one. Arguments

  • previousNode (node) - The node which has to be referenced before current node.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create()
  , node = list.node;
...
var last = node.Create()
  , newNode = node.Create();

last.setValue({
  field1: true, 
  field2: 123, 
  field3: {success: true}, 
  field4: "Everything's fine."
});

newNode.setValue("Only a small text string...");
last.setPrevious(newNode);
...

Get the previous node that is referenced to the current node. Arguments

  • No argument

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();
... 
var node = list.last()
...
node = node.previous();
...

Check the existence of a previous nodes reference. Arguments

  • No argument

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create();
... 
var node = list.last()
...
if (node.hasPrevious())
  node = node.previous();
...

Set the value that has to be added to the list. This method is used internally so it is fully transparent via ''list.add(...)'' if you use the standard node. Arguments

  • value (mixed) - The value that has to be put to a list via a node.

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create()
  , Node = list.node;
... 
var node = list.last()
...
var newNode = Node.Create();
newNode.setValue({message: 'Created new node.'});
node.setNext(newNode);
...

Get the value that is stored in a node. This method is used internally so it is fully transparent via ''list.get(position)'' if you use the standard node. Arguments

  • No argument

Example

var LinkedList = require("node-linkedlist")
  , list = LinkedList.Create()
  , Node = list.node;
... 
var node = list.last()
console.log(node.getValue());
...