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

cmt_node< K, T > Class Template Reference

class cmt_node More...

#include <cmt_map.h>

Collaboration diagram for cmt_node< K, T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

 ~cmt_node ()
 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.

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_nodefind_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_node< K, T > * m_left
m_key
T * m_t
cmt_node< K, T > * m_right

Detailed Description

template<class K, class T>
class cmt_node< K, T >

class cmt_node

Implements a binary tree of T* keyed by the class K

The class K must have the < and > operators.

This is the basic constituent for the cmt_map class.

Definition at line 25 of file cmt_map.h.


Constructor & Destructor Documentation

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

Required constructor.

Provides the key and the value.

Definition at line 33 of file cmt_map.h.

Referenced by cmt_node< cmt_string, Package >::add().

00033                                 : 
00034     m_left (0),
00035     m_key (key),
00036     m_t (&t),
00037     m_right (0)
00038   {
00039   }

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

Destructor.

Definition at line 44 of file cmt_map.h.

00045   {
00046     clear ();
00047   }


Member Function Documentation

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

Add an item.

Definition at line 71 of file cmt_map.h.

00072   {
00073     if (key < m_key)
00074       { 
00075         if (m_left == 0)
00076           {
00077             m_left = new cmt_node (key, t);
00078           }
00079         else
00080           {
00081             m_left->add (key, t);
00082           }
00083       }
00084     else if (key > m_key)
00085       { 
00086         if (m_right == 0)
00087           {
00088             m_right = new cmt_node (key, t);
00089           }
00090         else
00091           {
00092             m_right->add (key, t);
00093           }
00094       }
00095     else
00096       {
00097         m_t = &t;
00098       }
00099   }

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

Recursive clear operation.

Will delete sub-nodes

Definition at line 53 of file cmt_map.h.

Referenced by cmt_node< cmt_string, Package >::~cmt_node().

00054   {
00055     if (m_left == 0) return;
00056 
00057     delete m_left;
00058     m_left = 0;
00059 
00060     m_t = 0;
00061 
00062     if (m_right == 0) return;
00063 
00064     delete m_right;
00065     m_right = 0;
00066   }

template<class K, class T>
T* cmt_node< 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 128 of file cmt_map.h.

00129   {
00130     if (key < m_key)
00131       { 
00132         if (m_left == 0) return (0);
00133         else return (m_left->find (key));
00134       }
00135     else if (key > m_key)
00136       { 
00137         if (m_right == 0) return (0);
00138         else return (m_right->find (key));
00139       }
00140     else
00141       {
00142         return (m_t);
00143       }
00144   }

template<class K, class T>
const cmt_node* cmt_node< 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 151 of file cmt_map.h.

00152   {
00153     if (key < m_key)
00154       { 
00155         if (m_left == 0) return (0);
00156         else return (m_left->find_node (key));
00157       }
00158     else if (key > m_key)
00159       { 
00160         if (m_right == 0) return (0);
00161         else return (m_right->find_node (key));
00162       }
00163     else
00164       {
00165         return (this);
00166       }
00167   }

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

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

Definition at line 105 of file cmt_map.h.

00106   {
00107     if (key < m_key)
00108       { 
00109         if (m_left == 0) return (false);
00110         else return (m_left->has (key));
00111       }
00112     else if (key > m_key)
00113       { 
00114         if (m_right == 0) return (false);
00115         else return (m_right->has (key));
00116       }
00117     else
00118       {
00119         return (true);
00120       }
00121   }


Member Data Documentation

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

Definition at line 171 of file cmt_map.h.

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

Definition at line 170 of file cmt_map.h.

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

Definition at line 173 of file cmt_map.h.

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

Definition at line 172 of file cmt_map.h.


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