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.
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><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>
// 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
We have just briefly introduced Js-sdsl, and then we will start with a more in-depth study of the container category!
<textarea id='input'> const myOrderedMap = new OrderedMap(); myOrderedMap.setElement(1, 2); console.log(myOrderedMap.getElementByKey(1)); // 2 </textarea>
Run it Reset