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: |
---|
42 | PartRegistry() |
---|
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, const TreeNode *node); |
---|
52 | void put_part_from_partial_tree(PART*& part, const PART *partialTree, const TreeNode *node); |
---|
53 | void put_artificial_part(PART*& part); |
---|
54 | |
---|
55 | void build_sorted_list(double overall_weight); |
---|
56 | PART *get_part(); |
---|
57 | const PART *peek_part(int idx) const; |
---|
58 | |
---|
59 | size_t size() const { |
---|
60 | if (registration_phase()) return parts.size()+artificial_parts.size(); |
---|
61 | return sorted.size(); |
---|
62 | } |
---|
63 | }; |
---|
64 | |
---|
65 | #else |
---|
66 | #error CT_hash.hxx included twice |
---|
67 | #endif // CT_HASH_HXX |
---|