0.0.7 • Published 7 months ago

my-data-structures v0.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

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
0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago