@d1g1tal/collections

2.0.2 • Public • Published

collections

JavaScript Collections and Data Structures

Build Status Coverage Status npm version

Breaking Changes!

To my tens of users, I recently decided to learn TypeScript and I wanted to rewrite this library in TypeScript. The EvictingCache class has been removed as it is its own library now. I have also decided to change the way the classes are imported. Named exports are used now instead of default. Also, testing is now done using Vitest instead of Jest.

This is a collection of JavaScript data structures and algorithms. The goal is to provide a comprehensive set of data structures and algorithms that can be used in JavaScript programs.

Installation

npm install @d1g1tal/collections

Usage

List

import { List } from '@d1g1tal/collections';

const list = new List();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);

list.forEach((value) => {
	console.log(value); // 1, 2, 3, 4, 5
});

list.remove(3);

list.forEach((value) => {
	console.log(value); // 1, 2, 4, 5
});

LinkedList

import { LinkedList } from '@d1g1tal/collections';

const linkedList = new LinkedList();
linkedList.add(1);
linkedList.add(2);
linkedList.add(3);
linkedList.add(4);
linkedList.add(5);

linkedList.forEach((value) => {
	console.log(value); // 1, 2, 3, 4, 5
});

linkedList.remove(3);

linkedList.forEach((value) => {
	console.log(value); // 1, 2, 4, 5
});

linkedList.clear();

linkedList.forEach((value) => {
	console.log(value); // nothing
});

console.log(linkedList.size); // 0

Doubly Linked List

const doublyLinkedList = new LinkedList(LinkedList.Type.Doubly);

doublyLinkedList.add(1);
doublyLinkedList.add(2);
doublyLinkedList.add(3);
doublyLinkedList.add(4);
doublyLinkedList.add(5);

doublyLinkedList.forEach((value) => {
	console.log(value); // 1, 2, 3, 4, 5
});

doublyLinkedList.reverse();

doublyLinkedList.forEach((value) => {
	console.log(value); // 5, 4, 3, 2, 1
});

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.23latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.23
2.0.12
2.0.02
1.0.11
1.0.01
0.2.51
0.2.41
0.2.30
0.2.20
0.2.10
0.2.00
0.1.20
0.1.10
0.1.00
0.0.50
0.0.40
0.0.30
0.0.20
0.0.11

Package Sidebar

Install

npm i @d1g1tal/collections

Weekly Downloads

9

Version

2.0.2

License

ISC

Unpacked Size

171 kB

Total Files

39

Last publish

Collaborators

  • d1g1tal