Stable structure for 3D bounding boxes

We’ve hit a bit of a wall with Dragginz and need some help with a suitable data structure.

We have built a database system that utilise multiple B-Trees to partition data on a per-entity basis. You define your entity like this :

image

We have automatic fixture data creation, lexicographic sort keys

image

the B-Tree key is Vec<(String, Vec)> so you can nest entities (as denoted by the sk sort key line in the above schema.) This is great if you want to query a Character, their Pets, their Pets inventories etc.

We’re at the stage where we need to start storing data spatially, and then query the backend to get a list of all the 3d boxes that bound a certain point. I’ve looked at Spatial hashing (seems to be fairly complex to get right with a big world), and R-Trees but there’s no ic-stable-structures implementation for an R-Tree (not exactly low hanging fruit.)

The issue is that I can’t do range queries on compound keys because B-Trees do not work that way. Hadn’t given it much thought and found out the hard way that our design for the 3d chunk data would not scale.

Note I added indexing but that’s not working yet. That was an attempt at a possible solution, but right now I’m not sure whether we need secondary indexes.

Wondered if anybody was working on anything similar, or had advice. Thanks!

3 Likes

I could just store the boxes in a B-Tree and read them into a R-Tree as a lazy static method?

That would be fine on init, but on upgrade I guess the structure would be empty… so we’d have to have a flag like is_populated and if that’s false we read in the data.

There aren’t any upgrade hooks right? You have to do that manually?

Does using three B-Trees and then finding their intersection not scale well?

Yeah Im not sure. The issue is that everything’s generated by macros so I can’t really have more than one B-Tree for data. I’m going to hack at the rstar crate and see what happens.

Is relying on B-Trees solid enough to survive a rugpull?

I dont want to feed the obvious troll, but you do have a point. I went to the Dfinity offices in Zurich and there are no rugs. All been pulled.

5 Likes

One possible solution could be to create the bounding box plus data and store it in the BTree like usual (using the compound key).

and then populate a RefCell that contains a RTree with the bounding boxes and associated Keys

I honestly know how to fix this

You’ve not let me down in the past when it comes to advanced data structures, can you DM?

2 Likes

Everybody take like a 5 minute break. Smoke if you’ve got them. This isn’t going to be solved any time soon.

Motoko will have stable heap wasm 64 later this summer. Break out the old code. :wink:

3 Likes

Here’s the final-ish version. Go rust! Havent tested it yet, will update because I want to demonstrate our ORM before we open source it.

5 Likes