Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

container-doublylist

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

container-doublylist

DoublyList implementation in JavaScript

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
293
decreased by-7.57%
Maintainers
2
Weekly downloads
 
Created
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

Package last updated on 17 Aug 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc