mirror of
https://github.com/mourner/flatbush.git
synced 2025-12-08 17:36:26 +00:00
clean up, modernize
This commit is contained in:
parent
696e156466
commit
a5ffcdc445
20
README.md
20
README.md
@ -66,8 +66,6 @@ Creates a Flatbush index that will hold a given number of items (`numItems`). Ad
|
||||
- `nodeSize`: size of the tree node (`16` by default); experiment with different values for best performance.
|
||||
- `ArrayType`: the array type used for tree storage (`Float64Array` by default);
|
||||
other types may be faster in certain cases (e.g. `Int32Array` when your data is integer).
|
||||
- `data`: if provided an array or an array buffer from a previously indexed Flatbush object (`index.data` or `index.data.buffer`),
|
||||
an index will be recreated from this data (useful for transfering indices between threads).
|
||||
|
||||
#### index.add(minX, minY, maxX, maxY)
|
||||
|
||||
@ -106,18 +104,18 @@ Very useful for transfering indices between threads or storing them in a file.
|
||||
|
||||
## Performance
|
||||
|
||||
Running `npm run bench` with Node v8.10.0:
|
||||
Running `npm run bench` with Node v10.9.0:
|
||||
|
||||
```
|
||||
1000000 rectangles
|
||||
|
||||
flatbush: 252.849ms
|
||||
1000 searches 10%: 617.473ms
|
||||
1000 searches 1%: 66.968ms
|
||||
1000 searches 0.01%: 7.818ms
|
||||
flatbush: 256.701ms
|
||||
1000 searches 10%: 584.421ms
|
||||
1000 searches 1%: 70.088ms
|
||||
1000 searches 0.01%: 6.933ms
|
||||
|
||||
rbush: 1083.758ms
|
||||
1000 searches 10%: 920.252ms
|
||||
1000 searches 1%: 173.104ms
|
||||
1000 searches 0.01%: 19.057ms
|
||||
rbush: 1273.758ms
|
||||
1000 searches 10%: 1207.384ms
|
||||
1000 searches 1%: 226.523ms
|
||||
1000 searches 0.01%: 25.242ms
|
||||
```
|
||||
|
||||
10
bench.js
10
bench.js
@ -1,11 +1,11 @@
|
||||
|
||||
const Flatbush = require('./index.js').default;
|
||||
const rbush = require('rbush');
|
||||
import Flatbush from './index.js';
|
||||
import rbush from 'rbush';
|
||||
|
||||
const N = 1000000;
|
||||
const K = 1000;
|
||||
|
||||
console.log(N + ' rectangles');
|
||||
console.log(`${N} rectangles`);
|
||||
|
||||
function addRandomBox(arr, boxSize) {
|
||||
const x = Math.random() * (100 - boxSize);
|
||||
@ -40,7 +40,7 @@ index.finish();
|
||||
console.timeEnd('flatbush');
|
||||
|
||||
function benchSearch(boxes, name) {
|
||||
const id = K + ' searches ' + name;
|
||||
const id = `${K} searches ${name}`;
|
||||
console.time(id);
|
||||
for (let i = 0; i < boxes.length; i += 4) {
|
||||
index.search(boxes[i], boxes[i + 1], boxes[i + 2], boxes[i + 3]);
|
||||
@ -76,7 +76,7 @@ function benchSearchRBush(boxes, name) {
|
||||
maxY: boxes[i + 3]
|
||||
});
|
||||
}
|
||||
const id = K + ' searches ' + name;
|
||||
const id = `${K} searches ${name}`;
|
||||
console.time(id);
|
||||
for (let i = 0; i < boxes2.length; i++) {
|
||||
rbushIndex.search(boxes2[i]);
|
||||
|
||||
4
index.js
4
index.js
@ -25,12 +25,12 @@ export default class Flatbush {
|
||||
return new Flatbush(numItems, nodeSize, ARRAY_TYPES[versionAndType & 0x0f], data);
|
||||
}
|
||||
|
||||
constructor(numItems, nodeSize, ArrayType, data) {
|
||||
constructor(numItems, nodeSize = 16, ArrayType = Float64Array, data) {
|
||||
if (numItems === undefined) throw new Error('Missing required argument: numItems.');
|
||||
if (isNaN(numItems) || numItems <= 0) throw new Error(`Unpexpected numItems value: ${numItems}.`);
|
||||
|
||||
this.numItems = +numItems;
|
||||
this.nodeSize = Math.min(Math.max(+nodeSize || 16, 2), 65535);
|
||||
this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
|
||||
|
||||
// calculate the total number of nodes in the R-tree to allocate space for
|
||||
// and the index of each tree level (used in search later)
|
||||
|
||||
21
package.json
21
package.json
@ -24,14 +24,7 @@
|
||||
"url": "git+https://github.com/mourner/flatbush.git"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "mourner",
|
||||
"parserOptions": {
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"no-var": "error",
|
||||
"prefer-const": "error"
|
||||
}
|
||||
"extends": "mourner"
|
||||
},
|
||||
"keywords": [
|
||||
"geometry",
|
||||
@ -48,13 +41,13 @@
|
||||
},
|
||||
"homepage": "https://github.com/mourner/flatbush#readme",
|
||||
"devDependencies": {
|
||||
"eslint": "^4.19.1",
|
||||
"eslint-config-mourner": "^2.0.3",
|
||||
"esm": "^3.0.30",
|
||||
"eslint": "^5.5.0",
|
||||
"eslint-config-mourner": "^3.0.0",
|
||||
"esm": "^3.0.82",
|
||||
"rbush": "^2.0.2",
|
||||
"rollup": "^0.58.2",
|
||||
"rollup": "^0.65.1",
|
||||
"rollup-plugin-buble": "^0.19.2",
|
||||
"rollup-plugin-uglify": "^3.0.0",
|
||||
"tape": "^4.9.0"
|
||||
"rollup-plugin-terser": "^2.0.2",
|
||||
"tape": "^4.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import buble from 'rollup-plugin-buble';
|
||||
import uglify from 'rollup-plugin-uglify'
|
||||
import {terser} from 'rollup-plugin-terser'
|
||||
|
||||
const output = (file, plugins) => ({
|
||||
input: 'index.js',
|
||||
@ -13,5 +13,5 @@ const output = (file, plugins) => ({
|
||||
|
||||
export default [
|
||||
output('flatbush.js', [buble()]),
|
||||
output('flatbush.min.js', [uglify(), buble()])
|
||||
output('flatbush.min.js', [terser(), buble()])
|
||||
];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user