#include <cmt_map.h>
Collaboration diagram for cmt_node< K, T >:
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_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 |
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.
|
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().
|
|
Destructor.
Definition at line 44 of file cmt_map.h.
00045 { 00046 clear (); 00047 } |
|
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 } |
|
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().
|
|
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.
|
|
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 } |
|
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 } |
|
|
|
|
|
|
|
|