1.1.4 • Published 3 years ago

@tscafejr/common-data-structures v1.1.4

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Overview

This is a library to manage commonly used data structures in my projects.

Methods

Table of Contents

Common Data Structures

CircularLinkedList

Extends LinkedList

Creates a new CircularLinkedList instance

Properties

  • head Node? This is the head of the linked list.
  • tail Node? This is the tail of the linked list.
  • size number This is the length of the linked list.

add

This method adds an element to the end of the circular linked list.

Parameters

  • element any The element being added to the circular linked list.

Returns number The size of the linked list.

shiftHead

This method shifts the head of the circular linked list to to the right.

Graph

Creates a new Graph instance.

Properties

  • nodes (Array<any> | Array<string>) The list of nodes.
  • adjacencyList Object This tracks the adjacent nodes for a given node.

addNode

This method adds a node to the graph.

Parameters

  • node (string | any) The node that is inserted into the graph.

addEdge

This method only adds an edge to the graph if it does not exist already.

Parameters

  • node1 (string | any) The origin edge.
  • node2 (string | any) The destination edge.
  • weight number? The weight / cost of the link between the nodes.

findPathWithDijkstra

This finds a path from the start node to the end node using dijkstra's algorithm.

Parameters

  • startNode (string | any) The origin node.
  • endNode (string | any) The destination node.

Returns {path: [any], distance: number}

LinkedList

Creates a new LinkedList instance

Properties

  • head Node? This is the head of the linked list.
  • tail Node? This is the tail of the linked list.
  • size number This is the length of the linked list.

add

This method adds an element to a linked list and increments the size of the linked list.

Parameters

  • element any The element to add to the linked list.

addToBottom

This method adds an element to the end of the linked list.

Parameters

  • element any This is the element that will be added to the linked list.

addToTop

This method adds an element to the beginning of the linked list.

Parameters

  • element any This is the element that will be added to the linked list.

insertAt

This method adds an element at a specific index of a linked list

Parameters

  • element
  • index

Returns boolean

removeFrom

This method removes an element from a given index and returns that element

Parameters

  • index

Returns (number | any)

removeElement

This method removes a specific element from the linked list

Parameters

  • element

Returns (WebAssembly.TableKind | number)

indexOf

This method returns the index of given element

Parameters

  • element

Returns number

isEmpty

This method lets us know whether or not a linked list is empty.

Returns boolean

getTail

This method returns the tail node.

Returns Node The tail node.

getHead

This method returns the head node.

Returns Node The head node.

getSize

This method returns the size of the linked list.

Returns number The size of the linked list.

removeHead

This method removes a Node from the top of a linked list.

Returns any The node to return.

Node

Creates a new Node instance

Parameters

  • element any The element value of the node.

Properties

  • element any The element value of the node.
  • next Node? The next element following the node.
  • prev Node? The previous node.

PairTracker

This creates a new Pair Tracker instance

Parameters

  • collection Set<string> This set tracks the elements that have been added to the tracker

addPair

This method adds a pair to the pair tracker.

Parameters

orderPair

This method orders the pair and returns the same string.

Parameters

Returns string

pairExists

This method lets us know whether or not the pair is in the tracker.

Parameters

Returns boolean

getSize

This method returns the size of the pair tracker.

Returns number

PriorityQueue

Creates a new PriorityQueue instance

Properties

  • collection Array<any> The queue collection.
  • size number The number of elements in the queue.

enqueue

This method adds an element to the collection

Parameters

  • element

dequeue

This method removes an element from the collection

Returns any

isEmpty

This method checks to see if the collection is empty or not

Returns boolean

Queue

Creates a new Queue Instance

Properties

  • items Array<any> The items in the queue.
  • size number The size of the queue.

push

This method pushes an item onto the queue.

Parameters

  • item any

pop

This method removes the first item added to the queue.

Returns (null | any)

peek

This method returns the last item added to the queue without removing it.

Returns (null | any)

Stack

Creates a new Stack Instance

Properties

  • items Array<any> The items in the stack.

push

This method pushes an item onto the stack.

Parameters

  • item any

pop

This method removes the last item from the added to the stack.

Returns (null | any)

peek

This method returns the last item added to the stack without removing it.

Returns (null | any)

Trie

Creates a new Trie instance.

Properties

  • root Object The root node of the trie.

addWord

This method adds a word to the trie.

Parameters

  • word String The word to add to the trie.

addLetter

This method adds a letter to the trie on the node passed into the method.

Parameters

  • letter String The letter to add to the path.
  • node Object The node that the letter will be added to.

Returns Object

inTrie

This method lets us know whether a word is in the trie or not.

Parameters

  • word String The word being checked in the trie.

Returns boolean

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago