source: XIOS/dev/branch_yushan_merged/extern/remap/src/tree.hpp @ 1176

Last change on this file since 1176 was 1172, checked in by yushan, 7 years ago

save dev. need to unify the file type when using EP

File size: 2.3 KB
Line 
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
9namespace sphereRemap {
10
11using namespace std;
12extern const int MAX_LEVEL_SIZE ;
13
14class 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
24  CBasicTree() : ri(0), levelSize(MAX_LEVEL_SIZE), root(NULL), isAssignedLevel(false), okSplit(true), isActiveOkSplit(false) {} 
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
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 
52  private:
53  deque<NodePtr > pool;
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), 
60                                                 okSplit(true), isActiveOkSplit(false) {} 
61};
62
63class CTree : public CBasicTree
64{
65  public:
66  void insertNodes(vector<Node>& nodes);
67};
68
69class CSampleTree : public CBasicTree
70{
71
72  public:
73  CSampleTree(int keepNodes_, int assignLevel_) : CBasicTree(keepNodes_,assignLevel_) {}
74  void slimAssignedLevel() ;
75  void removeExtraNode(void) ;
76  void insertNodes(vector<Node>& nodes);
77};
78
79}
80#endif
Note: See TracBrowser for help on using the repository browser.