Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

guma::kdtnode Class Template Reference

#include <guma_rkdtree.h>

Inheritance diagram for guma::kdtnode::

gul::pool_object List of all members.

Public Methods

 kdtnode (const kdrec< U, V > &rec, int disc)
 kdtnode (gul::List< gul::ListNode< kdrec< U, V > > > &recs, int disc)
const V & key () const
void add_rec (const kdrec< U, V > &rec)
void update ()
void set_left (kdtnode *left)
void set_right (kdtnode *right)
void set_childs (kdtnode *left, kdtnode *right)
void unlink (kdtnode **left, kdtnode **right, gul::List< gul::ListNode< kdrec< U, V > > > &L)
 ~kdtnode ()
void height (int cur_height, int *max_height, int *avg_count, double *avg_sum)
void dump (int dim, int space)

Public Attributes

int m_disc
gul::List< gul::ListNode<
kdrec< U, V > > > 
m_recs
int m_nelems
kdtnode * m_left
kdtnode * m_right
kdtnode * m_parent

template<class U, class V>
class guma::kdtnode< U, V >


Constructor & Destructor Documentation

template<class U, class V>
guma::kdtnode< U, V >::kdtnode const kdrec< U, V > &    rec,
int    disc
[inline]
 

Definition at line 49 of file guma_rkdtree.h.

References gul::List::Append(), m_disc, and m_nelems.

Referenced by set_childs(), set_left(), set_right(), and unlink().

00050   {
00051     m_disc = disc;
00052     m_recs.Append( new gul::ListNode< kdrec<U,V> >(rec) );
00053     m_left = m_right = m_parent = 0;
00054     m_nelems = 1;
00055   }

template<class U, class V>
guma::kdtnode< U, V >::kdtnode gul::List< gul::ListNode< kdrec< U, V > > > &    recs,
int    disc
[inline]
 

Definition at line 56 of file guma_rkdtree.h.

References m_disc, and m_nelems.

00057   {
00058     m_disc = disc;
00059     m_recs = recs;
00060     m_left = m_right = m_parent = 0;
00061     m_nelems = 1;
00062   }

template<class U, class V>
guma::kdtnode< U, V >::~kdtnode   [inline]
 

Definition at line 125 of file guma_rkdtree.h.

00126   {
00127     if( m_left ) 
00128     {
00129       m_left->m_parent = 0;
00130       delete m_left;
00131     }
00132     if( m_right ) 
00133     {
00134       m_right->m_parent = 0;
00135       delete m_right;
00136     }
00137     if( m_parent )
00138     {
00139       if( m_parent->m_left == this )
00140         m_parent->m_left = 0;
00141       if( m_parent->m_right == this )
00142         m_parent->m_right = 0;
00143       m_parent->update();
00144     }
00145   }


Member Function Documentation

template<class U, class V>
void guma::kdtnode< U, V >::add_rec const kdrec< U, V > &    rec [inline]
 

Definition at line 67 of file guma_rkdtree.h.

References gul::List::Append().

00068   {
00069     m_recs.Append( new gul::ListNode< kdrec<U,V> >(rec) );
00070   }

template<class U, class V>
void guma::kdtnode< U, V >::dump int    dim,
int    space
 

Definition at line 71 of file guma_rkdtree.cpp.

References gul::List< gul::ListNode< kdrec< U, V > > >::First(), m_disc, m_left, m_nelems, m_recs, and m_right.

00072 {
00073   int i;
00074   ListNode< kdrec<U,V> > *r;
00075   
00076   for( i = 0; i < space; i++ ) cout << " ";
00077   cout << "discriminant = " << m_disc << ", number of elements = " 
00078        << m_nelems << "\n";
00079 
00080   for( i = 0; i < space; i++ ) cout << " ";
00081   cout << "records: {";
00082   for( r = m_recs.First(); r; r = r->next )
00083   {
00084     cout << "(" << r->el[0];
00085     for( i = 1; i < dim; i++ )
00086       cout << ", " << r->el[i];
00087     cout << ") ";
00088   }
00089   cout << "}\n";
00090 
00091   for( i = 0; i < space; i++ ) cout << " ";
00092   cout << "left subtree: " << (void *)m_left << "\n";
00093   if( m_left )
00094   {
00095     m_left->dump(dim,space+4);
00096   }
00097   for( i = 0; i < space; i++ ) cout << " ";
00098   cout << "right subtree: " << (void *)m_right << "\n";
00099   if( m_right )
00100   {
00101     m_right->dump(dim,space+4);
00102   }
00103 }

template<class U, class V>
void guma::kdtnode< U, V >::height int    cur_height,
int *    max_height,
int *    avg_count,
double *    avg_sum
 

