Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
A ridiculously lean B-tree of variable orders in plain JavaScript. Closure-compiled using advanced optimizations, 100% typed code.
npm install btreejs
var btree = require("btreejs");
var Tree = btree.create(2, btree.numcmp);
var tree = new Tree();
tree.put(0, "null");
tree.put(1, "one");
tree.put(2, "two");
tree.del(1);
tree.get(2); // == "two"
...
Creates and returns a Tree class of the specified order with the specified comparator.
Parameter | Function |
---|---|
order | Order of the Tree-class to build as a number. Defaults to 2 . |
compare | function(a: *, b: *):number returning -1 if a<b, 1 if a>b and 0 otherwise. Defaults to btree.numcmp |
Numeric comparator.
Strict string comparator that compares strings character by character.
Constructs a Tree instance of the order specified to btree.create
previously.
Puts a non-undefined, non-null key with the given non-undefined value into the tree. You have to type check keys on your own.
Gets the value of the specified key. Returns undefined
if the key does not exist. There is no Tree#exists method or
similar because it just would encourage multiple lookups if one is already sufficient. So the correct usage is:
var value = tree.get(myKey);
if (typeof value == 'undefined') {
// Key does not exist
} else {
// Key exists, value may be null
}
Deletes a key from the tree. Returns true
on success or false
if there is no such key.
Walks the range [minKey, ..., maxKey] in ascending order by calling the callback for every key/value pair found.
Parameter | Function |
---|---|
minKey | Minimum key or null to start at the beginning |
maxKey | Maximum key or null to walk till the end |
callback | function(key:, value:):undefined|boolean |
To break the loop, let callback explicitly return true
.
Walks the range [minKey, ..., maxKey] in descending order by calling the callback for every key/value pair found.
Counts the number of keys in the range [minKey, ..., maxKey]. See Tree#walk
.
Note: Tree#put
, Tree#get
and Tree#del
throw an Error
only if the key is undefined
or null
or the value
is undefined
. Other methods do not throw.
The test suite contains a 100k benchmark:
Ran in node v0.10.5 on one core of an 3.40Ghz Intel Core i7-2600K working with premium DDR3 ram (I'm too lazy to look
up the exact model). To test on your own hardware, simply run npm [-g] install testjs
&& npm test
.
testjs itself is an optimized wrapper around node's native assert module.
Also includes a cluster-based (runs in a dedicated worker) optimizer in tests/optimize.js
that takes ranges of orders
to calculate the optimal order for a specific tree size:
The times
parameter specifies how many benchmarks for each order shall be run to eliminate random peeks and is
responsible for how long a test takes. Results may vary depending on the actual hardware configuration used.
Beware: The default settings that have been used to find btree's default order of 52 (orders 0 to 200, 100k items, 20
times) will take a while to process.
Apache License, Version 2.0
FAQs
A ridiculously lean B-tree of variable orders in plain JavaScript. Closure-compiled using advanced optimizations, 100% typed code.
The npm package btreejs receives a total of 22 weekly downloads. As such, btreejs popularity was classified as not popular.
We found that btreejs 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.