JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q41340F
  • 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 Build Status

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

Table of Contents

DoubleLinkedList

Double Linked List

Meta

  • author: Michael Montaque

onChange

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

Parameters

  • func {function} function to call when a change occurs

canUndo

determines if there are any more undo left

Returns boolean

undo

will undo the last modifying command

clearUndo

removes all the undo that the user can perform

isEmpty

is this data list empty?

Returns boolean

getSize

Returns the size of this list

Returns Number

insertAtStart

Inserts data at the start of the list

Parameters

  • data {Object | Array} - Data to store into the array

insertAtEnd

Inserts data at the end of the list

Parameters

  • data {Object | Array} - Data to store into the array

insertAtPosition

Inserts data at a specified position the list

Parameters

  • data {Object | Array} - Data to store into the array

deleteAtPosition

removes a node at the specified position

Parameters

  • position {Number} index of the node you want to remove

deleteAll

removes all the nodes

removeNode

removes a node at the specified position

Parameters

  • 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

Examples

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

getTail

Returns Object the node at the end of the list

getHead

Returns Object the node at the start of the list

move

moves the object

Parameters

  • oldIdx Number the index of the object you want to move
  • newIdx Number the index you want to move the old object to

cycle

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.

Parameters

  • callback Callback function that cycles through each element returning the node and index.
  • isReversed {Boolean} to cycle through the list in reverse

Examples

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

Meta

  • deprecated: Will be removed by version 1.0.0. (Please use the psychic method instead)

psychic

cycles through each node and returns it along with the previous node, the next node and the index to the callback. To break free from the cycle the user can return false or let it run to the end

Parameters

  • callback Callback function that cycles through each element returning the node and index.
  • isReversed {Boolean} to cycle through the list in reverse

Examples

list.psychic(function(currentNode, previousNode, nextNode, idx){
     // Do something with the node
     // return true to keep going or false to stop
})

toArray

returns an array of the data

Returns Array the internal data as an array

findAll

removes a node at the specified position

Parameters

  • 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

Examples

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

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

recursiveFindByIndex

uses recursion(top down) to find the node by index

Parameters

  • node
  • indexPositionOfNode

Returns any

insertAtPosition

Inserts a new node (with data) at the specified position

Parameters

  • data
  • position

setData

sets the internal data object

Parameters

  • data Object the information you want to store the node

getDataForKey

getter for the internal data stored in the node

Parameters

  • key String the attribute property name to access the data

appendData

allows you to set data in the internal object.

Parameters

  • data Object the information you want to store the node
  • key String the property you want to store the data at

getProtectedData

Returns any Object

Meta

  • deprecated: Will be removed by version 1.0.0. (Please use the getData data method instead)

getData

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

Returns any Object

hasNext

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

Returns any Boolean

hasPrev

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

Returns any Boolean

setNext

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

Parameters

  • obj Node the node object you want to set as next

setPrevious

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

Parameters

  • obj Node the node object you want to set as previous

getNext

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

Returns any Node

getPrevious

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

Returns any Node

Comparitor

Type: Function

Parameters

  • node Object object in the list
  • idx Number index of the object in the list

Returns boolean the user should return true any time a condition is met while comparing the node

Callback

Type: Function

Parameters

  • node Object object in the list
  • idx Number index of the object in the list

Returns boolean Optionally the user can return false to break free from the cycle early

Psychic-Callback

Type: Function

Parameters

  • currentNode Object The current node object in the list
  • previousNode Object The previous node object in the list
  • nextNode Object The next node object in the list
  • idx Number index of the object in the list

Returns boolean Optionally the user can return false to break free from the cycle early