Octree for fast Nearest Neighbor searches

I made a point Octree for efficient Nearest Neighbor queries. The days of comparing each coordinate in O(n) time are long gone - behold, the power of (mostly) logarithmic nearest neighbor searches!

16 Likes

Can you show what format data is supposed to be in? Referring to this:

1 Like

data can be any roblox hashable type.
Basically, if you can use it as a key for a dictionary, you can store it in the tree (includes most roblox objects).

If that doesn’t work for you, you can always try wrapping data in a table, which should be hashable (make sure to keep track of references if you need it for removal, though!)

Example code:

Octree:Insert(Vector3.new(0, 1, 0), game.Players.sayhisam1)
Octree:Insert(Vector3.new(0, 1, 0), {"some object"})
Octree:Insert(Vector3.new(0, 1, 0), "foo")

2 Likes