-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollector.concrete.cpp
72 lines (55 loc) · 1.67 KB
/
collector.concrete.cpp
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
//Modified: Wed 26 Apr 2017 18:09:06 BST
//Author: Jonas R. Glesaaen ([email protected])
#include"collector.concrete.hpp"
#include<utility>
#include"pm.config.h"
#include"pm.paths.h"
#include"std_libs/position/position_compare.hpp"
namespace hop {
void TermCollector::configCollector(PMConfig * object)
{
current_config_prefactor = object->get_prefactor();
}
void TermCollector::pathCollector(PMPath * object)
{
for(WilsonString & w_term : object->w) {
w_term.prefactor *= current_config_prefactor;
auto lower = std::lower_bound(
terms.begin(), terms.end(),
w_term, StrictWilsonStringComparator() );
if( (lower == terms.end()) or StrictWilsonStringComparator::Compare(w_term,*lower) ) {
terms.insert(lower, std::move(w_term) );
} else {
lower->prefactor += w_term.prefactor;
if(lower->prefactor == 0)
terms.erase(lower);
}
}
}
void TermCollector::fetchResults(std::list<WilsonString> & res)
{
res.splice(res.end(), std::move(terms));
}
bool StrictWilsonStringComparator::Compare(
const WilsonString & lhs,
const WilsonString & rhs)
{
if (lhs.number_of_traces != rhs.number_of_traces)
return lhs.number_of_traces < rhs.number_of_traces;
return std::lexicographical_compare(
lhs.wilsons.begin(), lhs.wilsons.end(),
rhs.wilsons.begin(), rhs.wilsons.end(),
StrictWilsonComparator());
};
bool StrictWilsonComparator::Compare(
const Wilson & lhs,
const Wilson & rhs)
{
if(lhs.n != rhs.n)
return lhs.n < rhs.n;
else if(lhs.m != rhs.m)
return lhs.m < rhs.m;
return lhs.pos < rhs.pos;
//return Position::StrictCompare::Compare(lhs.pos,rhs.pos);
};
} //Namespace hop