3.3.0 • Published 1 year ago

data-structures-again v3.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Data Structures Again

Light weight javascript data structures library

  • Binary Search Tree
  • Stack
  • Queue
  • Heap
  • Graph
  • Disjoint Set
  • HashSet
  • Red Black Balanced Search Tree
  • 2D Tree

Installation and Usage

npm install data-structures-again

Binary Search Tree:

const { BST } = require('data-structures-again')

const bst = new BST()
bst.insert(2)
bst.insert(1)
const node = bst.search(1) // { data: 1, left: null, right: null }
bst.delete(1)

Stack

const { Stack } = require('data-structures-again')

const stack = new Stack()
stack.push(1)
stack.push(2)
const data = stack.pop() // 2
const top = stack.peek() // 1

Queue

const { Queue } = require('data-structures-again')

const queue = new Queue()
queue.enqueue(1)
queue.enqueue(2)
const data = queue.dequeue() // 1
const top = queue.peek() // 2

Heap

const { Heap } = require('data-structures-again')

const minHeap = new Heap()
minHeap.push(5)
minHeap.push(2)
minHeap.peek() // 2

const maxHeap = new Heap((a, b) => b - a)
maxHeap.push(4)
maxHeap.push(10)
maxHeap.peek() // 10

Graph

const { Graph } = require('data-structures-again')

const graph = new Graph()

/*
    a---b
    |  /    
    | /
    c
*/

graph.addVertex('a')
graph.addVertex('b')
graph.addVertex('c')

graph.addEdge('a', 'c') // add weight using graph.addEdge('a', 'c', 10)
graph.addEdge('c', 'b')
graph.addEdge('a', 'b')

const output = []
graph.dfs('a', vertex => output.push(vertex.name)) // ['a', 'c', 'b']

Disjoint Set(Union-find)

const { DisjointSet } = require('data-structures-again')

const ds = new DisjointSet()
ds.union('a', 'b')
ds.union('b', 'c')
ds.union('d', 'c')

ds.find('d') // 'a'
ds.isConnected('a', 'd') // true

HashSet

const { HashSet } = require("data-structures-again");

const set = new HashSet()
set.add(1)
set.add(2)

set.has(1) // true
set.has(2) // true
set.has(3)) // false

Red Black Balanced Search Tree:

const { RedBlackBST } = require('./index')

const tree = new RedBlackBST()
tree.set(1, 'a')
tree.set(2, 'b')

tree.get(1) // 'a'
tree.get(2) // 'b'

2d Tree

const { TwoDTree } = require('./index')

const tree = new TwoDTree()
tree.insert(4, 1)
tree.insert(2.5, 1.5)
tree.insert(2.7, 1.7)
tree.insert(4, 3)

             // x1, x2, y1, y2
tree.rangeSearch(2, 3, 1, 2))
/*
[
    [2.5, 1.5],
    [2.7, 1.7],
    [2.6, 1.6]
]
*/

License

MIT.

3.2.0

1 year ago

3.0.0

1 year ago

3.3.0

1 year ago

3.1.0

1 year ago

2.5.0

2 years ago

2.1.9

3 years ago

2.1.10

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.5

3 years ago

2.1.4

3 years ago

2.2.0

3 years ago

2.3.0

3 years ago

2.1.3

3 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

5 years ago

1.29.1

5 years ago

1.29.0

5 years ago

1.28.0

5 years ago

1.27.1

5 years ago

1.27.0

5 years ago

1.26.0

5 years ago

1.25.0

5 years ago

1.24.2

5 years ago

1.24.1

5 years ago

1.24.0

5 years ago

1.23.0

5 years ago

1.22.0

5 years ago

1.21.1

5 years ago

1.20.1

5 years ago

1.20.0

5 years ago

1.19.2

5 years ago

1.19.3

5 years ago

1.19.1

5 years ago

1.19.0

5 years ago

1.18.8

5 years ago

1.18.7

5 years ago

1.18.6

5 years ago

1.18.5

5 years ago

1.18.4

5 years ago

1.18.3

5 years ago

1.18.2

5 years ago

1.18.1

5 years ago

1.18.0

5 years ago

1.17.6

5 years ago

1.17.5

5 years ago

1.17.4

5 years ago

1.17.3

5 years ago

1.17.2

5 years ago

1.17.1

5 years ago

1.17.0

5 years ago

1.15.2

5 years ago

1.15.1

5 years ago

1.14.0

5 years ago

1.13.0

5 years ago

1.12.2

5 years ago

1.12.1

5 years ago

1.12.0

5 years ago

1.11.1

5 years ago

1.11.0

5 years ago

1.10.0

5 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago