Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@datastructures-js/avl-tree
Advanced tools
node's data type: string, number.
const avlTree = require('@datastructures-js/avl-tree');
const avl = avlTree();
.node(value, parent, left, right)
creates a binary tree node with height property.
const n = avl.node('test');
console.log(n.getValue()); // test
console.log(n.getParent()); // null
console.log(n.getLeft()); // null
console.log(n.getRight()); // null
console.log(n.getHeight()); // 1
.insert(value)
inserts a value into the tree and maintains the tree balance by rotating the imbalanced node.
avl.insert(20);
avl.insert(30);
avl.insert(40);
avl.insert(50);
avl.insert(60);
avl.insert(70);
avl.insert(80);
.root()
gets the root node
console.log(avl.root().getValue()); // 50
.min()
finds the min value node (most left).
console.log(avl.min().getValue()); // 20
.max()
finds the min value node (most right).
console.log(avl.max().getValue()); // 80
.count()
gets nodes count.
console.log(avl.count()); // 7
.find(value)
finds the value's node or returns null if not found.
let n = avl.find(30);
console.log(n.getValue()); // 30
console.log(n.getRight().getValue()); // 40
console.log(n.getLeft().getValue()); // 20
console.log(n.getHeight()); // 2
.traverseInOrder(cb)
// in-order traverse (left-parent-right)
avl.traverseInOrder(node => console.log(node.getValue()));
// 20
// 30
// 40
// 50
// 60
// 70
// 80
.traversePreOrder(cb)
// pre-order traverse (parent-left-right)
avl.traversePreOrder(node => console.log(node.getValue()));
// 50
// 30
// 20
// 40
// 70
// 60
// 80
.traversePostOrder(cb)
// post-order traverse (left-right-parent)
avl.traverse(node => console.log(node.getValue()));
// 20
// 40
// 30
// 60
// 80
// 70
// 50
.traverse(cb, order)
traverse the tree in the defined order and apply a callback on each node.
order values: inOrder
, preOrder
OR postOrder
. default is inOrder
avl.traverse(node => console.log(node.getValue())); // in-order
// 20
// 30
// 40
// 50
// 60
// 70
// 80
avl.traverse(node => console.log(node.getValue()), 'preOrder');
// 50
// 30
// 20
// 40
// 70
// 60
// 80
.remove(value)
removes a value's node (if exists) from the tree and maintains the tree balance by rotating the imbalanced node.
console.log(bst.find(30).getValue()); // 30
bst.remove(30);
console.log(bst.find(30)); // null
.clear()
clears the tree.
avl.clear();
console.log(avl.count()); // 0
grunt build
The MIT License. Full License is here
FAQs
avl tree implementation in javascript
The npm package @datastructures-js/avl-tree receives a total of 5 weekly downloads. As such, @datastructures-js/avl-tree popularity was classified as not popular.
We found that @datastructures-js/avl-tree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.