splaytreejs
v1.0.5
Published
Lightweight Splay tree javascript library for node, browser
Downloads
23
Maintainers
Readme
Splay tree
Lightweight Splay tree javascript library for node, browser
Install
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>
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