Registry / database / mnemonist

mnemonist

JSON →
library0.40.3jsnpmunverified

Mnemonist is a comprehensive, curated collection of over 50 data structures for JavaScript and TypeScript. It includes classic structures like Heaps, Queues, and LRU Caches, alongside more specialized and exotic options such as Burkhard-Keller Trees, Bloom Filters, and Fibonacci Heaps. The library emphasizes high performance, modularity, ease of use with an API consistent with standard JavaScript objects, and full TypeScript support. The current stable version is 0.40.3, with minor updates and fixes released regularly, often multiple times a month, addressing bug fixes and type declaration improvements. Its key differentiators are the sheer breadth of its offerings, from foundational structures to highly specialized algorithms for information retrieval and metric space indexation, all while maintaining a focus on performance and robust typing. Mnemonist does not include a Graph data structure due to its typical complexity.

npm install mnemonist
INSTALL
IMPORT
SIG · MNEMONIST
M
mnemonist
databasejavascriptv0.40.3
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.

Heap
import { Heap } from 'mnemonist/heap';
const Heap = require('mnemonist/heap');
For modularity, most data structures are imported directly from their respective paths. CommonJS 'require' syntax also follows this pattern.
BloomFilter
import { BloomFilter } from 'mnemonist/bloom-filter';
import { BloomFilter } from 'mnemonist';
Individual data structures are typically imported from their specific module path, not directly from the main 'mnemonist' package name. This ensures tree-shaking and modularity.
set
import { intersection } from 'mnemonist/set';
import { intersection } from 'mnemonist/Set';
Since v0.40.0, the module for set operations was renamed from `Set` to `set` (lowercase) to avoid CommonJS named export collisions. TypeScript users should also update their imports accordingly.

This quickstart demonstrates the instantiation and basic usage of a Min-Heap, a Bloom Filter, a BiMap, and a set intersection operation, showcasing common patterns for importing and interacting with Mnemonist data structures.

import { Heap } from 'mnemonist/heap'; import { BloomFilter } from 'mnemonist/bloom-filter'; import { BiMap } from 'mnemonist/bi-map'; import { intersection } from 'mnemonist/set'; // Note: 'set' module name for operations since v0.40.0 console.log('--- Using a Min-Heap ---'); const minHeap = new Heap<number>((a, b) => a - b); // Custom comparator for min-heap minHeap.push(5); minHeap.push(2); minHeap.push(8); console.log('Heap size:', minHeap.size); // Expected: 3 console.log('Min element:', minHeap.pop()); // Expected: 2 console.log('Min element after pop:', minHeap.pop()); // Expected: 5 console.log('\n--- Using a Bloom Filter ---'); const filter = new BloomFilter(100, 3); // 100 bits, 3 hash functions filter.add('apple'); filter.add('banana'); console.log('Contains "apple":', filter.has('apple')); // Expected: true console.log('Contains "orange":', filter.has('orange')); // Expected: false (or very likely false) console.log('\n--- Using a BiMap ---'); const biMap = new BiMap<string, number>(); biMap.set('one', 1); biMap.set('two', 2); console.log('Value for "one":', biMap.get('one')); // Expected: 1 console.log('Key for 2 via inverse map:', biMap.inverse.get(2)); // Expected: "two" console.log('Has "three":', biMap.has('three')); // Expected: false console.log('\n--- Using Set Operations ---'); const setA = new Set([1, 2, 3]); const setB = new Set([2, 3, 4]); const commonElements = intersection(setA, setB); console.log('Intersection of {1,2,3} and {2,3,4}:', Array.from(commonElements)); // Expected: [2, 3]
Debug
Known issues
breakingThe module for generic Set operations (e.g., `intersection`, `union`) was renamed from `Set` to `set` (lowercase) in v0.40.0. This was done to resolve a CommonJS named export collision. Users should update their import paths.
fix
Change `import { operation } from 'mnemonist/Set';` to `import { operation } from 'mnemonist/set';`
affects: >=0.40.0
gotchaPrior to v0.40.0, Mnemonist primarily supported CommonJS modules. While browser bundling was possible, direct ESM named exports were not officially supported. Version 0.40.0 introduced comprehensive ESM named exports, improving compatibility with modern build tools and environments.
fix
For optimal ESM compatibility, upgrade to v0.40.0 or higher. For older versions, rely on CommonJS `require()` or ensure your bundler correctly handles the CJS output.
affects: <0.40.0
gotchaSeveral type declaration fixes for specific data structures (e.g., `BloomFilter.from`, `SparseMap` constructor overloads, `BiMap.get`) were released in recent minor versions. Users relying heavily on TypeScript might encounter type-related issues or missing overloads if they are not on the latest minor release for their major version.
fix
Ensure you are using the latest patch version (e.g., `0.40.3`) to benefit from the most up-to-date and accurate TypeScript declarations.
affects: 0.39.x, 0.40.x (minor versions)
Errors
Common errors & fixes
TypeError: (0 , mnemonist_1.Set) is not a function
Attempting to use the `Set` operations module with the uppercase 'Set' path after v0.40.0, where it was renamed to lowercase 'set'.
fix
Update your import statement for Set operations from `import { operation } from 'mnemonist/Set';` to `import { operation } from 'mnemonist/set';`
TypeError: __webpack_require__(...).Heap is not a constructor
This error, common in bundled environments, indicates an incorrect import or module resolution, often when using `require()` syntax in an ESM context or an incorrect named import path.
fix
Ensure you are using specific, correct import paths like `import { Heap } from 'mnemonist/heap';`. If using CommonJS, `const Heap = require('mnemonist/heap');`. Verify your bundler configuration for proper module resolution, especially if on versions prior to 0.40.0.
Upgrade
Version history
0.40.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
mnemonist — npm install mnemonist · libregistry