2
#include "ktransition.h"
8
template class PtrSet<KTransition>;
9
template class PtrSet<KLocation>;
11
template class PtrSetEl<KTransition>;
12
template class PtrSetEl<KLocation>;
14
template <class T> PtrSetEl<T>::PtrSetEl(T *newitem, const PtrSetEl<T> *f /* = NULL */)
17
child[0] = child[1] = NULL;
21
template <class T> PtrSetEl<T>::~PtrSetEl() {
22
if ( NULL != child[0] )
24
if ( NULL != child[1] )
30
template <class T> PtrSetEl<T>::PtrSetEl(const PtrSetEl<T> ©, const PtrSetEl<T> *f /* = NULL */)
32
item = new T(*copy.item);
33
if ( NULL == copy.child[0] )
36
child[0] = new PtrSetEl<T>(*copy.child[0], this);
37
if ( NULL == copy.child[1] )
40
child[1] = new PtrSetEl<T>(*copy.child[1], this);
44
template <class T> T *PtrSetEl<T>::search(T *key, mode notfound) {
49
if ( NULL != child[i] )
50
result = child[i]->search(key, notfound);
51
else if ( SInsert == notfound )
52
child[i] = new PtrSetEl<T>(key, this);
53
return NULL != result || i != notfound ? result : item;
56
template <class T> void PtrSetEl<T>::print(int depth) {
57
if ( NULL != child[0] )
58
child[0]->print(depth + 1);
59
printf("%*c%s:\n", depth, ':', ((string *)item)->getstr());
60
if ( NULL != child[1] )
61
child[1]->print(depth + 1);
65
/*--------------------------------------------------------------------------*/
68
template <class T> PtrSet<T>::PtrSet()
72
template <class T> PtrSet<T>::~PtrSet() {
77
template <class T> PtrSet<T>::PtrSet(const PtrSet<T> ©)
79
if ( NULL == copy.root )
80
root = (PtrSetEl<T> *) NULL;
82
root = new PtrSetEl<T>(*copy.root);
85
template <class T> T *PtrSet<T>::search(T *key, mode notfound) {
87
return root->search(key, notfound);
88
if ( SInsert == notfound )
89
root = new PtrSetEl<T>(key);
93
template <class T> bool PtrSet<T>::first(mode dir /* = SNext */) {
95
if ( NULL == current )
97
while ( NULL != current->child[dir] )
98
current = current->child[dir];
102
template <class T> bool PtrSet<T>::next(mode dir /* = SNext */) {
103
if ( NULL == current )
105
register const PtrSetEl<T> *temp = current->child[1 - dir];
106
if ( NULL != temp ) {
109
while ( NULL != (temp = temp->child[dir]) );
114
if ( NULL == (current = temp->father) )
116
} while (current->child[dir] != temp);
120
template <class T> void PtrSet<T>::print() {