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

node-structures

v4.0.2

Published

Simple implementation of data structures in Javascript.

Downloads

33

Readme

node-structures

Build Status npm Code Climate GitHub license GitHub issues

Basic Data Structures for use in JavaScript (server-side, client side)

Description

The Library provides the following Data Structure Implementations

Installation

Server-side: npm install node-structures

Client-side: bower install node-structures

Usage

###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();

###Priority Queue

  const PriorityQueue = require('node-structures').PriorityQueue;
  /**
   * Creates an empty PriorityQueue with default comparator.
   * 
   * Default Comparator: Compares `a` and `b`, when `a > b` it returns a positive number, when `a` = `b` it returns 0,
   *  and when `a < b` it returns a negative number.
   */
  let priorityQueue = new PriorityQueue();
  
  /**
   * Creates an empty PriorityQueue with custom comparator.
   *
   * (`a > b` - return a positive number, when `a` = `b` return 0, and when `a < b`) return a negative number.
   */
  const comparator = function(a, b){
     return a - b; // define your own one.
  };
  let priorityQueue = new PriorityQueue(comparator);
  
  /**
   * Returns the number of elements in this collection
   *
   * @returns {Number} - the number of elements in this collection
   */
   priorityQueue.size();
   
  /**
   * Tests if this priority queue is empty.
   *
   * @returns {boolean} - true if and only if this priority queue contains no items; false otherwise.
   */
   priorityQueue.isEmpty();
   
   /**
    * Inserts the specified element into this priority queue.
    *
    * @param element - the element to add
    * @returns {boolean} Returns true
    */
    priorityQueue.add(40);
    
    /**
     * Retrieves and removes the head of this priority queue, or returns null if this priority queue is empty.
     *
     * @returns {*} Returns the head of this priority queue, or null if this priority queue is empty.
     */
     priorityQueue.poll();
     
     /**
      * Retrieves, but does not remove, the head of this priority queue, or returns null if this priority queue is empty.
      *
      * @returns {*} Returns the head of this priority queue, or null if this priority queue is empty.
      */
      priorityQueue.peek();

###Linked List

  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();

License

MIT