@nodebasics/datastructures
v0.3.0
Published
This is a simple, zero dependencies, package with popular data structures. This package, although strives to provide high quality code, is new and not yet battle tested for high performance production scenarios. Therefore, consider alternative solutions
Readme
Node basics - Data structures
This is a simple, zero dependencies, package with popular data structures. This package, although strives to provide high quality code, is new and not yet battle tested for high performance production scenarios. Therefore, consider alternative solutions if your use case is sensitive to those factors.
Current data structures implemented
Queue
- Supports enqueue, dequeue, peekFront, peekTail, size, isEmpty, isFull, and collection operations.
- Queue documentation
Stack
- Supports push, pop, peek, size, isEmpty, isFull, and collection operations.
- Stack documentation
Installation
To install the package, run:
npm install @nodebasics/datastructuresVery simple usage example
import { Queue, Stack } from '@nodebasics/datastructures';
const queue = new Queue({ maxSize: 10 });
queue.enqueue(1);
queue.enqueue(2);
console.log(queue.dequeue()); // 1
console.log(queue.peekFront()); // 2
const stack = new Stack({ maxSize: 10 });
stack.push(1);
stack.push(2);
console.log(stack.pop()); // 2
console.log(stack.peek()); // 1