Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

my-data-structures

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

my-data-structures

My implementation of custom data structures. Linked lists

  • 0.0.7
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
80
increased by433.33%
Maintainers
1
Weekly downloads
 
Created
Source

Data Structures Module

Overview

A various collection of data structures, including linked lists, stacks, queues, sets, and more, for Node.js and JavaScript projects. Simplify complex data operations and promote code reusability in web servers, utilities, and data-intensive apps with seamless CommonJS and ESM integration.

Key Data Structures

  • Linked List: A flexible linked list implementation for dynamic data storage and manipulation.
  • Stack: A stack data structure for managing data in a Last-In, First-Out (LIFO) manner.
  • Queue: A queue data structure for managing data in a First-In, First-Out (FIFO) manner.
  • Sets: A set data structure for handling unique values and set operations.

Benefits

  • Efficient Data Management: Easily handle and organize data with optimized data structures.
  • Code Reusability: Encapsulate common data operations, reducing code duplication.
  • Interoperability: Import and use the toolbox seamlessly in CommonJS and ESM environments.

Use Cases

  • Use linked lists for managing data with dynamic insertions and deletions.
  • Employ stacks and queues for algorithmic operations or task scheduling.
  • Utilize sets for maintaining unique collections of data.

Getting Started

  1. Install npm package to your project

    npm i my-data-structures

  2. Usage

  • ESM
    import { linkedList } from 'my-data-structures';

    const list = new LinkedList();
  • CommonJS
    const { linkedList } = require('my-data-structures');

    const list = new LinkedList();

Consult the documentation for details.

Documentation

Stack

Representing a stack data structure.

property/methodparamsreturndescription
.push(element)element: anyundefinedadd an element to the end of the stack
.pop()element: any / nullremove the last element
.peek()element: any / nullget the last element
.isEmpty()booleancheck is the stack empty or not
.size()numberget the stack size (length)
.clear()undefinedremove all stack items
Queue

The simple queue data structure.

property/methodparamsreturndescription
.enqueue(element)element: anyundefinedadd an element to the queue
.dequeue()element: any / nullremove the element from the queue
.front()element: any / nullget the first queue element
.isEmpty()booleancheck is the queue emptynot
.size()numberget the queue length
.clear()undefinedremove all queue items
Linked List

Linked list data structure.

property/methodparamsreturndescription
.append(data)data: anyundefinedadd an element to the end of the linked list
.insert(position, data)position: number, data: anybooleaninsert an element to the specified position in the linked list
.remove(data)data: anydata: any / nullremove an element from the list
.removeAt(position)position: numberdata: any / nullremove an element by the position
.indexOf(data)data: anyindex: numberto find the element index
.toArray()arrayto convert linked list to an array
Doubly Linked List

Doubly Linked list data structure.

property/methodparamsreturndescription
.insert(position, data)position: number, data: anybooleaninsert an element to the specified position
.remove(data)data: anydata: any / nullremove an element from the list
.removeAt(position)position: numberdata: any / nullremove an element by the position
.indexOf(data)data: anyindex: numberto find the element index
.toArray()arrayto convert doubly linked list to an array
Extended set

Custom set data structure with extra methods.

property/methodparamsreturndescription
.union(otherSet)otherSet: anySet: anyGiven two sets, this returns a new set with elements from both the given sets
.intersection(otherSet)otherSet: anySet: anyGiven two sets, this returns a new set with the elements that exist in both sets
.difference(otherSet)otherSet: anySet: anyGiven two sets, this returns a new set with all the elements that exist in the first set and do not exist in the second set
.subset(otherSet)otherSet: anybooleanThis confirms whether a given set is a subset of another set

Keywords

FAQs

Package last updated on 10 Oct 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc