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.
bkd tree implementation using random-access storage
This module implements some of the bkd tree paper and is very fast. However, the memory usage can be high at times and some features of the paper, such as the grid bulk load algorithm, are not yet implemented.
The robustness and atomicity of these data structures has not yet been thoroughly tested.
insert 5000 points to in-memory storage then search those points for
-0.5 <= x <= -0.4 and -0.9 <= y <= -0.85
var ram = require('random-access-memory')
function storage (name, cb) { cb(null,ram()) }
var bkd = require('bkd-tree')(storage, {
branchFactor: 4,
type: {
point: [ 'float32be', 'float32be' ],
value: [ 'uint32be' ]
},
compare: function (a, b) { return a.value[0] === b.value[0] }
})
var N = 5000
var batch = []
for (var i = 0; i < N; i++) {
var x = Math.random()*2-1
var y = Math.random()*2-1
batch.push({ type: 'insert', point: [x,y], value: [i+1] })
}
var bbox = [-0.5,-0.9,-0.4,-0.85]
bkd.batch(batch, function (err) {
if (err) console.error(err)
bkd.query(bbox, function (err, values) {
if (err) console.error(err)
else console.log(values)
})
})
output:
[ { point: [ -0.4952811002731323, -0.8651710152626038 ],
value: [ 1404 ] },
{ point: [ -0.46114417910575867, -0.8699662089347839 ],
value: [ 300 ] },
{ point: [ -0.4253665506839752, -0.8783734440803528 ],
value: [ 1869 ] },
{ point: [ -0.41438907384872437, -0.8694494962692261 ],
value: [ 3807 ] } ]
var BKD = require('bkd-tree')
Create a new bkd
instance from a random-access storage
instance and:
opts.type.point
- array of type strings for the coordinatesopts.type.value
- array of type strings for the data payloadopts.branchFactor
- branch factor. default: 4opts.levels
- number of levels in the smallest tree. default: 5opts.compare(a,b)
- boolean comparison function required for deletesThe dimensionality of the coordinates should match the length of the
opts.type.value
length.
The type strings listed in opts.type.point
and opts.type.value
can be:
Any of these types can have a [n]
quantity at the end. When n > 1
, the
corresponding value for the type will be a typed array except for uint8 which is
a Buffer
(which is also a Uint8Array).
Write or remove documents from an array of rows
. Each row
in the rows
array should have:
row.type
- 'delete'
or 'insert'
row.point
- coordinate arrayrow.value
- array of value typesSearch for records inside a bounding box bbox
.
Obtain the results with the returned pull-stream stream
or from
cb(err, results)
to get an array of results.
The bbox
should contain all the minimum values for each dimension followed by
all the maximum values for each dimension. In 2d, the bbox is
[minX,minY,maxX,maxY]
, or the more familiar [west,south,east,north]
.
Values exactly on the border are included in the results.
npm install bkd-tree
BSD
FAQs
[bkd tree][bkd] implementation using [random-access][] storage
The npm package bkd-tree receives a total of 2 weekly downloads. As such, bkd-tree popularity was classified as not popular.
We found that bkd-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.