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

sb-js-data-structures

v1.0.8

Published

JavaScript Data Structure written in TypeScript

Downloads

37

Readme

Data Structures

JavaScript Data Structure written in TypeScript

Summary

Installation and Usage

Server-side:

Using npm:

npm install sb-ds-data-structures

Then where needed:

Typescript

import { LinkedList } from 'sb-js-data-structures'

const list = new LinkedList()

list.addToLast(1)
list.addToLast(2)

Documentation

Linked List

Creates a Linked List, a data structure where each element is a separate object and the elements are linked using pointers.

Initializer

import { LinkedList } from 'sb-js-data-structures'

const list = new LinkedList()

Methods

addToLast
public addToLast(element: T): void
Parameters
  • element T - The element to be inserted
Description

Inserts an element in the ending of the Linked List.

addToHead
public addToHead(element: T): void
Parameters
  • element T - The element to be inserted
Description

Inserts an element in the beginning of the Linked List.

addElementAtPosition
public addElementAtPosition(element: T, position: number): void
Parameters
  • element T - The element to be inserted
  • position number - position where the element should be inserted
Description

Inserts an element in a specific position of the Linked List, since position is less then the number of elements of the Linked List.

removeFromLast
public removeFromLast(): void
Description

Removes the element from the ending of the Linked List.

removeFromHead
public removeFromHead(): void
Description

Removes the element from the beginning of the Linked List.

removeFirstElementFoundFromList
public removeFirstElementFoundFromList(element: T): void
Parameters
  • element T - The element to be removed
Description

Removes the first element found in the Linked List.

removeAllElementsFromList
public removeAllElementsFromList(element: T): void
Parameters
  • element T - The element to be removed
Description

Removes all the elements found in the Linked List.

reverse
public reverse(): void
Description

Reverse the Linked List.

fromArray
public fromArray(element: T[]): void
Parameters
  • elements T[] - Array of elements
Description

Inserts all the elements at the ending of the Linked List.

toArray
public toArray(): T[]
Description

Creates an array with all the elements of the Linked List.

getLength
public getLength(): number
Returns
  • number - Linked List length.
Description

Gets the length of the Linked List.

isEmpty
public isEmpty(): boolean
Returns
  • boolean - Returns true if the Linked List has no elements, otherwise, returns false.
Description

Informs if the Linked List is empty.

print
public isEmpty(): boolean
Description

Display the Linked List elements.

Sorted List

Creates a Sorted List, a data structure where each element is a separate object, the elements linked using pointers and the elements are sorted.

Initializer

import { SortedList } from 'sb-js-data-structures'

const list = new SortedList()

Methods

add
public add(element: T): void
Parameters
  • element T - The element to be inserted
Description

Inserts an element in the Sorted List.

removeFromLast
public removeFromLast(): void
Description

Removes the element from the ending of the Sorted List.

removeFromHead
public removeFromHead(): void
Description

Removes the element from the beginning of the Sorted List.

removeFirstElementFoundFromList
public removeFirstElementFoundFromList(element: T): void
Parameters
  • element T - The element to be removed
Description

Removes the first element found in the Sorted List.

removeAllElementsFromList
public removeAllElementsFromList(element: T): void
Parameters
  • element T - The element to be removed
Description

Removes all the elements found in the Sorted List.

fromArray
public fromArray(element: T[]): void
Parameters
  • elements T[] - Array of elements
Description

Inserts all the elements at the ending of the Sorted List.

toArray
public toArray(): T[]
Description

Creates an array with all the elements of the Sorted List.

getLength
public getLength(): number
Returns
  • number - Sorted List length.
Description

Gets the length of the Sorted List.

isEmpty
public isEmpty(): boolean
Returns
  • boolean - Returns true if the Sorted List has no elements, otherwise, returns false.
Description

Informs if the Sorted List is empty.

print
public isEmpty(): boolean

Doubly Linked List

Creates a Doubly Linked List, a data structure where each element is a separate object and the elements linked using pointers to the next and the previous node.

Initializer

import { DoublyLinkedList } from 'sb-js-data-structures'

const list = new DoublyLinkedList()

Methods

insertToHead
public insertToHead(element: T): void
Parameters
  • element T - The element to be inserted
Description

Inserts an element in the beginning of the Doubly Linked List.

insertToTail
public insertToTail(element: T): void
Parameters
  • element T - The element to be inserted
Description

Inserts an element in the ending of the Doubly Linked List.

insertAtPosition
public insertAtPosition(element: T, position: number): void
Parameters
  • element T - The element to be inserted
  • position number - position where the element should be inserted
Description

Inserts an element in a specific position of the Doubly Linked List, since position is less than the number of elements of the Doubly Linked List.

deleteFromHead
public deleteFromHead(): void
Description

Deletes an element in the beginning of the Doubly Linked List.

deleteFromTail
public deleteFromTail(): void
Description

Deletes an element in the ending of the Doubly Linked List.

