{"library":"splaytree","title":"Fast Splay Tree","type":"library","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install splaytree"],"cli":null},"imports":["import SplayTree from 'splaytree';","import type { Node } from 'splaytree';"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/w8r/splay-tree","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/splaytree","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import SplayTree from \"splaytree\";\n\nconst tree = new SplayTree();\n\n// Insert various key-value pairs\ntree.insert(5, \"apple\");\ntree.insert(-10, \"banana\");\ntree.add(0, \"cherry\"); // Using add to prevent duplicates if 0 already existed\ntree.insert(33, \"date\");\ntree.insert(2, \"elderberry\");\ntree.insert(5, \"fig\"); // Demonstrates duplicate key insertion with 'insert'\n\nconsole.log(\"Keys in sorted order:\", tree.keys());\nconsole.log(\"Values in sorted order:\", tree.values());\nconsole.log(\"Node with key 0:\", tree.find(0)?.data); // Finds data associated with key 0\nconsole.log(\"Minimum key:\", tree.min());\nconsole.log(\"Maximum key:\", tree.max());\nconsole.log(\"Tree size:\", tree.size);","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}