Socket
Socket
Sign inDemoInstall

js-sdsl

Package Overview
Dependencies
0
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    js-sdsl

javascript standard data structure library which benchmark against C++ STL


Version published
Weekly downloads
3.8M
decreased by-4.82%
Maintainers
1
Install size
432 kB
Created
Weekly downloads
 

Package description

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

Readme

Source

js-sdsl

A javascript standard data structure library which benchmark against C++ STL.

Note

Note that our official version starts from 2.0.0. In order to avoid unnecessary trouble, please select the latest version when downloading (>= 2.0.0).

Unfortunately, I try my best to improve the performance of hash table but failed. Ideally, the hash table should be O(1) and in my project when the size of each bucket is 1, its time is much longer than Set and Map.

After analysis, I find the operator new costs nearly 2s when the size is 1e6, This seems to be the bottleneck of js.

You can try the following code to verify my statement.

console.time("run");
const arr = new Array(1000000);
arr[100000] = new Array();
console.timeEnd("run");

You can imagine what happens when I repeat the above operation many times.

If you want to use hash container in js, please use set or map in ES6.

The official Set and Map are implemented using hash table instead of RBTree.

For more information about js hash table, please refer to https://stackoverflow.com/questions/368280/javascript-hashmap-equivalent.

Included data structures

  • Vector
  • Stack
  • Queue
  • LinkList
  • Deque
  • PriorityQueue
  • Set (using RBTree)
  • Map (using RBTree)
  • HashSet (for reference only)
  • HashMap (for reference only)

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

npm install js-sdsl

Usage

To help you have a better use, we provide this API document.

For Browser

<!-- you can download the file locally and import it or import it dynamically by using url. -->
<script src="https://zly201.github.io/js-sdsl/js-sdsl.min.js"></script>
<script>
    const { Vector } = sdsl;
    const myVector = new Vector();
    // you code here...
</script>

Other

Just like other packages.

If you want to get more help, viewing src/test.ts may help.

Build by source code

You can pull this repository and run yarn build to rebuild this library.

Unit test

Before publishing, we conducted strict unit tests on each function, you can see testResult.txt to find our test results or run yarn test to reproduce it.

License

This project is MIT licensed.

Keywords

FAQs

Last updated on 06 Jan 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc