sdd / kiddo

Kiddo
Apache License 2.0
87 stars 14 forks source link

WASM Compatible? #43

Closed DawChihLiou closed 1 year ago

DawChihLiou commented 1 year ago

Hi @sdd, thanks for the library. It looks great! I'm wondering if your k-d tree is serializable and deserializable. I would like to use it for portable targets like WebAssembly. Any thought would be great. Thanks so much!

cavemanloverboy commented 1 year ago

It supports serde and rkyv ser/de functionality. The rkyv FAQ mentions they test mainly x86 and wasm:

Is rkyv cross-platform?

Yes, but rkyv has been tested mostly on x86 machines and wasm. There may be bugs that need to get fixed for other architectures.

So, should def be possible.

sdd commented 1 year ago

Hi @DawChihLiou! Thanks for the kind words. 😄

To add a bit more to @cavemanloverboy's comment above, there are also two examples in the examples folder that you might find helpful. They are not WASM specific, but they do show how to do serialization / deserialization with both serde and rkyv.

https://github.com/sdd/kiddo/blob/master/examples/rkyv.rs https://github.com/sdd/kiddo/blob/master/examples/serde.rs

Hope this helps. If you do use Kiddo with WASM, I'd love to have an example that we can add to show how to do that too!

Best of luck 👍🏼

DawChihLiou commented 1 year ago

Thank you both @sdd @cavemanloverboy ! I'll give it a try. I'm curious if it's possible to store data in the tree nodes instead of references. Could you point me to the documentation please? Thanks so much!

sdd commented 1 year ago

It's not possible to store data in the nodes in kiddo v2. This was possible in v1. v2 has a strong focus on query performance, and as a consequence the Leaf nodes are kept small so that as much of the tree can be kept in the CPU cache as possible. The recommended approach is to keep a separate Vec of structs containing the data associated with each item stored in the tree, and for the tree to store just an index into this Vec.

You can see an example of this in the cities.rs example.

The main Kiddo documentation can be found at https://docs.rs/kiddo/latest/kiddo/.