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

@ahmeds.gaafer/ts-data-structures

v1.1.5

Published

a light weight package for typescript Data structures

Downloads

5

Readme

TypeScript Data Structures

Data Structures package made by TypeScript.

Install

$ npm i @ahmeds.gaafer/ts-data-structures

Data Structure list:

  • [x] Singly Linked List
  • [x] Doubly Linked List
  • [x] Queue
  • [x] Stack
  • [x] Heap
  • [x] Graph

Usage

Singly Linked List:

import { SinglyLinkedList } from "@ahmeds.gaafer/ts-data-structures";

// The constructor can accept an array as an input and it will transform the array to the linked list
const arr = [1, 2, 3];
const list = new SinglyLinkedList<number>(arr);

list.push(1);

list.view();

// You can chain methods that does not return a value

list.popStart().pop().view(); // vaild

list.getHead().view(); // invalid

functions:

  • .insert(data, pos) => Insert data to certian position.
  • .pushStart(data) => Insert data at the head position.
  • .push(data) => Insert data at tail position.
  • .delete(pos) => Delete element at a certian position.
  • .pop() => Delete element from the end of the tail.
  • .popStart() => Delte element from the head.
  • .getHead() => Returns a copy of the head node.
  • .getTail() => Returns a copy of the tail node.
  • .view() => Prints a visual dispaly of the linked list.
  • .toArray() => Returns the linked list as an array

Doubly Linked List:

import { DoublyLinkedList } from "@ahmeds.gaafer/ts-data-structures";
// The constructor can accept an array as an input and it will transform the array to the linked list
const arr = [1, 2, 3];
const list = new DoublyLinkedList<number>(arr);

list.push(1);

list.view();

// You can chain methods that does not return a value

list.popStart().pop().view(); // vaild

list.getHead().view(); // invalid

functions:

  • .insert(data, pos) => Insert data to certian position.
  • .pushStart(data) => Insert data at the head position.
  • .push(data) => Insert data at tail position.
  • .delete(pos) => Delete element at a certian position.
  • .pop() => Delete element from the end of the tail.
  • .popStart() => Delte element from the head.
  • .getHead() => Returns a copy of the head node.
  • .getTail() => Returns a copy of the tail node.
  • .view() => Prints a visual dispaly of the linked list.
  • .toArray() => Returns the linked list as an array.

Queue:

import { Queue } from "@ahmeds.gaafer/ts-data-structures";

// The constructor can accept an array as an input and it will transform the array to the Queue
const arr = [1, 2, 3];
const queue = new Queue<number>(arr);

queue.enqueue(5);
queue.deqeue();

// You can chain methods that does not return a value
queue.enqueue(5).dequeue().view(); //vaild

queue.peak().view(); // invalid

functions:

  • .enqueue(data) => Add data to the end of the queue.
  • .dequeue() => Remove first element of the queue.
  • .peak() => Returns the first element in the queue.
  • .getSize() => Returns the size of the queue.
  • .view() => Prints a visual dispaly of the queue.

Stack:

import { Stack } from "@ahmeds.gaafer/ts-data-structures";

// The constructor can accept an array as an input and it will transform the array to the Heap

const arr = [1, 2, 3];

const stack = new Stack<number>(arr);

stack.push(1);

// You can chain methods that does not return a value
stack.push(1).push(2).pop(); // vaild
stack.peak().push(1); // invalid

functions:

  • .push(data) => Inserts data to top of stack.
  • .pop() => Removes the item on the top of the stack.
  • .peak() => Returns the item on the top of the stack.
  • .getSize() =>Returns the size of the stack;
  • .view() => Prints a visual display of the stack.

Heap:

import { Heap } from "@ahmeds.gaafer/ts-data-structures";

// The constructor can accept an array as an input and it will transform the array to the Heap

const arr = [1, 2, 3];
const maxHeapOptions = {
  cmp: (a, b) => a < b;
}
const minHeapOptions = {
  cmp: (a, b) => a > b;
}

// Heap type is set to number by default but you can change it

//min heap
const minHeap = new Heap(arr, minHeapOptions);

//max heap
const maxHeap = new Heap(arr, maxHeapOptions);

/// or
const maxHeap = new Heap<string>([], maxHeapOptions);

maxHeap.push(5);

// You can chain methods that does not return a value
minHeap.push(1).push(2); // vaild
minHeap.peak().push(1); // invalid

functions:

  • .push(data) => Insert a data to the heap.
  • .pop() => Removes the root of the heap and fixes the the heap.
  • .peak() => Returns the value of the root of the heap.
  • .getSize() => Returns the size of the heap;
  • .view() => Prints the array of the heap;

Graph:

import { Graph } from "@ahmeds.gaafer/ts-data-structures";

//The graph can has 2 arguments that are set to false by default.
//The first argument is "isUniDirectional" if you set it to true the graph will be a directed graph.
//The second argument is "isWeighted" if you set it to true the graph will be weighted.

const g = new Graph(); // un-directed un-weighted graph
//or
const g = new Graph(true, false); // directed un-weighted graph.
//or
const g = new Graph(false, true); // un-directed  weighted graph.
//or
const g = new Graph(true, true); // directed weighted graph

g.addVertex(1);
g.addVertex(2);

// You can chain methods that does not return a value

g.addVertex(1).addVertex(2); // valid

g.getNeighbors(1).addVertex(3); // invalid

g.removeVertex(5); // remove a non-existent vertex

// etc...

functions:

  • .addVertex(v) => Adds vertex to the graph.
  • .addEdge(u, v, w: conditional) => Add edge between vertex "u" and vertex "v" . weight of the edge "w" is valid if only the graph is set to be weighted.
  • .removeVertex(v) => Removes the vertex from the graph and removes all of the linked edges to it.
  • .removeEdge(u, v) => Removes edge between vertex "u" and "v".
  • .getVerticesNumbers() => Returns the number of vertices in the Graph.
  • .getNeighbors(v) => Returns a the list of neighbors of vertex v
  • .view() => Display a visual display of the graphs adjacency list.

Important Note:

Any usage of the functions not mentioned in the functions above might lead to un-expected behavior and may lead to the functions throwing an error.