1.0.1 • Published 5 years ago

data-structure-user-add-functional v1.0.1

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

Javascript Data Structure

Javascript Data Structure Library
The interface of this library has been influenced by the c++ STL.
This is distributed to npm as 'data-structure-user-add-functional'
This Library is used for https://hongjisung.github.io/JS_DataStructure_Visualization/

Make Functional Method

User can make functional method to use it as functional by using copy method.
Just add 3 line function to prototype for make functional method.
Add Functional Method to Containers

Document Homeage Go Document

Homepage Address Go HomePage

Visualization

Visualization is developed in other repository
Visualization Repository

Usage

Containers

Container Usage Examples

Algorithms

Algorithm Usage Examples

Graph

Graph Usage Examples

Functional Usage

Containers

Add Functional Method to Containers

Install

Install Library

npm install --save data-structure-user-add-functional

Install dependencies

npm install

Run Test

npm run test

Make jsdoc homepage html

mkdir doc
npm run doc // open the ./doc/index.html

Containers

  • List

    Doubly linked list.

  • Stack

    Based on Array.

  • Queue

    Based on circular array.

  • Priority queue

    Based on Array.
    Sorted by Compare function basically descending order.

  • Deque

    Deque extends Queue.
    Based on circular array.
    pop and push method are assumed as private.

  • SetTree

    Red black tree with unique value.
    Identify key with data.
    Sorted by Compare function basically descending order.

  • MultiSetTree

    Red black tree.
    Identify key with data.
    Sorted by Compare function basically descending order.

  • MapTree

    Red black tree with unique value.
    key and data mapping structure.
    Sorted by Compare function basically descending order.

  • MultiMapTree

    Red black tree.
    key and data mapping structure.
    Sorted by Compare function basically descending order.

Algorithms

  • MergeSort

    Sort iterable object in O(nlogn) times. Sorting time almost similar in most cases.

  • QuickSort

    Sort iterable object in average O(nlogn) times. Sorting time is not stable.

  • removeCondition

    remove elements which data or key satisfies the condition in iterable container.

  • unique

    reduce duplicate elements to one in iterable container.

  • findNodes

    This can find several keys at one time.
    It return an array of the matched nodes.

  • map

    This can apply function to data of elements in container.
    It cannot use for set, because set is key and data are equal and is sorted by key.

Graph

  • DirectedGraph

    directed graph based on adjacent list concept
  • UndirectedGraph

    undirected graph based on adjacent list concept

Reference

Function Tables

Container Member Function Table

MethodListStackQueueDequePriorityQueueSetTreeMultiSetTreeMapTreeMultiMapTree
(constructor)List()Stack()Queue()Deque()PriorityQueue()SetTree()MultiSetTree()MapTree()MultiMapTree()
comparecompare()compare()compare()compare()
Iterators
Symbol.iterator...List...SetTree...MultiSetTree...MapTree...MultiMapTree
beginbegin()begin()begin()begin()begin()
rbeginrbegin()rbegin()rbegin()rbegin()rbegin()
endend()end()end()end()end()
rendrend()rend()rend()rend()rend()
Element Access
frontfront()front()front()top()
backback()top()back()back()
Capacity
emptyempty()empty()empty()empty()empty()empty()empty()empty()empty()
sizesize()size()size()size()size()size()size()size()size()
Modifier
clearclear()clear()clear()clear()clear()clear()clear()clear()clear()
insertinsert()insert()insert()insert()insert()
assignassign()assign()
insertOrAssigninsertOrAssign()insertOrAssign()
eraseerase()erase()erase()erase()erase()
pushFrontpushFront()pushFront()
pushBackpushBack()push()push()pushBack()push()
popFrontpopFront()pop()popFront()pop()
popBackpopBack()pop()popBack()
mergemerge()
List operations
splicesplice()
reversereverse()
sortsort()
Lookup
countcount()count()count()count()
findfind()find()find()find()
containscontains()contains()contains()contains()
lowerBoundlowerBound()lowerBound()lowerBound()lowerBound()
upperBoundupperBound()upperBound()upperBound()upperBound()
equalRangeequalRange()equalRange()equalRange()equalRange()
keyCompcompareFunction()keyComp()keyComp()keyComp()keyComp()
toStringtoString()toString()toString()toString()toString()toString()toString()toString()toString()
copycopy()copy()copy()copy()copy()copy()copy()copy()copy()

Node Member Function Table

MethodNode(list)TreeNode
getDatagetData()
setDatasetData(data)
getKeygetKey()
getValuegetValue()
getPrevgetPrev()getPrev()
getNextgetNext()getNext()

Algorithm Container Table

FunctionListSetTreeMultiSetTreeMapTreeMultiMapTree
mergeSortmergeSort(List)
quickSortquickSort(List)
removeConditionremoveCondition(function)removeCondition(function)removeCondition(function)removeCondition(function)removeCondition(function)
uniqueunique(List)unique(MultiSetTree)unique(MultiMapTree)
findNodesfindNodes(List, key array)findNodes(SetTree, key array)findNodes(MultiSetTree, key array)findNodes(MapTree, key array)findNodes(MultiMapTree, key array)
mapmap(List, function)map(MapTree, function)map(MultiMapTree, function)

Graph Table

MethodDirectedGraphUndirectedGraph
nodeSizenodeSize()nodeSize()
edgeSizeedgeSize()edgeSize()
getNodesgetNodes()getNodes()
getEdgesgetEdges()getEdges()
getWeightgetWeight()getWeight()
setIterTypesetIterType()setIterType()
setIterStartsetIterStart()setIterStart()
setWeightAddFuncsetWeightAddFunc()setWeightAddFunc()
setWeightCompFuncsetWeightCompFunc()setWeightCompFunc()
setWeightsetWeight()setWeight()
mapWeightmapWeight()mapWeight()
eraseNodeeraseNode()eraseNode()
eraseEdgeeraseEdge()eraseEdge()
insertNodeinsertNode()insertNode()
insertEdgeinsertEdge()insertEdge()
isCycleisCycle()isCycle()
isTreeisTree()isTree()
isNegativeWeightisNegativeWeight()isNegativeWeight()
isAllWeightEqualisAllWeightEqual()isAllWeightEqual()
reversereverse()
disjointSetdisjointSet()
copycopy()copy()

Data Structure Operation Time Complexity

ContainerSearchInsertionDeletionRemarks
Listn11
Stackn11
Queuen11
Priority QueueN/Alog(n)log(n)Access O(1) for the Top
Dequen11
SetTreelog(n)log(n)log(n)
MultiSetTreelog(n)log(n)log(n)Deletion is different according the number of same key
MapTreelog(n)log(n)log(n)
MultiMapTreelog(n)log(n)log(n)Deletion is different according the number of same key

Algorithm operation time complexity

OperationBestAverageWorstSpace
Merge Sortnlog(n)nlog(n)nlog(n)n
Quick Sortnlog(n)nlog(n)n2log(n)

Jsdoc

Template : docdash
Make document command : npm run doc

Eslint

Style : airbnb

Test

Test FrameWork : Mocha
Test command : npm run test