⚡ Tubelight.js
A pure javascript library providing most common data structures implementation.
Table of Contents
🚀 Quick Start
👉 Installation
Install Tubelight from npm
npm install tubelight
Stack
A stack is a linear data structure that follows the principle of Last In First Out (LIFO).
const Tubelight = require("tubelight");
const stack = new Tubelight.Stack();
⚒️ Operations that can be performed on Stack :
/**
* Push element on the top of the stack
* @param {Object} element
*/
stack.push(element);
/**
* Remove the topmost element from the stack
* @return {Object} element
*/
stack.pop();
/**
* return the element at the top of stack without removing it
* @return {Object} element
*/
stack.peek();
/**
* True if the stack is empty otherwise return false
* @return {Boolean}
*/
stack.isEmpty();
⏳ Time Complexity :
📦 Space Complexity :
Queue
Queue follows the First In First Out (FIFO) rule - the item that goes in first is the item that comes out first.
const Tubelight = require("tubelight");
const queue = new Tubelight.Queue();
⚒️ Operations that can be performed on Queue :
/**
* add element to the end of the queue
* @param {Object} element
*/
queue.enqueue(element);
/**
* remove element from the front of the queue
* @return {Object} element
*/
queue.dequeue(element);
/**
* return front element from the queue with removing it
* @return {Object} element
*/
queue.front();
/**
* return true if queue is empty otherwise false
* @return {Boolean}
*/
queue.isEmpty();
⏳ Time Complexity :
📦 Space Complexity :
Priority Queue
A priority queue is a special type of queue in which each element is associated with a priority value and elements are served based on their priority.
const Tubelight = require("tubelight");
const comparator = (a, b) => {
// priority of a will be higher than b;
return a > b;
};
/**
* This function will be used to decide the priority between two object
* @param {function} comparator
*/
const priorityQueue = new Tubelight.PriorityQueue(comparator);
⚒️ Operations that can be performed on Priority-Queue :
/**
* insert element in the priority-queue
* @param {Object} element
*/
priorityQueue.push(element);
/**
* remove and return the topmost priority element
* @return {Object} element
*/
priorityQueue.pop();
/**
* return the topmost priority element
* @return {Object} element
*/
priorityQueue.top();
/**
* return true if priority-queue is empty otherwise false
* @return {Boolean}
*/
priorityQueue.pop();
⏳ Time Complexity :
📦 Space Complexity :
Disjoint Set
Disjoint set union provides near-constant-time operations to add new sets, to merge existing sets, and to determine whether elements are in the same set.
const Tubelight = require("tubelight");
const disjointSet = new Tubelight.DisjointSet();
⚒️ Operations that can be performed on Disjoint-Set :
/**
* Union(x, y) combines the set containing element x and set containing element y
* @param {Object} x
* @param {Object} y
*/
disjointSet.union(x, y);
/**
* check if the set containing element x and set containing element y are same or not
* @param {Object} x
* @param {Object} y
* @returns {Boolean} true if x and y are in same set otherwise false
*/
disjointSet.sameSet(x, y);