{"library":"splaytree-ts","title":"Splay Tree Data Structures for TypeScript","type":"library","description":"splaytree-ts is a TypeScript library that provides efficient implementations of Splay Tree data structures, specifically `SplayTreeMap` and `SplayTreeSet`. Splay trees are self-balancing binary search trees with the distinct characteristic that recently accessed elements are more quickly accessible again, offering O(log(n)) amortized time complexity for fundamental operations like insertion, lookup, and removal. The current stable version is 1.0.2. Its key differentiation lies in the splaying heuristic, which optimizes for temporal locality of reference, making it particularly performant for workloads with skewed access patterns. The library supports custom comparison functions and key validation predicates for flexible use with various data types, enhancing its utility beyond simple primitive comparisons.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install splaytree-ts"],"cli":null},"imports":["import { SplayTreeSet } from 'splaytree-ts';","import { SplayTreeMap } from 'splaytree-ts';"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/SBanksX/splaytree-ts","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/splaytree-ts","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import { SplayTreeSet, SplayTreeMap } from 'splaytree-ts';\n\n// Example 1: Using SplayTreeSet for numbers\nconst ages = new SplayTreeSet<number>();\nfor (const age of [33, 45, 25, 35, 59, 18, 62]) {\n  ages.add(age);\n}\n\nconsole.log('Ages in set:', Array.from(ages.values())); // [18, 25, 33, 35, 45, 59, 62]\nconsole.log('First age after 35:', ages.firstAfter(35));  // Expected: 45\nconsole.log('Last age before 33:', ages.lastBefore(33));   // Expected: 25\n\nages.delete(59);      // true\nconsole.log('Has 59 after deletion:', ages.has(59)); // false\n\n// Example 2: Using SplayTreeMap with custom comparison for objects\ninterface User { id: number; name: string; }\nconst users = new SplayTreeMap<number, User>(\n  (a, b) => a - b // Compare by user ID\n);\n\nusers.set(101, { id: 101, name: 'Alice' });\nusers.set(50, { id: 50, name: 'Bob' });\nusers.set(200, { id: 200, name: 'Charlie' });\n\nconsole.log('User with ID 50:', users.get(50)); // { id: 50, name: 'Bob' }","lang":"typescript","description":"Demonstrates basic usage of SplayTreeSet for number operations and SplayTreeMap with a custom comparison function for object keys.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}