Commit bb997ebb authored by Bas Couwenberg's avatar Bas Couwenberg

New upstream version 2.0.2

parent a3e82dbc
bench
viz
test
.travis.yml
MIT License
Copyright (c) 2016 Vladimir Agafonkin
Permission is hereby granted, free of charge, to any person obtaining a copy
......
......@@ -19,20 +19,30 @@ Open web console to see benchmarks;
click on buttons to insert or remove items;
click to perform search under the cursor.
* [uniformly distributed random data](http://mourner.github.io/rbush/viz/viz-uniform.html)
* [randomly clustered data](http://mourner.github.io/rbush/viz/viz-cluster.html)
* [uniformly distributed random data](http://mourner.github.io/rbush/viz/viz-uniform.html)
## Install
Install with NPM (`npm install rbush`), or use CDN links for browsers:
[rbush.js](https://unpkg.com/rbush@2.0.1/rbush.js),
[rbush.min.js](https://unpkg.com/rbush@2.0.1/rbush.min.js)
## Usage
### Creating a Tree
```js
var tree = rbush(9);
var tree = rbush();
```
An optional argument to `rbush` defines the maximum number of entries in a tree node.
It drastically affects the performance, so you should adjust it
considering the type of data and search queries you perform.
`9` (used by default) is a reasonable choice for most applications.
Higher value means faster insertion and slower search, and vice versa.
```js
var tree = rbush(16);
```
### Adding Data
......@@ -65,6 +75,7 @@ which is useful when you only have a copy of the object you need removed (e.g. l
tree.remove(itemCopy, function (a, b) {
return a.id === b.id;
});
```
Remove all items:
......@@ -84,6 +95,8 @@ var tree = rbush(9, ['[0]', '[1]', '[0]', '[1]']); // accept [x, y] points
tree.insert([20, 50]);
```
If you're indexing a static list of points (you don't need to add/remove points after indexing), you should use [kdbush](https://github.com/mourner/kdbush) which performs point indexing 5-8x faster than RBush.
### Bulk-Inserting Data
Bulk-insert the given data into the tree:
......
'use strict';
module.exports = rbush;
module.exports.default = rbush;
var quickselect = require('quickselect');
......@@ -90,7 +91,7 @@ rbush.prototype = {
return this;
}
// recursively build the tree with the given data from stratch using OMT algorithm
// recursively build the tree with the given data from scratch using OMT algorithm
var node = this._build(data.slice(), 0, data.length - 1, 0);
if (!this.data.children.length) {
......
{
"name": "rbush",
"version": "2.0.1",
"version": "2.0.2",
"description": "High-performance 2D spatial index for rectangles (based on R*-tree with bulk loading and bulk insertion algorithms)",
"homepage": "https://github.com/mourner/rbush",
"repository": {
......@@ -18,24 +18,30 @@
"author": "Vladimir Agafonkin",
"license": "MIT",
"main": "index.js",
"jsdelivr": "rbush.js",
"unpkg": "rbush.js",
"devDependencies": {
"benchmark": "^2.1.0",
"browserify": "^13.0.1",
"eslint": "^2.10.2",
"eslint-config-mourner": "^2.0.1",
"benchmark": "^2.1.4",
"browserify": "^14.5.0",
"eslint": "^4.13.1",
"eslint-config-mourner": "^2.0.3",
"faucet": "0.0.1",
"istanbul": "~0.4.3",
"tape": "^4.5.1",
"uglify-js": "^2.6.4"
"istanbul": "~0.4.5",
"tape": "^4.8.0",
"uglify-js": "^3.2.2"
},
"scripts": {
"test": "eslint index.js test/test.js && node test/test.js | faucet",
"perf": "node ./debug/perf.js",
"perf": "node ./bench/perf.js",
"cov": "istanbul cover test/test.js -x test/test.js",
"build": "browserify index.js -s rbush -o rbush.js",
"build-min": "browserify index.js -s rbush | uglifyjs -c warnings=false -m > rbush.min.js",
"prepublish": "npm run build && npm run build-min"
"prepare": "npm run build && npm run build-min"
},
"files": [
"rbush.js",
"rbush.min.js"
],
"eslintConfig": {
"extends": "mourner",
"rules": {
......@@ -44,6 +50,6 @@
}
},
"dependencies": {
"quickselect": "^1.0.0"
"quickselect": "^1.0.1"
}
}
......@@ -21,8 +21,9 @@ function genData(N, M, R) {
var data = [];
for (var i = 0; i < M; i++) {
var cluster = randClusterPoint(R);
var size = Math.min(Math.ceil(N / M), N - data.length);
for (var j = 0; j < N / M; j++) {
for (var j = 0; j < size; j++) {
data.push(randClusterBox(cluster, R, 1));
}
}
......@@ -44,6 +45,8 @@ function genInsertOneByOne(K, M) {
}
console.timeEnd('insert ' + K + ' items');
data = data.concat(data2);
draw();
};
}
......
......@@ -13,7 +13,7 @@
<script src="viz.js"></script>
<script>
var N = 50000;
var N = 100000;
function genData(N) {
var data = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment