Main Page ? Class Hierarchy ? Compound List ? File List ? Compound Members ? File Members ?

cmt_node< K, T > Class Template Reference

class cmt_node More...

#include <cmt_map.h>

Inheritance diagram for cmt_node< K, T >:

[legend]
Collaboration diagram for cmt_node< K, T >:

[legend]
List of all members.

Public Methods

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

Detailed Description

template
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 19 of file cmt_map.h.


Constructor & Destructor Documentation

template
cmt_node< K, T >::cmt_node (? const K &? ? key,
T &? ? t
)? [inline]
?

Required constructor.

Provides the key and the value.

Definition at line 27 of file cmt_map.h.

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

00027                                 : 
00028     m_left (0),
00029     m_key (key),
00030     m_t (&t),
00031     m_right (0)
00032   {
00033   }

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

Destructor.

Definition at line 38 of file cmt_map.h.

00039   {
00040     clear ();
00041   }

Member Function Documentation

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

Add an item.

Definition at line 65 of file cmt_map.h.

00066   {
00067     if (key < m_key)
00068       { 
00069         if (m_left == 0)
00070           {
00071             m_left = new cmt_node (key, t);
00072           }
00073         else
00074           {
00075             m_left->add (key, t);
00076           }
00077       }
00078     else if (key > m_key)
00079       { 
00080         if (m_right == 0)
00081           {
00082             m_right = new cmt_node (key, t);
00083           }
00084         else
00085           {
00086             m_right->add (key, t);
00087           }
00088       }
00089     else
00090       {
00091         m_t = &t;
00092       }
00093   }

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

Recursive clear operation.

Will delete sub-nodes

Definition at line 47 of file cmt_map.h.

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

00048   {
00049     if (m_left == 0) return;
00050 
00051     delete m_left;
00052     m_left = 0;
00053 
00054     m_t = 0;
00055 
00056     if (m_right == 0) return;
00057 
00058     delete m_right;
00059     m_right = 0;
00060   }

template
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 122 of file cmt_map.h.

00123   {
00124     if (key < m_key)
00125       { 
00126         if (m_left == 0) return (0);
00127         else return (m_left->find (key));
00128       }
00129     else if (key > m_key)
00130       { 
00131         if (m_right == 0) return (0);
00132         else return (m_right->find (key));
00133       }
00134     else
00135       {
00136         return (m_t);
00137       }
00138   }

template
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 145 of file cmt_map.h.

00146   {
00147     if (key < m_key)
00148       { 
00149         if (m_left == 0) return (0);
00150         else return (m_left->find_node (key));
00151       }
00152     else if (key > m_key)
00153       { 
00154         if (m_right == 0) return (0);
00155         else return (m_right->find_node (key));
00156       }
00157     else
00158       {
00159         return (this);
00160       }
00161   }

template
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 99 of file cmt_map.h.

00100   {
00101     if (key < m_key)
00102       { 
00103         if (m_left == 0) return (false);
00104         else return (m_left->has (key));
00105       }
00106     else if (key > m_key)
00107       { 
00108         if (m_right == 0) return (false);
00109         else return (m_right->has (key));
00110       }
00111     else
00112       {
00113         return (true);
00114       }
00115   }

Member Data Documentation

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

Definition at line 165 of file cmt_map.h.

Referenced by cmt_node< cmt_string, Package >::add(), cmt_node< cmt_string, Package >::cmt_node(), cmt_node< cmt_string, Package >::find(), cmt_node< cmt_string, Package >::find_node(), and cmt_node< cmt_string, Package >::has().

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

Definition at line 164 of file cmt_map.h.

Referenced by cmt_node< cmt_string, Package >::add(), cmt_node< cmt_string, Package >::clear(), cmt_node< cmt_string, Package >::cmt_node(), cmt_node< cmt_string, Package >::find(), cmt_node< cmt_string, Package >::find_node(), and cmt_node< cmt_string, Package >::has().

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

Definition at line 167 of file cmt_map.h.

Referenced by cmt_node< cmt_string, Package >::add(), cmt_node< cmt_string, Package >::clear(), cmt_node< cmt_string, Package >::cmt_node(), cmt_node< cmt_string, Package >::find(), cmt_node< cmt_string, Package >::find_node(), and cmt_node< cmt_string, Package >::has().

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

Definition at line 166 of file cmt_map.h.

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


The documentation for this class was generated from the following file:
Generated on Thu Jul 1 15:26:34 2004 for CMT by 1.2.18