Skip to content

Latest commit

 

History

History
181 lines (146 loc) · 10.7 KB

introduction.md

File metadata and controls

181 lines (146 loc) · 10.7 KB

What Is Js-sdsl

Js-sdsl is a JavaScript standard data structure library implemented with reference to C++ STL, which is used to make up for the lack of some data structures in JavaScript.

If you have some research on C++ STL libraries, then Js-sdsl is completely pediatric for you, we provide almost all data structures in C++ STL:

  • Stack - first in last out stack.
  • Queue - first in first 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.

Unlike other Js data structure libraries, Js-sdsl is completely self-contained. It is written in TypeScript, has strict type deduction, and is implemented with reference to OOP. All containers have a common ancestor.

If you want to know more about the comparison of Js-sdsl with other mainstream libraries, please refer to benchmark.

Start

If you are using a browser, we provide cdn import:

<!-- development -->
<script src='https://unpkg.com/js-sdsl/dist/umd/js-sdsl.js' />
<!-- production -->
<script src='https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js' />

or use npm:

npm i js-sdsl

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

<style>.markdown-section>table{display:table;text-align:left;}</style>
package npm size docs
@js-sdsl/stack NPM Package GZIP Size link
@js-sdsl/queue NPM Package GZIP Size link
@js-sdsl/priority-queue NPM Package GZIP Size link
@js-sdsl/vector NPM Package GZIP Size link
@js-sdsl/link-list NPM Package GZIP Size link
@js-sdsl/deque NPM Package GZIP Size link
@js-sdsl/ordered-set NPM Package GZIP Size link
@js-sdsl/ordered-map NPM Package GZIP Size link
@js-sdsl/hash-set NPM Package GZIP Size link
@js-sdsl/hash-map NPM Package GZIP Size link

Usage

Browser

<script src='https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js' />
<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>

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

Ready

We have just briefly introduced Js-sdsl, and then we will start with a more in-depth study of the container category!

Try it

<textarea id='input'> const myOrderedMap = new OrderedMap(); myOrderedMap.setElement(1, 2); console.log(myOrderedMap.getElementByKey(1)); // 2 </textarea>

Run it Reset