JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q41383F
  • License BSD-2-Clause

A double linked list data structure for storing data

Package Exports

  • double-linkedlist

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

Readme

DOUBLE LINKED LIST

Getting Started

This is a simple double linked list. It has some tests but still use discretion.

You will have to create a new object to use it so for browsers...

var linkedList =  new DoubleLinkedList()

and for node...

var linkedList =  new require('double-linkedlist')();

Classes

DoubleLinkedList
## Typedefs
Comparitorboolean
Callbackboolean
## DoubleLinkedList **Kind**: global class **Author:** Michael Montaque

new DoubleLinkedList()

Double Linked List

doubleLinkedList.onChange(func)

Will trigger all the functions given to it when objects are added, removed or moved.

Kind: instance method of DoubleLinkedList

Param Type Description
func function function to call when a change occurs

doubleLinkedList.canUndo() ⇒ boolean

determines if there are any more undo left

Kind: instance method of DoubleLinkedList

doubleLinkedList.undo()

will undo the last modifying command

Kind: instance method of DoubleLinkedList

doubleLinkedList.clearUndo()

removes all the undo that the user can perform

Kind: instance method of DoubleLinkedList

doubleLinkedList.isEmpty() ⇒ boolean

is this data list empty?

Kind: instance method of DoubleLinkedList

doubleLinkedList.getSize() ⇒ Number

Returns the size of this list

Kind: instance method of DoubleLinkedList

doubleLinkedList.insertAtStart(data)

Inserts data at the end of the list

Kind: instance method of DoubleLinkedList
Summary: This method is may be faster than the browser's native array in placing an object at the beginning of the array

Param Type Description
data Object | Array Data to store into the array

doubleLinkedList.insertAtEnd(data)

Inserts data at the end of the list

Kind: instance method of DoubleLinkedList

Param Type Description
data Object | Array Data to store into the array

doubleLinkedList.insertAtPosition(data)

Inserts data at the end of the list

Kind: instance method of DoubleLinkedList

Param Type Description
data Object | Array Data to store into the array

doubleLinkedList.deleteAtPosition(position)

removes a node at the specified position

Kind: instance method of DoubleLinkedList

Param Type Description
position Number index of the node you want to remove

doubleLinkedList.deleteAll()

removes all the nodes

Kind: instance method of DoubleLinkedList

doubleLinkedList.removeNode(comparitor, isReversed)

removes a node at the specified position

Kind: instance method of DoubleLinkedList

Param Type Description
comparitor Comparitor function that cycles through each element returning the node and index. The user must return true or false to indicate whether or not the node should be removed.
isReversed Boolean to cycle through the list in reverse

Example

list.removeNode(function(node, idx){
     return node.id === 4
},true)

doubleLinkedList.getTail() ⇒ Object

Kind: instance method of DoubleLinkedList
Returns: Object - the node at the end of the list

doubleLinkedList.getHead() ⇒ Object

Kind: instance method of DoubleLinkedList
Returns: Object - the node at the start of the list

doubleLinkedList.move(oldIdx, newIdx)

moves the object

Kind: instance method of DoubleLinkedList
Todo

  • optimize (Method is brute force)
Param Type Description
oldIdx Number the index of the object you want to move
newIdx Number the index you want to move the old object to

doubleLinkedList.cycle(callback, isReversed)

cycles through each node and returns it along with the index to the callback To break free from the cycle the user can return false.

Kind: instance method of DoubleLinkedList

Param Type Description
callback Callback function that cycles through each element returning the node and index.
isReversed Boolean to cycle through the list in reverse

Example

list.cycle(function(node, idx){
     // Do something with the node
})

doubleLinkedList.toArray() ⇒ Array

returns an array of the data

Kind: instance method of DoubleLinkedList
Returns: Array - the internal data as an array

doubleLinkedList.findAll(comparitor)

removes a node at the specified position

Kind: instance method of DoubleLinkedList

Param Type Description
comparitor Comparitor | Object function that cycles through each element returning the node and index. The user must return true or false to indicate whether or not the node should be removed. Or it can be an object and the method will find any node that matches the attribute's data

Example

var array = list.findAll(function(node, idx){
     return node.id === 4
})

var list = list.findAll({id:4})

Comparitor ⇒ boolean

Kind: global typedef
Returns: boolean - the user should return true any time a condition is met while comparing the node

Param Type Description
node Object object in the list
idx Number index of the object in the list

Callback ⇒ boolean

Kind: global typedef
Returns: boolean - Optionally the user can return false to break free from the cycle early

Param Type Description
node Object object in the list
idx Number index of the object in the list

~Node

todo seal the default methods but allow object to be extensible

Kind: inner class

new Node(data, nextNode, previousNode)

class that represents the nodes that make up the list. Each of the node are referenced to at most two other nodes - a previous and a next.

Param Description
data any object to store
nextNode a node to reference as next
previousNode a node to reference as previous

node.setData(data)

sets the internal data object

Kind: instance method of Node

Param Type Description
data Object the information you want to store the node

node.getDataForKey(key)

getter for the internal data stored in the node

Kind: instance method of Node

Param Type Description
key String the attribute property name to access the data

node.appendData(data, key)

allows you to set data in the internal object.

Kind: instance method of Node

Param Type Description
data Object the information you want to store the node
key String the property you want to store the data at

node.getProtectedData() ⇒

Deprecated

Kind: instance method of Node
Returns: Object

node.getData() ⇒

Returns the data that was passed into the object (or added) by the user

Kind: instance method of Node
Returns: Object

node.hasNext() ⇒

true if there is another node linked after the node that is caller of this method

Kind: instance method of Node
Returns: Boolean

node.hasPrev() ⇒

true if there is another node linked before the node that is caller of this method

Kind: instance method of Node
Returns: Boolean

node.setNext(obj)

takes a node object and sets it as the next node in the linked list

Kind: instance method of Node

Param Type Description
obj Node the node object you want to set as next

node.setPrevious(obj)

takes a node object and sets it as the previous node in the linked list

Kind: instance method of Node

Param Type Description
obj Node the node object you want to set as previous

node.getNext() ⇒

returns the node that is after the node that called this method

Kind: instance method of Node
Returns: Node

node.getPrevious() ⇒

returns the node that is before the node that called this method

Kind: instance method of Node
Returns: Node

Change Log

Version 0.0.6

Bug Fixes:

  • Fixed cycle to require true to be explicitly returned to make the cycle continue.
  • Fixed the Move method to properly rearrange the the nodes

Version 0.0.7

Bug Fixes:

  • Fixed issue where adding attributes to the Node object via the dot notation did not propagate properly by restricting alterations to the inner node class attributes through only 4 methods: setData, getDataForKey, appendData & getProtectedData;

Version 0.2.0

Bug Fix/Added Feature:

  • Able to use dot notation to manipulate data on the node objects
  • Node base methods are immutable and unenumberable