/usr/include/libphylo/treeIt.h is in rate4site 3.0.0-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | // $Id: treeIt.h 962 2006-11-07 15:13:34Z privmane $
#ifndef ___TREE_IT
#define ___TREE_IT
#include "definitions.h"
#include "errorMsg.h"
#include "tree.h"
class treeIterTopDown{
public:
treeIterTopDown(tree& t) : _t(t) , _current(_t.getRoot()) {
_childCheck.push_back(0);
}
tree::nodeP first() {
_childCheck.clear();
_childCheck.push_back(0);
_current = _t.getRoot();
return _t.getRoot();
}
tree::nodeP next() {
if (_childCheck.empty()) return NULL;
if (_childCheck[_childCheck.size()-1]<_current->getNumberOfSons()) {
_current = _current->getSon(_childCheck[_childCheck.size()-1]);
_childCheck[_childCheck.size()-1]++;
_childCheck.push_back(0);
}
else {
_current = _current->father();
_childCheck.pop_back();
return next();
}
return _current;
}
tree::nodeP operator++(int) {return next();}
tree::nodeP operator++() {return next();}
tree::nodeP end(){ return NULL;}
tree::nodeP operator-> (){ return _current;}
tree::TreeNode& operator* (){return *_current;}
bool operator!= (tree::nodeP t) {return (t != this->_current);}
private:
vector<int> _childCheck;
tree& _t;
tree::nodeP _current;
};
class treeIterTopDownConst{
public:
treeIterTopDownConst(const tree& t) : _t(t) , _current(_t.getRoot()) {
_childCheck.push_back(0);
}
tree::nodeP first() {
_childCheck.clear();
_childCheck.push_back(0);
_current = _t.getRoot();
return _t.getRoot();
}
tree::nodeP next() {
if (_childCheck.empty()) return NULL;
if (_childCheck[_childCheck.size()-1]<_current->getNumberOfSons()) {
_current = _current->getSon(_childCheck[_childCheck.size()-1]);
_childCheck[_childCheck.size()-1]++;
_childCheck.push_back(0);
}
else {
_current = _current->father();
_childCheck.pop_back();
return next();
}
return _current;
}
tree::nodeP operator++(int) {return next();}
tree::nodeP operator++() {return next();}
tree::nodeP end(){ return NULL;}
tree::nodeP operator-> (){ return _current;}
tree::TreeNode& operator* (){return *_current;}
bool operator!= (tree::nodeP t) {return (t != this->_current);}
private:
vector<int> _childCheck;
const tree& _t;
tree::nodeP _current;
};
class treeIterDownTopConst{
public:
treeIterDownTopConst(const tree& t) : _t(t) , _current(_t.getRoot()) {
_childCheck.push_back(0);
}
const tree::nodeP first() {
_childCheck.clear();
_childCheck.push_back(0);
_current = _t.getRoot();
return next();
}
const tree::nodeP next() {
if (_childCheck[_childCheck.size()-1]>_current->getNumberOfSons()) {//checked
_current = _current->father();
if (!_current) return NULL;
_childCheck.pop_back();
_childCheck[_childCheck.size()-1]++;
return next();
}
else if (_childCheck[_childCheck.size()-1]<_current->getNumberOfSons()) {
_current = _current->getSon(_childCheck[_childCheck.size()-1]);
_childCheck.push_back(0);
return next();
}
// else //if (_childCheck[_childCheck.size()-1]==_current->getNumberOfSons())
// {
_childCheck[_childCheck.size()-1]++;
return _current;
// }
// return next();
}
const tree::nodeP operator++(int) {return next();}
const tree::nodeP operator++() {return next();}
const tree::nodeP end(){ return NULL;}
const tree::nodeP operator-> (){ return _current;}
const tree::TreeNode& operator* (){return *_current;}
bool operator!= (tree::nodeP t) {return (t != this->_current);}
private:
vector<int> _childCheck;
const tree& _t;
tree::nodeP _current;
};
#endif
|