-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext_alignment.hh
56 lines (51 loc) · 1.45 KB
/
ext_alignment.hh
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
#ifndef EXT_ALIGNMENT_HH
#define EXT_ALIGNMENT_HH
inline uint32_t hashable_value(const typ_ali& candidate) {
Rope concat;
append(concat, candidate.first);
append(concat, candidate.second);
return hashable_value(concat);
}
inline bool operator==(const typ_ali& a, const typ_ali& b) {
return (a.first == b.first) && (a.second == b.second);
}
// a function that realizes the Trace representation of an alignment,
// i.e. Ins, Ins, Del becomes Del, Ins, Ins
// We assume that Del is abbreviated as 'D' and Ins as 'I' in the calling algebra
template<typename X>
inline Rope trace_pushback(char a, const rope::Ref<X> &x) {
rope::Ref<X> &constx = const_cast<rope::Ref<X>&>(x);
typename rope::Ref<X>::iterator it = constx.begin();
Rope res;
if (a == 'I') {
unsigned int i = 0;
for (i = 0; i < x.size(); ++i) {
if (((char) *it) == 'D') {
append(res, (char) *it);
++it;
} else {
break;
}
}
append(res, a);
for (unsigned int j = i+1; j <= x.size(); ++j) {
append(res, (char) *it);
++it;
}
} else {
append(res, a);
append(res, x);
}
return res;
}
// append a "Rope" in reverse order to another "Rope"
template<typename X>
inline void append_reverse(rope::Ref<X> &str, const rope::Ref<X> &o) {
rope::Ref<X> &x = const_cast<rope::Ref<X>&>(o);
std::string rev = std::string();
for (typename rope::Ref<X>::iterator it = x.begin(); it != x.end(); ++it) {
rev.insert(0, 1, *it);
}
str.append(rev.c_str(), rev.size());
}
#endif