mourner / kdbush

A fast static index for 2D points
ISC License
637 stars 69 forks source link

more documentation #14

Closed turtleDev closed 6 years ago

turtleDev commented 7 years ago

Hi !

Can you please document the tree-building process, as well as search and range queries? especially the select process.

mourner commented 7 years ago

What kind of documentation would you want to see? More comments in the code? Or a section in the readme with a high-level description of the algorithms?

turtleDev commented 7 years ago

A little bit of both. Things like how dataset is arranged (are data points only kept in node leaves vs data points in internal nodes?), how the tree is stored, and some general insights into design of your implementation.

mourner commented 7 years ago

I see, thanks! I'll try to add a bit of both. The main concept here is that the data is stored flat — it's a sorted array where median splits items into two halfs horizontally, then medians of both halfs split it into quarters vertically, etc. This makes it very fast, but also static.

turtleDev commented 7 years ago

do you think query performance would take a hit, if instead of using an array, you used an object based tree ?

mourner commented 7 years ago

Yes, both query performance and initial indexing would take much longer (judging by speedup compared to RBush, which is tree-based). V8 is really fast when it comes to working with arrays of numbers.

hsnetzer commented 7 years ago

I'd also appreciate a few comments in the code! I'm interested in porting to Swift...

hsnetzer commented 6 years ago

To shed light on the original question, the select function is basically doing Quicksort.

mourner commented 6 years ago

@hsnetzer it's related to quicksort, but does a different thing: https://en.wikipedia.org/wiki/Quickselect