File: supertree_variants_multitree.hpp

package info (click to toggle)
iqtree 2.0.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,700 kB
  • sloc: cpp: 142,571; ansic: 57,789; sh: 275; python: 242; makefile: 95
file content (72 lines) | stat: -rw-r--r-- 2,166 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef SUPERTREE_VARIANTS_MULTITREE_HPP
#define SUPERTREE_VARIANTS_MULTITREE_HPP

#include "multitree_impl.hpp"
#include "supertree_variants.hpp"

#include <memory>
#include <stack>

namespace terraces {
namespace variants {

class multitree_callback : public abstract_callback<multitree_node*> {
private:
	multitree_impl::storage_blocks<multitree_node> m_nodes;
	multitree_impl::storage_blocks<index> m_leaves;

	multitree_node* alloc_node() { return m_nodes.get(); }

	multitree_node* alloc_nodes(index num) { return m_nodes.get_range(num); }

	std::pair<index*, index*> alloc_leaves(const ranked_bitvector& leaves) {
		auto size = leaves.count();
		auto a_leaves = m_leaves.get_range(size);
		index i = 0;
		for (auto el : leaves) {
			a_leaves[i++] = el;
		}
		return {a_leaves, a_leaves + size};
	}

public:
	using return_type = multitree_node*;

	return_type base_one_leaf(index i) {
		return multitree_impl::make_single_leaf(alloc_node(), i);
	}
	return_type base_two_leaves(index i, index j) {
		return multitree_impl::make_two_leaves(alloc_node(), i, j);
	}
	return_type base_unconstrained(const ranked_bitvector& leaves) {
		return multitree_impl::make_unconstrained(alloc_node(), alloc_leaves(leaves));
	}
	return_type null_result() const { return nullptr; }

	return_type fast_return_value(const bipartitions& bip_it) {
		return multitree_impl::make_unexplored(alloc_node(), alloc_leaves(bip_it.leaves()));
	}

	return_type begin_iteration(const bipartitions& bip_it, const bitvector&,
	                            const constraints&) {
		return multitree_impl::make_alternative_array(
		        alloc_node(), alloc_nodes(bip_it.num_bip()), bip_it.leaves().count());
	}

	return_type accumulate(multitree_node* acc, multitree_node* node) {
		assert(acc->num_leaves == node->num_leaves);
		acc->num_trees += node->num_trees;
		*(acc->alternative_array.end) = *node;
		++(acc->alternative_array.end);
		return acc;
	}

	return_type combine(multitree_node* left, multitree_node* right) {
		return multitree_impl::make_inner_node(alloc_node(), left, right);
	}
};

} // namespace variants
} // namespace terraces

#endif // SUPERTREE_VARIANTS_MULTITREE_HPP