| 1 | // ============================================================= // |
|---|
| 2 | // // |
|---|
| 3 | // File : CT_hash.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // ============================================================= // |
|---|
| 10 | |
|---|
| 11 | #include "CT_hash.hxx" |
|---|
| 12 | #include "CT_ntree.hxx" |
|---|
| 13 | #include "CT_ctree.hxx" |
|---|
| 14 | |
|---|
| 15 | #include <arb_sort.h> |
|---|
| 16 | |
|---|
| 17 | PART *PartRegistry::get_part() { |
|---|
| 18 | /*! each call to get_part() returns the next part from the sorted PART-list. |
|---|
| 19 | * build_sorted_list() has to be called once before. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | arb_assert(!sorted.empty()); // call build_sorted_list before |
|---|
| 23 | |
|---|
| 24 | PART *p = NULL; |
|---|
| 25 | if (retrieved<sorted.size()) { |
|---|
| 26 | p = sorted[retrieved++]; |
|---|
| 27 | } |
|---|
| 28 | return p; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | void PartRegistry::put_part(PART*& part) { |
|---|
| 32 | //! insert part in PartRegistry (destroys/reassigns part) |
|---|
| 33 | |
|---|
| 34 | arb_assert(sorted.empty()); // too late, already build_sorted_list |
|---|
| 35 | part->standardize(); |
|---|
| 36 | |
|---|
| 37 | PartSet::iterator found = parts.find(part); |
|---|
| 38 | |
|---|
| 39 | if (found != parts.end()) { |
|---|
| 40 | (*found)->add(part); |
|---|
| 41 | delete part; |
|---|
| 42 | } |
|---|
| 43 | else { |
|---|
| 44 | parts.insert(part); |
|---|
| 45 | } |
|---|
| 46 | part = NULL; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | inline bool insertionOrder_less(const PART *p1, const PART *p2) { |
|---|
| 50 | return p1->insertionOrder_cmp(p2)<0; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | void PartRegistry::build_sorted_list(double overall_weight) { |
|---|
| 54 | //! sort the parts into insertion order. |
|---|
| 55 | |
|---|
| 56 | arb_assert(sorted.empty()); |
|---|
| 57 | arb_assert(!parts.empty()); |
|---|
| 58 | |
|---|
| 59 | copy(parts.begin(), parts.end(), std::back_insert_iterator<PartVector>(sorted)); |
|---|
| 60 | sort(sorted.begin(), sorted.end(), insertionOrder_less); |
|---|
| 61 | parts.clear(); |
|---|
| 62 | |
|---|
| 63 | for (size_t i = 0; i<sorted.size(); ++i) { |
|---|
| 64 | PART *pi = sorted[i]; |
|---|
| 65 | pi->takeMean(overall_weight); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | arb_assert(!sorted.empty()); |
|---|
| 69 | } |
|---|