
Security News
npm Introduces minimumReleaseAge and Bulk OIDC Configuration
npm rolls out a package release cooldown and scalable trusted publishing updates as ecosystem adoption of install safeguards grows.
bfs-tree-layout
Advanced tools
Operations on nodes for balanced binary trees stored in bfs layout. These are useful if you are building data structures, like binary search trees, implicitly (ie not storing pointers to subtrees).
BFS layout, unlike inorder layout, is much faster for performing binary searches and bounds queries. The disadvantage is that it is much slower at inorder traversal.
npm install bfs-tree-layout
Assume that the tree is filled in level order, and laid out in memory via an bfs traversal. For example:
The tree:
0
/ \
1 2
/ \ / \
3 4 5 6
/ \ |
7 8 9
With this picture in mind, here are some operations:
var layout = require("bfs-tree-layout")
console.log(layout.left(10, 3)) //Prints: 7
console.log(layout.parent(10, 4)) //Prints: 1
console.log(layout.height(10, 2)) //Prints: 1
var layout = require("bfs-tree-layout")
Conventions:
n is always the size of the treex is the index of a node in the treelayout.root(n)Returns the index of the root of a tree of size n.
layout.begin(n)Returns the index of the first node of the tree
layout.end(n)Returns the index of the last node in the tree
layout.height(n, x)Returns the height of node x in a tree of size n
layout.prev(n, x)Returns the predecessor of x in an in-order traversal
layout.next(n, x)Returns the successor of x in an in-order traversal
layout.parent(n, x)Returns the parent of x in a tree of size n
layout.left(n, x)Returns the left child of x
layout.right(n, x)Returns the right child of x
layout.leaf(n, x)Returns true if the node x is a leaf
layout.lo(n, x)Returns the left-most ancestor of x
layout.hi(n, x)Returns the right-most ancestor of x
(c) 2013 Mikola Lysenko. MIT License
FAQs
Index computations for balanced binary trees stored in BFS order
The npm package bfs-tree-layout receives a total of 8 weekly downloads. As such, bfs-tree-layout popularity was classified as not popular.
We found that bfs-tree-layout 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.

Security News
npm rolls out a package release cooldown and scalable trusted publishing updates as ecosystem adoption of install safeguards grows.

Security News
AI agents are writing more code than ever, and that's creating new supply chain risks. Feross joins the Risky Business Podcast to break down what that means for open source security.

Research
/Security News
Socket uncovered four malicious NuGet packages targeting ASP.NET apps, using a typosquatted dropper and localhost proxy to steal Identity data and backdoor apps.