Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

cmt_vnode< K, T > Class Template Reference

#include <cmt_map.h>

Collaboration diagram for cmt_vnode< K, T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 cmt_vnode (const K &key, T &t)
 Required constructor.

 ~cmt_vnode ()
 Destructor.

void clear ()
 Recursive clear operation.

void add (const K &key, T &t)
 Add an item.

bool has (const K &key) const
 Finds whether the tree starting from this node contains this key.

const T * find (const K &key) const
 Finds in the tree starting from this node the value associated with this key Return 0 if not found.

const cmt_vnodefind_node (const K &key) const
 Finds in the tree starting from this node the node holding the value associated with this key Return 0 if not found.


Protected Attributes

cmt_vnode< K, T > * m_left
m_key
m_t
cmt_vnode< K, T > * m_right

template<class K, class T>
class cmt_vnode< K, T >


Constructor & Destructor Documentation

template<class K, class T>
cmt_vnode< K, T >::cmt_vnode const K &  key,
T &  t
[inline]
 

Required constructor.

Provides the key and the value.

Definition at line 185 of file cmt_map.h.

Referenced by cmt_vnode< cmt_string, int >::add().

00185                                  : 
00186     m_left (0),
00187     m_key (key),
00188     m_t (t),
00189     m_right (0)
00190   {
00191   }

template<class K, class T>
cmt_vnode< K, T >::~cmt_vnode  )  [inline]
 

Destructor.

Definition at line 196 of file cmt_map.h.

00197   {
00198     clear ();
00199   }


Member Function Documentation

template<class K, class T>
void cmt_vnode< K, T >::add const K &  key,
T &  t
[inline]
 

Add an item.

Definition at line 221 of file cmt_map.h.

00222   {
00223     if (key < m_key)
00224       { 
00225         if (m_left == 0)
00226           {
00227             m_left = new cmt_vnode (key, t);
00228           }
00229         else
00230           {
00231             m_left->add (key, t);
00232           }
00233       }
00234     else if (key > m_key)
00235       { 
00236         if (m_right == 0)
00237           {
00238             m_right = new cmt_vnode (key, t);
00239           }
00240         else
00241           {
00242             m_right->add (key, t);
00243           }
00244       }
00245     else
00246       {
00247         m_t = t;
00248       }
00249   }

template<class K, class T>
void cmt_vnode< K, T >::clear  )  [inline]
 

Recursive clear operation.

Will delete sub-nodes

Definition at line 205 of file cmt_map.h.

Referenced by cmt_vnode< cmt_string, int >::~cmt_vnode().

00206   {
00207     if (m_left == 0) return;
00208 
00209     delete m_left;
00210     m_left = 0;
00211 
00212     if (m_right == 0) return;
00213 
00214     delete m_right;
00215     m_right = 0;
00216   }

template<class K, class T>
const T* cmt_vnode< K, T >::find const K &  key  )  const [inline]
 

Finds in the tree starting from this node the value associated with this key Return 0 if not found.

Definition at line 278 of file cmt_map.h.

00279   {
00280     if (key < m_key)
00281       { 
00282         if (m_left == 0) return (0);
00283         else return (m_left->find (key));
00284       }
00285     else if (key > m_key)
00286       { 
00287         if (m_right == 0) return (0);
00288         else return (m_right->find (key));
00289       }
00290     else
00291       {
00292         return (&m_t);
00293       }
00294   }

template<class K, class T>
const cmt_vnode* cmt_vnode< K, T >::find_node const K &  key  )  const [inline]
 

Finds in the tree starting from this node the node holding the value associated with this key Return 0 if not found.

Definition at line 301 of file cmt_map.h.

00302   {
00303     if (key < m_key)
00304       { 
00305         if (m_left == 0) return (0);
00306         else return (m_left->find_node (key));
00307       }
00308     else if (key > m_key)
00309       { 
00310         if (m_right == 0) return (0);
00311         else return (m_right->find_node (key));
00312       }
00313     else
00314       {
00315         return (this);
00316       }
00317   }

template<class K, class T>
bool cmt_vnode< K, T >::has const K &  key  )  const [inline]
 

Finds whether the tree starting from this node contains this key.

Definition at line 255 of file cmt_map.h.

00256   {
00257     if (key < m_key)
00258       { 
00259         if (m_left == 0) return (false);
00260         else return (m_left->has (key));
00261       }
00262     else if (key > m_key)
00263       { 
00264         if (m_right == 0) return (false);
00265         else return (m_right->has (key));
00266       }
00267     else
00268       {
00269         return (true);
00270       }
00271   }


Member Data Documentation

template<class K, class T>
K cmt_vnode< K, T >::m_key [protected]
 

Definition at line 321 of file cmt_map.h.

template<class K, class T>
cmt_vnode<K,T>* cmt_vnode< K, T >::m_left [protected]
 

Definition at line 320 of file cmt_map.h.

template<class K, class T>
cmt_vnode<K,T>* cmt_vnode< K, T >::m_right [protected]
 

Definition at line 323 of file cmt_map.h.

template<class K, class T>
T cmt_vnode< K, T >::m_t [protected]
 

Definition at line 322 of file cmt_map.h.


The documentation for this class was generated from the following file:
Generated on Mon May 2 10:25:31 2005 for CMT by doxygen 1.3.5