Definition at line 46 of file guma_rkdtree.cpp.

References m_left, m_parent, and m_right.

00048 {
00049   (*avg_count)++;
00050   (*avg_sum) += (double)cur_height;
00051 
00052   if( m_parent == 0 )
00053     cout << "warning: parent == 0 in node " << (void *)this
00054          << "\n";      
00055 
00056   if( !m_left && !m_right )
00057   {
00058     if( cur_height > *max_height )
00059       *max_height = cur_height;
00060   }
00061   else
00062   {
00063     if( m_left ) 
00064       m_left->height( cur_height+1, max_height, avg_count, avg_sum );
00065     if( m_right ) 
00066       m_right->height( cur_height+1, max_height, avg_count, avg_sum );
00067   }
00068 } 

template<class U, class V>
const V& guma::kdtnode< U, V >::key   const [inline]
 

Definition at line 63 of file guma_rkdtree.h.

References gul::List::First(), and m_disc.

00064   {
00065     return m_recs.First()->el[m_disc];
00066   }

template<class U, class V>
void guma::kdtnode< U, V >::set_childs kdtnode< U, V > *    left,
kdtnode< U, V > *    right
[inline]
 

Definition at line 90 of file guma_rkdtree.h.

References kdtnode(), and update().

00091   {
00092     m_left = left;
00093     if( m_left ) m_left->m_parent = this;
00094     m_right = right;
00095     if( m_right ) m_right->m_parent = this;
00096     update();
00097   }

template<class U, class V>
void guma::kdtnode< U, V >::set_left kdtnode< U, V > *    left [inline]
 

Definition at line 78 of file guma_rkdtree.h.

References kdtnode(), and update().

00079   {
00080     m_left = left;
00081     if( m_left ) m_left->m_parent = this;
00082     update();
00083   }

template<class U, class V>
void guma::kdtnode< U, V >::set_right kdtnode< U, V > *    right [inline]
 

Definition at line 84 of file guma_rkdtree.h.

References kdtnode(), and update().

00085   {
00086     m_right = right;
00087     if( m_right ) m_right->m_parent = this;
00088     update();
00089   }

template<class U, class V>
void guma::kdtnode< U, V >::unlink kdtnode< U, V > **    left,
kdtnode< U, V > **    right,
gul::List< gul::ListNode< kdrec< U, V > > > &    L
[inline]
 

Definition at line 98 of file guma_rkdtree.h.

References kdtnode().

00100   {
00101     L += m_recs;
00102 
00103     *left = m_left;   
00104     if( m_left ) 
00105     {
00106       m_left->m_parent = 0;
00107       m_left = 0;
00108     }
00109     *right = m_right;   
00110     if( m_right ) 
00111     {
00112       m_right->m_parent = 0;
00113       m_right = 0;
00114     }
00115     if( m_parent )
00116     {
00117       if( m_parent->m_left == this )
00118         m_parent->m_left = 0;
00119       if( m_parent->m_right == this )
00120         m_parent->m_right = 0;
00121       m_parent->update();
00122       m_parent = 0;
00123     }
00124   }

template<class U, class V>
void guma::kdtnode< U, V >::update   [inline]
 

Definition at line 71 of file guma_rkdtree.h.

References m_nelems.

Referenced by set_childs(), set_left(), and set_right().

00072   {
00073     m_nelems = 1;
00074     if( m_left ) m_nelems += m_left->m_nelems;
00075     if( m_right ) m_nelems += m_right->m_nelems;
00076     if( m_parent ) m_parent->update();
00077   }


Member Data Documentation

template<class U, class V>
int guma::kdtnode::m_disc
 

Definition at line 41 of file guma_rkdtree.h.

Referenced by dump(), kdtnode(), and key().

template<class U, class V>
kdtnode* guma::kdtnode::m_left
 

Definition at line 45 of file guma_rkdtree.h.

Referenced by dump(), and height().

template<class U, class V>
int guma::kdtnode::m_nelems
 

Definition at line 43 of file guma_rkdtree.h.

Referenced by dump(), kdtnode(), and update().

template<class U, class V>
kdtnode* guma::kdtnode::m_parent
 

Definition at line 47 of file guma_rkdtree.h.

Referenced by height().

template<class U, class V>
gul::List< gul::ListNode< kdrec<U,V> > > guma::kdtnode::m_recs
 

Definition at line 42 of file guma_rkdtree.h.

Referenced by dump().

template<class U, class V>
kdtnode* guma::kdtnode::m_right
 

Definition at line 46 of file guma_rkdtree.h.

Referenced by dump(), and height().


The documentation for this class was generated from the following files:
Generated on Mon Jan 21 04:18:03 2002 for GUL 0.6 - Geometry Utility Library by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001