Socket
Socket
Sign inDemoInstall

js-sdsl

Package Overview
Dependencies
0
Maintainers
2
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
4.4M
increased by1.58%
Maintainers
2
Install size
1.04 MB
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

Changelog

Source

[4.2.0] - 2022.11.20

Changed

  • Optimized the structure of class TreeNodeEnableIndex.
  • Change the iterator access denied error message to reduce the packing size.
  • Change the internal storage of the hash container to the form of a linked list, traversing in insertion order.
  • Standardize hash container. Make it extends from Container and add general functions.
  • Refactor LinkList to do optimization.

Added

  • Add public length property to all the container.
  • Add returned value to pop function including popBack and popFront to all the container which has such function.
  • Add returned value to eraseElementByKey which means whether erase successfully.
  • Add returned value to push or insert function which means the size of the container.

Fixed

  • Fixed wrong error type when updateKeyByIterator.
  • Fixed wrong iterator was returned when erase tree reverse iterator.

Readme

Source

js-sdsl logo

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

NPM Version Build Status Coverage Status GITHUB Star NPM Downloads Gzip Size Rate this package MIT-license GITHUB-language

English | 简体中文

✨ Included data structures

  • Stack - first in first out stack.
  • Queue - first in last out queue.
  • PriorityQueue - heap-implemented priority queue.
  • Vector - protected array, cannot to operate properties like length directly.
  • LinkList - linked list of non-contiguous memory addresses.
  • Deque - double-ended-queue, O(1) time complexity to unshift or getting elements by index.
  • OrderedSet - sorted set which implemented by red black tree.
  • OrderedMap - sorted map which implemented by red black tree.
  • HashSet - refer to the polyfill of ES6 Set.
  • HashMap - refer to the polyfill of ES6 Map.

⚔️ Benchmark

We are benchmarking against other popular data structure libraries. In some ways we're better than the best library. See benchmark.

🖥 Supported platforms

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
Opera
Opera
NodeJs
NodeJs
Edge 123149103610

📦 Download

Download directly by cdn:

Or install js-sdsl using npm:

npm install js-sdsl

Or you can download the isolation packages containing only the containers you want:

packagenpmsizedocs
@js-sdsl/stackNPM PackageGZIP Sizelink
@js-sdsl/queueNPM PackageGZIP Sizelink
@js-sdsl/priority-queueNPM PackageGZIP Sizelink
@js-sdsl/vectorNPM PackageGZIP Sizelink
@js-sdsl/link-listNPM PackageGZIP Sizelink
@js-sdsl/dequeNPM PackageGZIP Sizelink
@js-sdsl/ordered-setNPM PackageGZIP Sizelink
@js-sdsl/ordered-mapNPM PackageGZIP Sizelink
@js-sdsl/hash-setNPM PackageGZIP Sizelink
@js-sdsl/hash-mapNPM PackageGZIP Sizelink

🪒 Usage

You can visit our official website to get more information.

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

For previous versions of the documentation, please visit:

https://js-sdsl.org/js-sdsl/previous/v${version}/index.html

E.g.

https://js-sdsl.org/js-sdsl/previous/v4.1.5/index.html

For browser

<script src="https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js"></script>
<script>
    const {
      Vector,
      Stack,
      Queue,
      LinkList,
      Deque,
      PriorityQueue,
      OrderedSet,
      OrderedMap,
      HashSet,
      HashMap
    } = sdsl;
    const myOrderedMap = new OrderedMap();
    myOrderedMap.setElement(1, 2);
    console.log(myOrderedMap.getElementByKey(1)); // 2
</script>

For npm

// esModule
import { OrderedMap } from 'js-sdsl';
// commonJs
const { OrderedMap } = require('js-sdsl');
const myOrderedMap = new OrderedMap();
myOrderedMap.setElement(1, 2);
console.log(myOrderedMap.getElementByKey(1)); // 2

🛠 Test

Unit test

We use jest library to write unit tests, you can see test coverage on coveralls. You can run yarn test:unit command to reproduce it.

For performance

We tested most of the functions for efficiency. You can go to gh-pages/performance.md to see our running results or reproduce it with yarn test:performance command.

You can also visit here to get the result.

⌨️ Development

Use Gitpod, a free online dev environment for GitHub.

Open in Gippod

Or clone locally:

$ git clone https://github.com/js-sdsl/js-sdl.git
$ cd js-sdsl
$ npm install
$ npm run dev   # development mode

Then you can see the output in dist/cjs folder.

🤝 Contributing

Feel free to dive in! Open an issue or submit PRs. It may be helpful to read the Contributor Guide.

Contributors

Thanks goes to these wonderful people:


Takatoshi Kondo

💻 ⚠️

noname

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

❤️ Sponsors and Backers

The special thanks to these sponsors or backers because they provided support at a very early stage:

eslint logo

Thanks also give to these sponsors or backers:

sponsors

backers

🪪 License

MIT © ZLY201

Keywords

FAQs

Last updated on 21 Nov 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