ARB
CT_hash.hxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : CT_hash.hxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #ifndef CT_HASH_HXX
12 #define CT_HASH_HXX
13 
14 #ifndef CT_PART_HXX
15 #include "CT_part.hxx"
16 #endif
17 #ifndef _GLIBCXX_SET
18 #include <set>
19 #endif
20 #ifndef _GLIBCXX_VECTOR
21 #include <vector>
22 #endif
23 
24 typedef PART *PARTptr;
25 typedef std::set<PARTptr, bool (*)(const PART *, const PART *)> PartSet;
26 typedef std::vector<PARTptr> PartVector;
27 
28 inline bool topological_less(const PART *p1, const PART *p2) { return p1->topological_cmp(p2)<0; }
29 
30 class PartRegistry : virtual Noncopyable {
31  PartSet parts;
32  PartSet artificial_parts; // these occurred in no tree
33  PartVector sorted;
34  size_t retrieved;
35 
36  bool registration_phase() const { return sorted.empty(); }
37  bool retrieval_phase() const { return !registration_phase(); }
38 
39  void merge_artificial_parts();
40 
41 public:
43  : parts(topological_less),
44  artificial_parts(topological_less),
45  retrieved(0)
46  {
47  arb_assert(registration_phase());
48  }
49  ~PartRegistry();
50 
51  void put_part_from_complete_tree(PART*& part);
52  void put_part_from_partial_tree(PART*& part, const PART *partialTree);
53  void put_artificial_part(PART*& part);
54 
55  void build_sorted_list(double overall_weight);
56  PART *get_part();
57 
58  size_t size() const {
59  if (registration_phase()) return parts.size()+artificial_parts.size();
60  return sorted.size();
61  }
62 };
63 
64 #else
65 #error CT_hash.hxx included twice
66 #endif // CT_HASH_HXX
#define arb_assert(cond)
Definition: arb_assert.h:245
int topological_cmp(const PART *other) const
Definition: CT_part.cxx:338
std::set< PARTptr, bool(*)(const PART *, const PART *)> PartSet
Definition: CT_hash.hxx:25
PART * PARTptr
Definition: CT_hash.hxx:24
PART * get_part()
Definition: CT_hash.cxx:24
void build_sorted_list(double overall_weight)
Definition: CT_hash.cxx:134
std::vector< PARTptr > PartVector
Definition: CT_hash.hxx:26
void put_part_from_partial_tree(PART *&part, const PART *partialTree)
Definition: CT_hash.cxx:71
size_t size() const
Definition: CT_hash.hxx:58
Definition: CT_part.hxx:62
void put_artificial_part(PART *&part)
Definition: CT_hash.cxx:56
void put_part_from_complete_tree(PART *&part)
Definition: CT_hash.cxx:38
bool topological_less(const PART *p1, const PART *p2)
Definition: CT_hash.hxx:28