<br><div class="gmail_quote">On Mon, Apr 28, 2008 at 8:33 PM, Sylvain Bougerel &lt;<a href="mailto:sylvain.bougerel.devel@gmail.com">sylvain.bougerel.devel@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Sorry this comes a little late:<br>
<div class="Ih2E3d"><br>
On Fri, Apr 25, 2008 at 12:16 PM, Eric Fowler &lt;<a href="mailto:eric.fowler@gmail.com">eric.fowler@gmail.com</a>&gt; wrote:<br>
&gt; I have a toy app that is storing a set&lt;&gt; of pointers to a PlanePoint object,<br>
&gt; itself little more than a wrapper for {int x, y;}.<br>
&gt;<br>
&gt; Since I am storing pointers I want to store pointers in my KDTree too. With<br>
&gt; that in mind, I wrote this:<br>
&gt;<br></div><br>
Now, in the KD tree, as Paul explained in this mail, we use an<br>
accessor to get the data, we do not directly manipulate the element.<br>
So you need to define the accessor just as Paul told you.<br>
<br>
May be, according to your example, it will look like smth like this:<br>
<br>
struct accessor {<br>
 &nbsp; typedef int result_type;<br>
 &nbsp; int operator () (const PlanePoint *e, int k) const { return<br>
(k==0)?e-&gt;x, e-&gt;y; }<br>
};</blockquote><div><br>I had done something like this at some point and was still getting errors.But I have made progress and shall revisit it. <br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
Okay I haven&#39;t tried. Of course, as Paul says you shouldn&#39;t move your<br>
PlanePoint around in memory. But if you&#39;re using pointers in your<br>
set&lt;&gt; as well, I don&#39;t think there is a danger.<br>
</blockquote><div>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Why just not using a pointer at all? Your object is just a few `int&#39;?<br>

You will gain in performance when you need to do computation (cause it<br>
does not need to access the memory of the pointer) and you will also<br>
gain in ease with your implementation. You might consume more memory,<br>
but not necessarily, because you will not leak memory with copies of<br>
your plane object.</blockquote><div><br>Hmm, that is an idea. I was thinking of something like this: <br><br>class MyPoint<br>{<br>public: int x, y; <br><br>char * data; <br>int more_data;<br>double still_more_data;<br>bool by_now_you_get_the_idea;<br>
};<br><br>...and did not want to duplicate all that stuff in the kdtree, especially since I had reasons for storing the structs elsewhere (need to lookup on different criteria, effectively a different index). <br><br>So I could just use the x,y, and a pointer to the MyPoint in a new struct that is made just for KDTree-ability, and store and search over them. This is a little redundant but the coding is simpler and memory-wise only a little more costly. <br>
<br>But I think I will try to make the pointers work, mainly because that sort of thing is my style, and I am getting too old to change =-)<br>&nbsp;<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
Also there is one side effect that Paul did not mention: you cannot<br>
change the coordinate of your PlanePoint once they are inside the<br>
tree. It&#39;s easy to overlook this with pointers because it can be done.<br>
But you would completely invalidate your tree. You would not get<br>
memory corruption, but it will just return weird results when you send<br>
a query.</blockquote><div>Yes, I intend to be cautious. I understand the procedure is: (1) remove point from KDTree; (2) change coordinates; (3) re-insert into KDTree; (4) optimiZe() the tree.&nbsp; <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
<br>
I recommend against the use of pointers. It does not mean that<br>
libkdtree should not support it. But it&#39;s generally a bad idea.<br>
<font color="#888888"><br>
Sylvain<br>
</font></blockquote></div><br>