splaytree is a JavaScript library providing a fast, non-recursive implementation of a Splay tree data structure. It is designed for use in both Node.js environments (requiring Node.js >=18.20 or >=20) and modern browsers. The current stable version is 3.2.3, with recent patch releases indicating active maintenance and quick fixes for module resolution issues. Key differentiators include its simplicity (under 1000 lines of code) and high performance, offering amortized O(log n) time complexity for search, insert, and delete operations. It supports splitting, merging, key updates, bulk loading, and allows for optional duplicate keys. Its API is similar to w8r/avl, making it familiar to users of that library, and the implementation is adapted directly from Wikipedia's top-down splaying algorithm.
npm install splaytreeVerified import paths — ran on the pinned version, not inferred.
This example demonstrates creating a SplayTree, inserting and adding elements, retrieving keys and values, finding specific nodes, and checking the min/max keys, showcasing basic tree operations.
Thoroughly test your custom comparator function (function(a,b)) to ensure it returns 0 for equality, <0 if a<b, and >0 if a>b. Verify behavior with `comparator(a,b)` and `comparator(b,a)`.
Upgrade your Node.js environment to a compatible version (18.20+ or 20+). Check the `engines` field in `package.json` for precise requirements.
Choose `insert()` if you need to store multiple items with the same key, or `add()` if you require keys to be unique within the tree.
Prefer modern `import` statements over `require()` where possible. If using `require()`, be aware that you might need to access the default export via `.default` (e.g., `require('splaytree').default`) depending on your Node.js version and configuration.Ensure you are importing `SplayTree` correctly. For ESM, use `import SplayTree from 'splaytree';`. For CommonJS in some contexts, you may need `const SplayTree = require('splaytree').default;`.Carefully review and test your custom comparator function. Ensure it handles all edge cases, returns 0 for equality, a negative number for 'a < b', and a positive number for 'a > b', and that its logic is consistent for `comparator(a,b)` and `comparator(b,a)`.
No dependency data recorded yet.