Socket
Book a DemoInstallSign in
Socket

k-d-tree

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

k-d-tree

JavaScript k-d Tree Implementation

latest
npmnpm
Version
1.0.1
Version published
Weekly downloads
86
2.38%
Maintainers
1
Weekly downloads
 
Created
Source

NPM

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.

Installation

$ npm install k-d-tree

Methods

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

Running Tests

Install the development dependencies:

$ npm install

Then run the tests:

$ npm test

Code Coverage

Install the development dependencies:

$ npm install

Then run coverage

$ npm run coverage

View coverage reports

$ firefox coverage/lcov-report/index.html

Browser Bundle

$ npm run build

Keywords

tree

FAQs

Package last updated on 08 Jan 2016

Did you know?

Socket

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.

Install

Related posts