npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

data-structures-again

v3.3.0

Published

A Javascript library of simple data structures

Downloads

88

Readme

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.