What is js-sdsl?
The js-sdsl package is a JavaScript library that provides a variety of data structures and algorithms. It is designed to be efficient and easy to use, offering structures like vectors, lists, queues, stacks, and trees, as well as algorithms for sorting, searching, and other operations.
What are js-sdsl's main functionalities?
Vector
Vector is a dynamic array that can grow and shrink in size. It provides random access to elements, similar to an array.
const { Vector } = require('js-sdsl');
let vector = new Vector();
vector.pushBack(1);
vector.pushBack(2);
console.log(vector.size()); // Output: 2
LinkedList
LinkedList is a sequence of elements where each element points to the next. It allows for efficient insertion and removal of elements from any position.
const { LinkedList } = require('js-sdsl');
let linkedList = new LinkedList();
linkedList.pushBack(1);
linkedList.pushFront(0);
console.log(linkedList.front()); // Output: 0
Queue
Queue is a first-in-first-out (FIFO) data structure that allows for efficient addition of elements at the end and removal from the front.
const { Queue } = require('js-sdsl');
let queue = new Queue();
queue.push(1);
queue.push(2);
console.log(queue.front()); // Output: 1
Stack
Stack is a last-in-first-out (LIFO) data structure that allows for adding and removing elements from the top of the stack.
const { Stack } = require('js-sdsl');
let stack = new Stack();
stack.push(1);
stack.push(2);
console.log(stack.top()); // Output: 2
Tree
Tree structures like AVLTree are used to store data in a hierarchical manner. AVLTree is a self-balancing binary search tree.
const { AVLTree } = require('js-sdsl');
let tree = new AVLTree();
tree.insert(1);
tree.insert(2);
console.log(tree.find(1)); // Output: true
Other packages similar to js-sdsl
immutable
Immutable.js offers persistent immutable data structures. Unlike js-sdsl, which provides mutable structures, Immutable.js ensures that the data cannot be changed once created.
lodash
Lodash is a utility library that provides functions for common programming tasks, including manipulating and testing values, arrays, objects, and strings. It is more focused on utility functions than the data structure implementations provided by js-sdsl.
underscore
Underscore.js is a utility library similar to Lodash, offering a range of functions for working with JavaScript collections and arrays. It does not focus on providing data structures but offers many utilities for working with existing ones.
A javascript standard data structure library
Included data structures
- Vector
- Stack
- Queue
- LinkList
- Deque
- PriorityQueue
Supported platforms
- node.js (using commonjs)
- react/vue (using es5)
- browser (support most browsers including IE8+)
Download
Download directly
Or install js-sdsl using npm (It will become soon)
npm install js-sdsl
Usage
Please see API documents or see src/test.ts
to find usage.
Build by source code
You can pull this repository and run yarn build
or run yarn test
to test our library.
License
This project is MIT licensed.