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

loki-ds

v1.0.6

Published

This repository provides a collection of common data structure implementations in TypeScript.

Downloads

9

Readme

Data Structures

This repository provides a collection of common data structure implementations in TypeScript.

Installation

You can install the loki-ds package from npm using the following command:

npm install loki-ds

Example

Linked list


const linkedList = new LinkedList<number>();
linkedList.addToHead(3);
linkedList.addToHead(2);
linkedList.addToHead(1);
linkedList.print();

Stack

const stack = new Stack<number>();
stack.push(1);
stack.push(2);
stack.push(3);
console.log(stack.peek());
console.log(stack.size());
stack.pop();
console.log(stack.peek());
console.log(stack.size());

Queue

const queue = new Queue<number>();
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
console.log(queue.peek());
console.log(queue.size());
queue.dequeue();
console.log(queue.peek());
console.log(queue.size());

Tree

const tree = new Tree<number>();
tree.setRoot(1);
const root = tree.getRoot();
if (root) {
  const child1 = new TreeNode(2);
  const child2 = new TreeNode(3);
  const child3 = new TreeNode(4);
  root.addChild(child1);
  root.addChild(child2);
  root.addChild(child3);
  console.log(root.data);
  console.log(root.children.length);
}

Graph

const graph = new Graph<string>();
graph.addEdge("A", "B");
graph.addEdge("A", "C");
graph.addEdge("B", "D");
graph.addEdge("C", "E");
console.log(graph.getNeighbors("A"));
console.log(graph.getNeighbors("B"));
console.log(graph.getNeighbors("C"));
console.log(graph.getNeighbors("D"));
console.log(graph.getNeighbors("E"));

Trie

const trie = new Trie();
trie.insert("apple");
trie.insert("banana");
trie.insert("orange");
console.log(trie.search("apple"));
console.log(trie.search("orange"));
console.log(trie.search("grape"));
console.log(trie.startsWith("app"));
console.log(trie.startsWith("ora"));
console.log(trie.startsWith("ban"));

Hash map

const hashmap = new HashMap<string, number>();
hashmap.put("apple", 1);
hashmap.put("banana", 2);
hashmap.put("orange", 3);
console.log(hashmap.get("apple"));
console.log(hashmap.get("banana"));
console.log(hashmap.get("orange"));
hashmap.remove("banana");
console.log(hashmap.contains("banana"));
console.log(hashmap.getSize());
console.log(hashmap.isEmpty());

Heap

const minHeap = new MinHeap();
minHeap.insert(5);
minHeap.insert(8);
minHeap.insert(3);
minHeap.insert(10);
minHeap.insert(2);
console.log(minHeap.getSize());
console.log(minHeap.peek());
console.log(minHeap.removeMin());
console.log(minHeap.removeMin());
minHeap.insert(1);
console.log(minHeap.peek());
minHeap.print();

Hash set

const hashSet = new HashSet<string>();
hashSet.add("apple");
hashSet.add("banana");
hashSet.add("orange");
console.log(hashSet.has("apple"));
console.log(hashSet.has("grape"));
console.log(hashSet.size());
hashSet.delete("banana");
console.log(hashSet.values());
console.log(hashSet.isEmpty());