Lightweight Splay tree javascript library for node, browser
npm i splaytreejs
node
const splayTree = require("splaytreejs")
let tree = new splayTree.SplayTree();
for (let i = 0; i < 10; i++)
tree.insert(i);
console.log(tree.keys());
tree.find(5);
console.log(tree.keys());
browser
<head>
<script src="../dist/splaytree.min.js"></script>
<script>
const {SplayTree} = splaytree;
let tree = new SplayTree();
for (let i = 0; i < 10; i++) {
tree.insert(i);
}
console.log(tree.keys());
tree.find(5);
console.log(tree.keys());
</script>
</head>
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