<p>There are many similar code constructs are found in this file<br>
For example...<br>
<code><br>
if (kdTreeNS)<br>
    delete kdTreeNS;<br>
  if (coverTreeNS)<br>
    delete coverTreeNS;<br>
  if (rTreeNS)<br>
    delete rTreeNS;<br>
  if (rStarTreeNS)<br>
    delete rStarTreeNS;<br>
  if (ballTreeNS)<br>
    delete ballTreeNS;<br>
  if (xTreeNS)<br>
    delete xTreeNS;<br>
</code><br>
is similar to ...</p>

<p><code><br>
if (kdTreeNS)<br>
    return kdTreeNS-&gt;ReferenceSet();<br>
  else if (coverTreeNS)<br>
    return coverTreeNS-&gt;ReferenceSet();<br>
  else if (rTreeNS)<br>
    return rTreeNS-&gt;ReferenceSet();<br>
  else if (rStarTreeNS)<br>
    return rStarTreeNS-&gt;ReferenceSet();<br>
  else if (ballTreeNS)<br>
    return ballTreeNS-&gt;ReferenceSet();<br>
  else if (xTreeNS)<br>
    return xTreeNS-&gt;ReferenceSet();<br>
</code></p>

<p>I think it would be better to implement this using inheritance as we are doing the exact same thing that a compiler does but just with if-else clauses. (strictly having faith in people who optimizes compilers.). We can create an interface which is inherited by NSType templatized class and implement a getAppropriateTreePointer() which an interface pointer. (we should find better names). </p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/mlpack/mlpack/issues/674">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe/AJ4bFHKpO9MQxAcpY7cxxzLUSIXhvCLcks5qII4-gaJpZM4It4UX">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFM8Y93fiky8enLUII1BEjqv2FBnkks5qII4-gaJpZM4It4UX.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/issues/674"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>