Registry / serialization / js-sdsl

js-sdsl

JSON →
library4.4.2jsnpmunverified

js-sdsl is a comprehensive JavaScript library providing various standard data structures, designed to offer high performance comparable to C++ STL. It includes implementations for structures like Stack, Queue, PriorityQueue, Vector, LinkedList, Deque, OrderedSet, OrderedMap, HashSet, and HashMap. The library is currently on stable version 4.4.2, actively maintained with a regular release cadence as seen by frequent updates within the 4.x series. Its key differentiators include optimized performance that often surpasses other popular JavaScript data structure libraries (e.g., Denque), a lightweight footprint (~9KB compressed), and a lack of external dependencies. It also provides C++ STL-like bidirectional iterators and ships with full TypeScript type definitions, making it suitable for modern JavaScript and TypeScript projects that require efficient, robust data management.

npm install js-sdsl
INSTALL
IMPORT
SIG · JS-SDSL
J
js-sdsl
serializationjavascriptv4.4.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OrderedMap
import { OrderedMap } from 'js-sdsl';
const OrderedMap = require('js-sdsl').OrderedMap;
ESM imports are the recommended standard. For v4+, direct CommonJS `require('js-sdsl').OrderedMap` may not work as expected due to changes in CJS target to ES6 in v4.1.0. Use `import()` for dynamic CJS loading if strictly necessary, but prefer ESM.
Vector
import { Vector } from 'js-sdsl';
const Vector = require('js-sdsl').Vector;
As with all exports from js-sdsl v4+, prefer named ESM imports. This ensures correct tree-shaking and module resolution in modern build environments.
OrderedSet
import { OrderedSet } from 'js-sdsl';
import { Set } from 'js-sdsl'; // Incorrect symbol name for v4+
In version 4.x and later, the `Set` and `Map` classes were renamed to `OrderedSet` and `OrderedMap` respectively to avoid conflicts with native JavaScript `Set` and `Map` global objects.
Deque
import { Deque } from 'js-sdsl';
const Deque = require('js-sdsl'); // CommonJS import often requires destructuring for named exports
Always explicitly import the specific data structure classes you need. Direct `require('js-sdsl')` will not expose the individual classes in a usable way for CJS without further destructuring. ESM named imports are cleaner.

This quickstart demonstrates the instantiation and basic operations of OrderedMap, Deque, and Vector, including adding, retrieving, iterating, and modifying elements.

import { OrderedMap, Deque, Vector } from 'js-sdsl'; // Using an OrderedMap (a sorted map implemented with a red-black tree) const myOrderedMap = new OrderedMap<string, number>(); myOrderedMap.set('apple', 10); myOrderedMap.set('banana', 20); myOrderedMap.set('cherry', 5); console.log('OrderedMap size:', myOrderedMap.size()); // Output: 3 console.log('Value of apple:', myOrderedMap.get('apple')); // Output: 10 myOrderedMap.forEach((key, value) => { console.log(`Map: ${key} -> ${value}`); }); // Output: // Map: apple -> 10 // Map: banana -> 20 // Map: cherry -> 5 // Using a Deque (Double-ended queue) const myDeque = new Deque<string>(); myDeque.pushFront('first'); myDeque.pushBack('second'); myDeque.pushFront('zero'); console.log('Deque elements:', myDeque.toArray()); // Output: [ 'zero', 'first', 'second' ] console.log('Pop back:', myDeque.popBack()); // Output: second console.log('Pop front:', myDeque.popFront()); // Output: zero // Using a Vector (a protected array) const myVector = new Vector<number>([1, 2, 3]); myVector.pushBack(4); myVector.insert(0, 0); console.log('Vector elements:', myVector.toArray()); // Output: [ 0, 1, 2, 3, 4 ] console.log('Element at index 2:', myVector.getElementByPos(2)); // Output: 2
Debug
Known issues
breakingIn version 4.x, the classes `Set` and `Map` were renamed to `OrderedSet` and `OrderedMap` respectively. If you are migrating from v3 or earlier, you must update your imports and class instantiations to use the new names to avoid conflicts with native JavaScript `Set` and `Map` objects. Additionally, `eraseElementByValue` on `HashSet` and `OrderedSet` was renamed to `eraseElementByKey` in v4.0.0.
fix
Rename `Set` to `OrderedSet` and `Map` to `OrderedMap` in your code. Update method calls from `eraseElementByValue` to `eraseElementByKey` for affected containers.
affects: >=4.0.0
gotchaWhile `js-sdsl` offers high-performance data structures, for very small datasets or simple array/object operations, native JavaScript `Array` or `Map`/`Set` might sometimes exhibit comparable or even better performance due to V8 engine optimizations. `js-sdsl` shines in scenarios requiring specific algorithmic complexities, ordered iteration, or large-scale data manipulation where its optimized implementations provide consistent benefits.
fix
Benchmark critical sections of your application to determine if `js-sdsl` provides a meaningful performance improvement for your specific use case, especially for smaller datasets.
affects: >=3.0.0
breakingWith version 4.1.0, the CommonJS target was changed to ES6. While `js-sdsl` generally aims for broad compatibility, modern Node.js environments and bundlers primarily favor ES Modules (ESM). Using `require()` for named exports in CJS contexts with `js-sdsl` v4+ may lead to unexpected behavior or `undefined` imports.
fix
Refactor your module imports to use ESM `import { Name } from 'js-sdsl';` syntax. If you are in a pure CommonJS environment, consider using dynamic `import('js-sdsl').then(...)` or ensure your build setup correctly transpiles ESM to CJS with named exports.
affects: >=4.1.0
gotchaIterator behavior and internal implementations were subject to changes in the 4.x series. Specifically, `OrderedMap`'s iterator pointer retrieval changed from `Object.defineProperty` to `Proxy` in v4.1.4, and iterator type descriptions evolved. While generally backward-compatible for common use, advanced iterator manipulation might require re-testing.
fix
If experiencing unexpected iterator behavior, review the `CHANGELOG.md` for your specific `js-sdsl` version regarding iterator updates and adjust custom iterator logic or assumptions accordingly.
affects: >=4.1.0
Errors
Common errors & fixes
ReferenceError: OrderedMap is not defined
Attempting to use `OrderedMap` (or other classes) without a proper ESM named import, or an incorrect CommonJS `require` call that does not destructure the named export.
fix
Ensure you are using `import { OrderedMap } from 'js-sdsl';` in ESM or `const { OrderedMap } = require('js-sdsl');` in CJS. For v4+, ESM is highly recommended.
TypeError: container.set is not a function
This error typically occurs when attempting to call a method like `set` on a variable that is either not an instance of the expected data structure (e.g., `OrderedMap`), or has not been properly initialized.
fix
Verify that `container` is correctly initialized, for example: `const container = new OrderedMap<KeyType, ValueType>();`. Also, ensure you are calling the correct method for the specific data structure (e.g., `OrderedSet` uses `add` instead of `set`).
Error: Iterator access denied
This error message indicates an invalid operation on an iterator, possibly due to accessing an iterator that has become invalid (e.g., after an element it pointed to was removed) or attempting to dereference an 'end' iterator.
fix
Always check iterator validity before dereferencing or using it. Ensure that modifications to the container do not invalidate active iterators that are subsequently used. The library implements C++ STL-like iterators, so similar rules regarding iterator invalidation apply.
Upgrade
Version history
4.4.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources