Socket
Socket
Sign inDemoInstall

container-doublylist

Package Overview
Dependencies
0
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    container-doublylist

DoublyList implementation in JavaScript


Version published
Weekly downloads
109
decreased by-48.58%
Maintainers
2
Install size
8.42 kB
Created
Weekly downloads
 

Readme

Source

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 insert an element before the given node:

var myOtherObjectReference = myList.addBefore(myObjectReference, myOtherObject);

To insert an element after the given node:

var myOtherObjectReference = myList.addAfter(myObjectReference, myOtherObject);

To move an element to the beginning:

myList.moveToTheBeginning(myObjectReference);

To move an element to the end:

myList.moveToTheEnd(myObjectReference);

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();

Keywords

FAQs

Last updated on 17 Aug 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc