Can I build a KDTree of pointers to objects?

Eric Fowler eric.fowler at gmail.com
Tue Apr 29 06:19:18 UTC 2008


On Mon, Apr 28, 2008 at 10:32 PM, Paul Harris <paulharris at computer.org>
wrote:

>
>
> if that is the extent of your data, then it would just use copies inside
> the kdtree instead of pointers.
>
> i use pointers when i need to find an item, and then refer back to where
> it was originally in the vector... or if there was a *lot* of data in each
> point.
>

Yeh ... you could really do it either way. My application will be using some
structs that are points in space with associated data, and will be
"indexing" them for lookup not only by their x,y coordinates but also by the
other data, so I need to put them (or references to them) into several
different types of maps (hash table, kdtree, etc.) depending on how I am
looking them up.

It has long been a habit of mine, when I have an issue of this type, to
create a single datum and to reference it through pointers that I pass
around the app. As long as I am careful about who owns the memory and when
it is still "live" then everything is fine. This is not the only way to
write programs but as I said it has long been a habit of mine to avoid
duplication of data, not for reasons of conserving memory but to make the
code easier to organize. So I like to do it that way for my personal
reasons.


>
> go for it
>

I went for it, and I now have a toy app that  stuffs a kdtree with pointers
to a  "singlet" (an object storing only one  scalar datum!)  and does the
basic find stuff on it. If anyone is interested I will send it to the ng and
it can perhaps be another example. We could use more.


>
>
> no need to remove and re-add... i think it'll be ok if you simply make the
> change to the item, and then optimise.
>

I am curious to know about efficiency of reoptimisation ..  n log n, n^2,
whatever ..

Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.alioth.debian.org/pipermail/libkdtree-devel/attachments/20080428/e5957e3f/attachment.htm 


More information about the libkdtree-devel mailing list