-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathconstraints.hpp
55 lines (42 loc) · 1.44 KB
/
constraints.hpp
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
#ifndef TERRACES_CONSTRAINTS_HPP
#define TERRACES_CONSTRAINTS_HPP
#include <iosfwd>
#include <tuple>
#include <vector>
#include "trees.hpp"
namespace terraces {
/**
* Represents a LCA constraint on leaves of a tree.
* It is of the form \code
* lca(left, shared) < lca(shared, right)
* where the LCA's are compared by their height in the tree.
*/
struct constraint {
index left;
index shared;
index right;
constraint(index left, index shared, index right)
: left{left}, shared{shared}, right{right} {}
bool operator==(const constraint& o) const {
return std::tie(left, shared, right) == std::tie(o.left, o.shared, o.right);
}
bool operator!=(const constraint& o) const { return !(o == *this); }
};
using constraints = std::vector<constraint>;
std::ostream& operator<<(std::ostream& s, const constraint& c);
/**
* Extracts all LCA constraints from the input trees.
* \param trees The input trees.
* \returns All LCA constraints for the input trees.
* For every inner edge, one LCA constraint based on the leftmost and rightmost descendant
* of the endpoints are is extracted.
*/
constraints compute_constraints(const std::vector<tree>& trees);
/**
* Removes duplicate constraints from the input vector
* \param in_c The input constraints.
* \returns The input constraints without duplicates and possibly reordered.
*/
index deduplicate_constraints(constraints& in_c);
} // namespace terraces
#endif // TERRACES_CONSTRAINTS_HPP