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

structure-data-collection

v1.0.4

Published

data collection that is easy and efficient to use

Downloads

8

Readme

structure-data-collection

A simple implementation of a linked list in TypeScript.

Table of Contents

Installation

You can install this package via npm:

    npm install structure-data-collection

Usage

Collection List

Here is an example of how to use the Collection.List class:

    import { Collection } from "structure-data-collection";

    const list = new Collection.List<number>();

    list.add(10);
    list.add(5);
    list.add(15);

    list.contain(10); // Output: true
    list.contain(100); //Output: false

    list.indexOf(10); //Output: 1
    list.indexOf(100); //Output: -1

    list.size(); //Output: 3

    list.get(1); //Output: 10
    list.get(100); //throw error index is not bound limit

    console.log(list.toJSON()) // { data: 15, next: { data: 5, next: { data: 10, next: null } } }

    console.log(list.toArray()); // Output: [10, 5, 15]

Collection Linked List

Here is an example of how to use the Collection.LinkedList class:

    import { Collection } from "structure-data-collection";

    const linkedList = new Collection.LinkedList<number>();

    linkedList.appendLast(200);

    linkedList.appendFirst(10);
    linkedList.appendFirst(20);

    linkedList.append(1, 80);

    console.log(linkedList.toReverseArray()) //Output: [200, 10, 80, 20]
    console.log(linkedList.toArray()) // Output: [20, 80, 10, 200]

    linkedList.removeFirst();
    console.log(linkedList.toArray()); //// Output: [80, 10, 200]

    console.log(linkedList.contain(80)); // Output: true
    console.log(linkedList.contain(20)); // Output: false

    console.log(linkedList.get(0)) // Output: 80

    console.log(linkedList.indexOf(1000)); //Output: -1

Collection Queue

Here is an example of how to use the Collection.Queue class:

    import { Collection } from "structure-data-collection";

    const queue = new Collection.Queue<string>();

    queue.enqueue("Aldo Ratmawan");
    queue.enqueue("John Alex");
    queue.enqueue("Erwin Clark");

    console.log(queue.size()); // Output: 3
    console.log(queue.peek()); // Output: Aldo Ratmawan
    console.log(queue.isEmpty()) ; // Output: false


    console.log(queue.dequeue()) // Output: Aldo Ratmawan
    console.log(queue.peek()) // Output: John Alex

    console.log(queue.toString()) // Output: John Alex Erwin Clark

    queue.clear();
    console.log(queue.isEmpty()); //Output: true

Collection Stack

Here is an example of how to use the Collection.Stack class:

    import { Collection } from "structure-data-collection";

    const stack = new Collection.Stack<number>();

    stack.push(100);
    stack.push(200);
    stack.push(300);
    stack.push(400);

    console.log(stack.size()); // Output: 4

    console.log(stack.peek()); // Output: 100
    console.log(stack.pop()); // Output: 100

    console.log(stack.size()); // Output: 3
    console.log(stack.peek()); // Output: 200

    console.log(stack.isEmpty()); // Output: false

    stack.clear();
    console.log(stack.isEmpty()) ; // Output: true

Collection HasMap

Here is an example of how to use the Collection.HasMap class:

    import { Collection } from "structure-data-collection";

    const hashMap = new Collection.HasMap<string, number>;

    hashMap.put("one", 1);
    hashMap.put("two", 2);
    hashMap.put("tree", 3);

    hashMap.values(); // Output: [1, 2, 3]
    hashMap.keys(); // Output: [on, two, three]

    hashMap.containKey("one"); //Output: true

Collection TreeNode

Here is an example of how to use the Collection.BinaryTree class:

    import { Collection } from "strukture-data-collection";

    const treeNode = new Collection.BinaryTree<number>();

    treeNode.add(100);
    treeNode.add(200);
    treeNode.add(300);

    treeNode.add(400);

    treeNode.height();

    treeNode.inorderTraversal((data) => {
        console.log(data)
    });

    treeNode.postorderTraversal((data) => {
        console.log(data)
    });

    treeNode.preorderTraversal((data) => {
        console.log(data)
    })

API

Collection.List<T>

Methods

  • add(data: T): void

    • Adds a new element to the list.
  • remove() : void

    • Removes the first element from the list
  • get() : T | undifined

    • Retrieves the element at the specified index
  • size() : number

    • Gets the number of elements in the list
  • indexOf(data: T) : number

    • Searches for the index of a particular element
  • contain(data: T) : boolean

    • Checks whether a particular element exists in a list
  • forEach(callback: (data: T, index: number) => void) : void

    • Iterates over each element in the list and runs the callback
  • toJSON() : object

    • Converts a list to JSON format
  • toArray(): Array<T>

    • Converts the list to an array.
Collection.LinkedList<T>

Methods

  • appendFirst(data: T): void

    • Adds a new element to the front of the list
  • appendLast(data: T): void

    • Add a new element to the end of the list
  • append(index: number, data: T): void

    • Add a new element at a specific index
  • removeFirst() : void

    • Remove the first element in the list
  • removeLast(): void

    • Remove the last element in the list
  • remove(data: T): void

    • Remove an element based on its value
  • removeAt(index: number): void

    • Remove an element at a specific index
  • get(index: number): T | null

    • Get an element at a specific index
  • indexOf(data: T): number

    • Find the index of a specific element
  • contain(data: T): boolean

    • Check if a specific element is in the list
  • size(): number

    • Get the number of elements in the lis
  • toTree(): Node.LinkedList<T> | null

    • Return the head of the list
  • toArray(): T[]

    • Convert the list to an array
  • toReverseArray(): T[]

    • Convert the list to a reversed array

Licence

    Copyright © 2024 Aldo Ratmawan

    Permission to use, copy, modify, and distribute this software for any
    purpose with or without fee is hereby granted, provided that the above
    copyright notice and this permission notice appear in all copies.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Author

name : Aldo Ratmawan
email: [email protected]