Lightweight Splay tree javascript library for node, browser
Install
npm i splaytreejs
node
const splayTree = let tree = ;for let i = 0; i < 10; i++ tree; console;tree;console;
browser
API
new SplayTree([duplicate=true, comparator])
, wherecomparator
is optional comparison function andduplicate
is optional allow duplicate key (default is true)tree.insert(key: any, data: any):Node
- Insert itemtree.find(key: any):Boolean
- Find item, return result, reshapes the tree so that finding node is rootedtree.remove(key: any):Boolean
- Remove item, return result, reshapes the tree so that finding node is rootedtree.findKth(k: Integer):Boolean
- Find Kth item, return result, reshapes the tree so that finding node is rootedtree.keys(order: Integer):Array<key: any>
- Get Keys by order (0: preorder, 1: inorder, 2: postorder)tree.merge(tree: SplayTree):Node
- Merge this tree and argument treetree.load(Array<key: any>, Array<data: any>, nTrees: Integer):None
- Load Array of keys and datas, if datas is null or keys.length is not equal datas.length then set default ([{} for keys.length])tree.clear():SplayTree
- Clear tree