Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
node-structures
Advanced tools
Basic Data Structures for use in JavaScript (server-side, client side)
The Library provides the following Data Structure Implementations
Server-side: npm install node-structures
Client-side: bower install node-structures
###Stack
const Stack = require('node-structures').Stack;
let stack = new Stack();
/**
* Tests if this stack is empty.
* @returns {boolean} - true if and only if this stack contains no items; false otherwise.
*/
stack.isEmpty();
/**
* Pushes an item onto the top of this stack.
* @param item - the item to be pushed onto this stack.
* @return {boolean} - true if the item is pushed.
*/
stack.push(3);
/**
* Looks at the object at the top of this stack without removing it from the stack.
* @throws {Error} - if this stack is empty.
* @returns {*} - the object at the top of this stack (the last item of the Vector object).
*/
stack.peek();
/**
* Removes the object at the top of this stack and returns that object as the value of this function.
* @throws {Error} - if this stack is empty.
* @return {*} - the object at the top of this stack (the last item of the Vector object).
*/
stack.pop();
/**
* Returns the size of the stack.
* @returns {Number} - the size of the stack.
*/
stack.size();
###Queue
const Queue = require('node-structures').Queue;
let queue = new Queue();
/**
* Returns the size of the queue.
* @returns {Number} - the size of the queue.
*/
queue.size();
/**
* Tests if this queue is empty.
* @returns {boolean} - true if and only if this queue contains no items; false otherwise.
*/
queue.isEmpty();
/**
* Inserts the specified element into this queue.
* @param element - the element to add
* @return {boolean} Returns true
*/
queue.add(3);
/**
* Retrieves and removes the head of this queue. This method differs from poll only in that it throws an exception
* if this queue is empty.
* @throws {Error} when the queue is empty.
* @return {*} Returns the head of this queue
*/
queue.remove();
/**
* Retrieves and removes the head of this queue, or returns null if this queue is empty.
* @returns {*} Returns the head of this queue, or null if this queue is empty.
*/
queue.poll();
/**
* Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
* @returns {*} Returns the head of this queue, or null if this queue is empty.
*/
queue.peek();
###LinkedList
const LinkedList = require('node-structures').LinkedList;
let linkedList = new LinkedList();
/**
* Tests if this LinkedList is empty.
* @returns {boolean} - true if and only if this LinkedList contains no items; false otherwise.
*/
linkedList.isEmpty();
/**
* Inserts the specified element at the beginning of this list.
* @param data - the element to add
*/
linkedList.addFirst("A");
/**
* Appends the specified element to the end of this list.
* @param data - the element to add
*/
linkedList.addLast("B");
/**
* Inserts the specified element at the specified position in this list.
* Shifts the element currently at that position (if any) and any subsequent elements to the right
* (adds one to their indices).
* @throws IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
* @param index - index at which the specified element is to be inserted
* @param element - element to be inserted
*/
linkedList.add(1, "C");
/**
* Removes the element at the specified position in this list. Shifts any subsequent elements to the left
* (subtracts one from their indices).
* Returns the element that was removed from the list.
* @throws IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
* @param index - the index of the element to be removed
* @returns {*} - the element previously at the specified position
*/
linkedList.remove(2);
/**
* Returns the element at the specified position in this list.
* @throws IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
* @param index - index of the element to return
* @returns {*} - the element at the specified position in this list
*/
linkedList.get(1);
/**
* Returns the number of elements in this list.
* @returns {Number} - the number of elements in this list.
*/
linkedList.size();
/**
* Removes all of the elements from this list. The list will be empty after this call returns.
*/
linkedList.clear();
MIT
FAQs
Simple implementation of data structures in Javascript.
The npm package node-structures receives a total of 1 weekly downloads. As such, node-structures popularity was classified as not popular.
We found that node-structures demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.