JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q27311F
  • License Apache-2.0

quicker doubly-linked list

Package Exports

  • qdlist

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (qdlist) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

qdlist

Build Status Coverage Status

Quicker doubly-linked list.

Items are kept on a circular linked list, with the list itself being the terminal node.

Api

qdlist( )

Construct a new empty list. Can be called either as a function or as a constructor with new qdlist().

const qdlist = require('qdlist');
const list = qdlist();

list.push(1);
list.push(2);
list.push(3);
list.moveToTail(list.head());
list.toArray();
// => [ 2, 3, 1 ]

unshift( value ), push( value )

Append a new value to the head / tail of the list, respectively. Returns the node that contains the value. The returned node has properties value containing the call argument and value2 with initial contents not specified.

unshift2( value, value2 ), push2( value, value2 )

Add a new pair of items to the head / tail of the list, respectively. Returns the node that contains the item with properties node.value set to value and node.value2 set to value2.

shift( ), pop( )

Remove and return the first / last value on the list. Returns undefined if the list is empty. If necessary, use isEmpty to distinguish the undefined value from an empty list.

isEmpty( )

Returns boolean true if the list is empty, else false.

Remove the node from the list.

head( ), tail( )

Return the first / last node on the list, or undefined if the list is empty.

Note that head / tail / push / unshift return nodes, but shift / pop return values.

moveToHead( node ), moveToTail( node )

Move the given node to the head / tail of the list. The node may be unlinked, or may still be on the list.

forEach( handler(node) )

Call the handler with each node on the list, in list order.

toArray( [limit] )

Return up to limit values from the list, in list order. The default limit is Infinity, return all values. Useful for testing or inspection.

l.push(1);
l.push(2);
l.toArray();        // => [1, 2]

Changelog

  • 0.9.0 - first release version
  • 0.0.1 - first working version

Todo

  • fromArray method to initialize / reset list contents