{"id":11339,"library":"mnemonist","title":"Mnemonist Data Structures Library","description":"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.","status":"active","version":"0.40.3","language":"javascript","source_language":"en","source_url":"https://github.com/yomguithereal/mnemonist","tags":["javascript","bag","bimap","bit array","bit set","bit vector","bitset","bk tree","burkhard-keller tree","typescript"],"install":[{"cmd":"npm install mnemonist","lang":"bash","label":"npm"},{"cmd":"yarn add mnemonist","lang":"bash","label":"yarn"},{"cmd":"pnpm add mnemonist","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For modularity, most data structures are imported directly from their respective paths. CommonJS 'require' syntax also follows this pattern.","wrong":"const Heap = require('mnemonist/heap');","symbol":"Heap","correct":"import { Heap } from 'mnemonist/heap';"},{"note":"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.","wrong":"import { BloomFilter } from 'mnemonist';","symbol":"BloomFilter","correct":"import { BloomFilter } from 'mnemonist/bloom-filter';"},{"note":"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.","wrong":"import { intersection } from 'mnemonist/Set';","symbol":"set","correct":"import { intersection } from 'mnemonist/set';"}],"quickstart":{"code":"import { Heap } from 'mnemonist/heap';\nimport { BloomFilter } from 'mnemonist/bloom-filter';\nimport { BiMap } from 'mnemonist/bi-map';\nimport { intersection } from 'mnemonist/set'; // Note: 'set' module name for operations since v0.40.0\n\nconsole.log('--- Using a Min-Heap ---');\nconst minHeap = new Heap<number>((a, b) => a - b); // Custom comparator for min-heap\nminHeap.push(5);\nminHeap.push(2);\nminHeap.push(8);\nconsole.log('Heap size:', minHeap.size); // Expected: 3\nconsole.log('Min element:', minHeap.pop()); // Expected: 2\nconsole.log('Min element after pop:', minHeap.pop()); // Expected: 5\n\nconsole.log('\\n--- Using a Bloom Filter ---');\nconst filter = new BloomFilter(100, 3); // 100 bits, 3 hash functions\nfilter.add('apple');\nfilter.add('banana');\nconsole.log('Contains \"apple\":', filter.has('apple')); // Expected: true\nconsole.log('Contains \"orange\":', filter.has('orange')); // Expected: false (or very likely false)\n\nconsole.log('\\n--- Using a BiMap ---');\nconst biMap = new BiMap<string, number>();\nbiMap.set('one', 1);\nbiMap.set('two', 2);\nconsole.log('Value for \"one\":', biMap.get('one')); // Expected: 1\nconsole.log('Key for 2 via inverse map:', biMap.inverse.get(2)); // Expected: \"two\"\nconsole.log('Has \"three\":', biMap.has('three')); // Expected: false\n\nconsole.log('\\n--- Using Set Operations ---');\nconst setA = new Set([1, 2, 3]);\nconst setB = new Set([2, 3, 4]);\nconst commonElements = intersection(setA, setB);\nconsole.log('Intersection of {1,2,3} and {2,3,4}:', Array.from(commonElements)); // Expected: [2, 3]","lang":"typescript","description":"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."},"warnings":[{"fix":"Change `import { operation } from 'mnemonist/Set';` to `import { operation } from 'mnemonist/set';`","message":"The 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.","severity":"breaking","affected_versions":">=0.40.0"},{"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.","message":"Prior 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.","severity":"gotcha","affected_versions":"<0.40.0"},{"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.","message":"Several 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.","severity":"gotcha","affected_versions":"0.39.x, 0.40.x (minor versions)"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Update your import statement for Set operations from `import { operation } from 'mnemonist/Set';` to `import { operation } from 'mnemonist/set';`","cause":"Attempting to use the `Set` operations module with the uppercase 'Set' path after v0.40.0, where it was renamed to lowercase 'set'.","error":"TypeError: (0 , mnemonist_1.Set) is not a function"},{"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.","cause":"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.","error":"TypeError: __webpack_require__(...).Heap is not a constructor"}],"ecosystem":"npm"}