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

ds-algorithms

v1.0.4

Published

Data Sturctures package for javascript that adds new data structures and improves existing ones

Downloads

2

Readme

DS - Algorithms

An npm package that adds new data structures and improves existing ones.

Installation

npm i ds-algorithms --save

Usage

const  dataStructures  =  require("ds-algorithms");

let  SlinkedList  =  new  dataStructures.SinglyLinkedList();
let  DlinkedList  =  new  dataStructures.DoublyLinkedList();
let  stack  =  new  dataStructures.Stack();
let  queue  =  new  dataStructures.Queue();


SlinkedList.add(3);
SlinkedList.add(7);

DlinkedList.add(2);
DlinkedList.add(5);

stack.push(4);
stack.pop();

queue.enqueue(10);
queue.dequeue();

Options

Singly Linked List

Visual representation of singly linked list - Source: geeksforgeeks.org

In a singly linked list data is stored in individual objects named nodes. Each node has a value and link to the next node. The main advantage of using a linked list over an array is that we generally could add and delete data much faster and is stored at discontinuous locations in memory. A singly linked list is slightly limited in functionality than the doubly linked list but is generally faster than singly linked list.

Methods:

  • add(value) - adds a value to the end of the linked list

  • prepend(value) - adds a value to the start of the linked list

  • insertAt(index, value) - adds a value to the node at index + 1 position in the linked list i.e. if index is 0 the value is added at the 1st node in the list

  • removeFrom(index) - removes the node at index + 1 position in the linked list, returns the deleted value

  • removeValue(value) - removes the first node which has the same value, returns the deleted value

  • indexOf(value) - returns the index of the given value

  • isEmpty() - returns true if the list is empty

  • toArray() - returns the linked list as an array

  • display() - prints the graphical representation of the linked list in the console

  • forEach(callback) - calls the callback function for each element in the list and passes the value of each node as an argument to the callback function

  • clearAll() - clears the list

Doubly Linked Lists

Visual representation of doubly linked list - Source: medium.com

In a doubly linked list data is stored in individual objects named nodes. Each node has a value and link to the next node and a link to the previous. The main advantage of using a linked list over an singly linked list is that its much more useful but slightly slower.

Methods:

  • add(value) - adds a value to the end of the linked list

  • prepend(value) - adds a value to the start of the linked list

  • insertAt(index, value) - adds a value to the node at index + 1 position in the linked list i.e. if index is 0 the value is added at the 1st node in the list

  • removeFrom(index) - removes the node at index + 1 position in the linked list, returns the deleted value

  • removeValue(value) - removes the first node which has the same value, returns the deleted value

  • indexOf(value) - returns the index of the given value

  • isEmpty() - returns true if the list is empty

  • toArray() - returns the linked list as an array

  • display() - prints the graphical representation of the linked list in the console

  • forEach(callback) - calls the callback function for each element in the list and passes the value of each node as an argument to the callback function

  • clearAll() - clears the list

Stack

Visual representation of a stack - Source: pediaa.com

A stack is a collection of items in which only the most recently added item may be removed first. The latest added item is at the top. It is commonly used for implementing undo features, call stacks etc.

Methods:

  • push(value) - adds a value to the top of the stack

  • pop() - removes a value from the top of the stack, returns the deleted value

  • peek() - returns the value at the top of the stack without removing it

  • indexOf(value) - returns the index of the given value

  • isEmpty() - returns true if the stack is empty

  • toArray() - returns the stack as an array

  • display() - prints the graphical representation of the stack in the console

  • clearAll() - clears the list

Queue

Visual representation of a stack - Source: tutorialandexample.com

A queue is a collection of items in which only the earliest added item may be accessed first. Basic applications of queue include priority queue or serving shared resources to a single server etc.

Methods:

  • enqueue(value) - adds a value to the first position of the queue

  • dequeue() - removes a value from the first position of the queue, returns the deleted value

  • first() - returns the value from the first position of the queue without removing it

  • isEmpty() - returns true if the stack is empty

  • display() - prints the graphical representation of the stack in the console

  • clearAll() - clears the list