JSPM

container-doublylist

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 185
  • Score
    100M100P100Q86930F
  • License MIT

DoublyList implementation in JavaScript

Package Exports

  • container-doublylist

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 (container-doublylist) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

container-doublylist

DoublyList implementation in JavaScript

To manage a list of elements. Best use case: elements are frequently removed from the list. Complexity in O(1) for addition and removal.

Note: Benchmarks seem to show that list iteration is as fast as array iteration on all major browsers.

To instantiate a new list:

var myList = new DoublyList();

To add an element:

var myObjectReference = myList.add(myObject); // add on front by default
// or
var myObjectReference = myList.addFront(myObject);
// or
var myObjectReference = myList.addBack(myObject);

To remove an element:

myList.removeByReference(myObjectReference); // O(1)
// or
myList.remove(myObject); // O(n)

To pop an element:

var myObject = myList.pop(); // pop from front by default
// or
var myObject = myList.popFront();
// or
var myObject = myList.popBack();

To iterate through the elements:

for (var node = myList.first; node !== null; node = node.next) {
    node.object += 1;
}

To apply a treatment on all the elements:

myList.forEach(function (object) {
    console.log(object);
});

To convert into an array:

var myArray = myList.toArray();