[688] | 1 | #ifndef __TREE_HPP__ |
---|
| 2 | #define __TREE_HPP__ |
---|
| 3 | //#include <list> |
---|
| 4 | #include <deque> |
---|
| 5 | #include <vector> |
---|
| 6 | #include "elt.hpp" |
---|
| 7 | #include "node.hpp" |
---|
| 8 | |
---|
| 9 | namespace sphereRemap { |
---|
| 10 | |
---|
| 11 | using namespace std; |
---|
[923] | 12 | extern const int MAX_LEVEL_SIZE ; |
---|
[688] | 13 | |
---|
| 14 | class CBasicTree |
---|
| 15 | { |
---|
| 16 | public: |
---|
| 17 | |
---|
| 18 | NodePtr root; /* The main tree is stored as Nodes which can be reached through traversal starting here */ |
---|
| 19 | NodePtr ref; // FIXME this reference, set by a node is odd, try to remove |
---|
| 20 | int ri; /** this is set to one by a node in case of reinsertion */ |
---|
| 21 | vector<int> levelSize; /** e.g. levelSize[0] == leafs.size() */ |
---|
| 22 | vector<Node> leafs; /** leafs are stored in vector for easy access and rest of the tree nodes as separate allocations, only reachable through tree traversal */ |
---|
| 23 | |
---|
[923] | 24 | CBasicTree() : ri(0), levelSize(MAX_LEVEL_SIZE), root(NULL), isAssignedLevel(false), okSplit(true), isActiveOkSplit(false) {} |
---|
[688] | 25 | ~CBasicTree(); |
---|
| 26 | void build(vector<Node>& nodes); |
---|
| 27 | void slim(int nbIts = 1); |
---|
| 28 | virtual void insertNodes(vector<Node>& node) = 0; |
---|
| 29 | |
---|
| 30 | void routeNodes(vector<int>& route, vector<Node>& nodes, int assignLevel); |
---|
| 31 | void routeIntersections(vector<vector<int> >& route, vector<Node>& nodes); |
---|
| 32 | |
---|
| 33 | void push_back(NodePtr node); |
---|
| 34 | void push_front(NodePtr node); |
---|
| 35 | void increaseLevelSize(int level); |
---|
| 36 | void decreaseLevelSize(int level); |
---|
| 37 | void newRoot(int level); |
---|
| 38 | void insertNode(NodePtr node); |
---|
| 39 | void output(ostream& flux, int level) ; |
---|
| 40 | |
---|
[923] | 41 | int keepNodes; |
---|
| 42 | bool isAssignedLevel ; |
---|
| 43 | int assignLevel; |
---|
| 44 | bool isActiveOkSplit ; |
---|
| 45 | bool canSplit(void) |
---|
| 46 | { |
---|
| 47 | if (isActiveOkSplit && levelSize[assignLevel] >= keepNodes ) okSplit=false ; |
---|
| 48 | return okSplit ; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
[688] | 52 | private: |
---|
| 53 | deque<NodePtr > pool; |
---|
[923] | 54 | |
---|
| 55 | bool okSplit ; |
---|
| 56 | |
---|
| 57 | protected: |
---|
| 58 | void emptyPool(); |
---|
| 59 | CBasicTree(int keepNodes_, int assignLevel_) : ri(0), levelSize(MAX_LEVEL_SIZE), root(NULL), keepNodes(keepNodes_), assignLevel(assignLevel_), isAssignedLevel(true), okSplit(true), isActiveOkSplit(false) {} |
---|
[688] | 60 | }; |
---|
| 61 | |
---|
| 62 | class CTree : public CBasicTree |
---|
| 63 | { |
---|
| 64 | public: |
---|
| 65 | void insertNodes(vector<Node>& nodes); |
---|
| 66 | }; |
---|
| 67 | |
---|
| 68 | class CSampleTree : public CBasicTree |
---|
| 69 | { |
---|
[923] | 70 | |
---|
[688] | 71 | public: |
---|
[923] | 72 | CSampleTree(int keepNodes_, int assignLevel_) : CBasicTree(keepNodes_,assignLevel_) {} |
---|
| 73 | void slimAssignedLevel() ; |
---|
| 74 | void removeExtraNode(void) ; |
---|
[688] | 75 | void insertNodes(vector<Node>& nodes); |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | } |
---|
| 79 | #endif |
---|