
Product
Introducing Custom Pull Request Alert Comment Headers
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
A basic but super fast JavaScript implementation of the k-dimensional tree data structure.
In computer science, a k-d tree (short for k-dimensional tree) is a space-partitioning data structure for organizing points in a k-dimensional space. k-d trees are a useful data structure for several applications, such as searches involving a multidimensional search key (e.g. range searches and nearest neighbor searches). k-d trees are a special case of binary space partitioning trees.
$ npm install k-d-tree
constructor(points, metric)
Create a new tree
Parameters
points: Array, GeoJSON points
metric: function, a distance function
nearest(point, maxNodes, maxDistance)
Query the nearest maxNodes neighbors to a point
Parameters
point: object, GeoJSON point
maxNodes: number, maximum amount of elements to return
maxDistance: number, optional maximal search distance
Returns
Array, Elements with two components: the searched point and the distance to it
insert(point)
Insert a new point into the tree
Parameters
point: object, GeoJSON point
Returns
Node, reference to inserted Node instance
remove(point)
Remove a point from the tree by reference
Parameters
point: object, GeoJSON point
Returns
Node, reference to removed Node instance
balanceFactor()
Get an approximation of how unbalanced the tree is
Returns
number, The higher this number, the worse query performance will be. It indicates how many times worse it is than the optimal tree. Minimum is 1. Unreliable for small trees.
toJSON()
Convert tree to a JSON serializable structure
Returns
object, JSON representation of the k-d tree
Install the development dependencies:
$ npm install
Then run the tests:
$ npm test
Install the development dependencies:
$ npm install
Then run coverage
$ npm run coverage
View coverage reports
$ firefox coverage/lcov-report/index.html
$ npm run build
FAQs
JavaScript k-d Tree Implementation
The npm package k-d-tree receives a total of 85 weekly downloads. As such, k-d-tree popularity was classified as not popular.
We found that k-d-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.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.