kdbush icon indicating copy to clipboard operation
kdbush copied to clipboard

v4.0 — Serializable KDBush

Open mourner opened this issue 5 years ago • 2 comments

Reimplements KDBush to store the whole index along with its properties in a single array buffer for easy transfer and serialization. Closes #31. Closes #25. Closes #23. cc @hydrosquall

Breaks the API to support this in the same way as Flatbush:

// old API
const index = new KDBush(points, p => p.x, p => p.y, 64, Uint32Array);

// new API
const index = new KDBush(points.length, 64, Uint32Array);
for (const {x, y} of points) index.add(x, y);
index.finish();

The new API is more verbose, but it allows creating an index without requiring to store coordinates in some intermediate point array, allowing more efficient memory use.

To do:

  • [x] New format and API
  • [x] Deserialization
  • [x] Cover new API with tests
  • [ ] Update readme

mourner avatar Mar 26 '20 22:03 mourner

Great to see this, thanks @mourner !

hydrosquall avatar Mar 27 '20 21:03 hydrosquall

Hello!

Is this new API avaible?

I am trying to build a static KDTree that I can save as a JSON. The static KDTree will then be loaded as a JSON into my site as a reference for indexing for user-defined points. This is possible? I am able to make the JSON but once I load it in I lose the .range extension. Any suggestion would be greatly appreciated :)

Cheers, Chris

cerodell avatar Jul 09 '20 17:07 cerodell