deleteFirstFound
public deleteFirstFound(element: T): void
Parameters
  • element T - The element to be deleted
Description

Deletes the element found in the Doubly Linked List.

deleteAllFound
public deleteAllFound(element: T): void
Parameters
  • element T - The element to be deleted
Description

Deletes all the elements found in the Doubly Linked List.

displayForward
public displayForward(): void
Description

Displays all elements in the Doubly Linked List from the first to the last element.

displayBackward
public displayBackward(): void
Description

Displays all elements in the Doubly Linked List from the last to the first element.

search
public search(element: T): number
Parameters
  • element T - The element to be searched
Returns
  • number - returns the position found or -1 if the element doesn't exist on the list.
Description

Searches the element in the Doubly Linked List.

fromArray
public fromArray(element: T[]): void
Parameters
  • elements T[] - Array of elements
Description

Inserts all the elements at the ending of the Doubly Linked List.

getLength
public getLength(): number
Returns
  • number - Doubly Linked List length.
Description

Gets the length of the Doubly Linked List.

isEmpty
public isEmpty(): boolean
Returns
  • boolean - Returns true if the Doubly Linked List has no elements, otherwise, returns false.
Description

Informs if the Doubly Linked List is empty.

Queue

Creates a Queue, a first-in-first-out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed.

Initializer

import { Queue } from 'sb-js-data-structures'

const queue = new Queue()

Methods

enqueue
public enqueue(element: T): void
Parameters
  • element T - The element to be inserted
Description

Inserts an element in the Queue.

dequeue
public dequeue(): void
Description

Removes an element from the Queue.

peek
public peek(): void
Description

Gets the element at the front of the Queue without removing it.

getLength
public getLength(): number
Returns
  • number - Queue length.
Description

Gets the length of the Queue.

isEmpty
public isEmpty(): boolean
Returns
  • boolean - Returns true if the Queue has no elements, otherwise, returns false.
Description

Informs if the Queue is empty.

Stack

Creates a Stack, a last-in-first-out (LIFO) data structure. In a LIFO data structure, the last element added to the stack will be the first one to be removed.

Initializer

import { Stack } from 'sb-js-data-structures'

const stack = new Stack()

Methods

push
public push(element: T): void
Parameters
  • element T - The element to be inserted
Description

Inserts an element in the Stack.

pop
public pop(): void
Description

Removes an element from the Stack.

peek
public peek(): void
Description

Gets the last element at the Stack without removing it.

getLength
public getLength(): number
Returns
  • number - Stack length.
Description

Gets the length of the Stack.

isEmpty
public isEmpty(): boolean
Returns
  • boolean - Returns true if the Stack has no elements, otherwise, returns false.
Description

Informs if the Stack is empty.

Hash Table

Creates a Hash Table, a data structure that stores in an array format, where each data value has its own unique index value.

Initializer

import { HashTable } from 'sb-js-data-structures'

const hash = new HashTable()

Methods

insert
public insert(key: string, value: T): void
Parameters
  • key string - The key
  • value T - The value to be inserted
Description

Inserts an element in the Hash Table.

delete
public delete(key: string): void
Parameters
  • key string - The key
Description

Removes an element from the Hash Table.

search
public search(key: string): void
Parameters
  • key string - The key
Description

Searches an element in a hash table.

Binary Search Tree

Creates a Binary Search Tree, a last-in-first-out (LIFO) data structure. In a LIFO data structure, the last element added to the tree will be the first one to be removed.

Creates a Binary Search Tree, a data structure that is a tree in which all the nodes follow: (1) The value of the key of the left sub-tree is less than the value of its parent (root) node's key; (2) The value of the key of the right sub-tree is greater than or equal to the value of its parent (root) node's key.

Initializer

import { BinarySearchTree } from 'sb-js-data-structures'

const tree = new BinarySearchTree()

Interfaces

INode
export interface INode<T> {
  element: T
  right: INode<T> | null
  left: INode<T> | null
}

Methods

insert
public insert(element: T): void
Parameters
  • element T - The element to be inserted
Description

Inserts an element in the Binary Search Tree.

delete
public delete(element: T): void
Parameters
  • element T - The element to be removed
Description

Removes an element from the Binary Search Tree.

search
public search(element: T): INode
Parameters
  • element T - The element to be searched
Description

Gets the last element at the Binary Search Tree without removing it.

Returns
  • INode - The node found.
getLength
public getLength(): number
Returns
  • number - Binary Search Tree length.
Description

Gets the number of elements of the Binary Search Tree.

isEmpty
public isEmpty(): boolean
Returns
  • boolean - Returns true if the Binary Search Tree has no elements, otherwise, returns false.
Description

Informs if the Binary Search Tree is empty.

fromArray
public fromArray(element: T[]): void
Parameters
  • elements T[] - Array of elements
Description

Inserts all the elements in the Binary Search Tree.

License

MIT