Skip to content

Commit 772e42e

Browse files
authored
Merge pull request #32 from jlab/codestyle_rtlib
Thanks @kmaibach and @sgtkellox for your reviews!
2 parents 355974e + 6dc7dae commit 772e42e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5932
-6105
lines changed

rtlib/adp.hh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@
2222
}}} */
2323

2424

25-
#ifndef ADP_HH
26-
#define ADP_HH
25+
#ifndef RTLIB_ADP_HH_
26+
#define RTLIB_ADP_HH_
2727

28-
#include "empty.hh"
29-
#include "algebra.hh"
30-
#include "erase.hh"
31-
#include "list.hh"
28+
#include <algorithm>
29+
// needed for uint64_t (Integer ...)
30+
#include <boost/cstdint.hpp>
31+
32+
#include "empty.hh"
33+
#include "algebra.hh"
34+
#include "erase.hh"
35+
#include "list.hh"
3236
#include "sequence.hh"
3337
#include "string.hh"
34-
#include "table.hh"
38+
#include "table.hh"
3539
#include "terminal.hh"
3640

3741
#include "filter.hh"
@@ -52,14 +56,9 @@
5256

5357
#include "rope.hh"
5458

55-
// needed for uint64_t (Integer ...)
56-
#include <boost/cstdint.hpp>
57-
58-
#include <algorithm>
59-
6059
using std::max;
6160
using std::min;
6261

6362
typedef int nosuchtype;
6463

65-
#endif
64+
#endif // RTLIB_ADP_HH_
Lines changed: 77 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,77 @@
1-
/*
2-
* File: pareto_0_nosort_block.hh
3-
* Author: gatter
4-
*
5-
* Created on July 21, 2015, 12:33 PM
6-
*/
1+
/* {{{
72
8-
#ifndef PARETO_0_NOSORT_BLOCK_HH
9-
#define PARETO_0_NOSORT_BLOCK_HH
3+
This file is part of gapc (GAPC - Grammars, Algebras, Products - Compiler;
4+
a system to compile algebraic dynamic programming programs)
5+
6+
Copyright (C) 2008-2011 Georg Sauthoff
7+
email: gsauthof@techfak.uni-bielefeld.de or gsauthof@sdf.lonestar.org
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
* Author: gatter
22+
*
23+
* Created on July 21, 2015, 12:33 PM
24+
25+
}}} */
26+
27+
#ifndef RTLIB_ADP_SPECIALIZATION_PARETO_0_NOSORT_BLOCK_HH_
28+
#define RTLIB_ADP_SPECIALIZATION_PARETO_0_NOSORT_BLOCK_HH_
29+
30+
#include <deque>
1031

1132
#if __cplusplus >= 201103L
1233
#define _MOVE(__val) std::move(__val)
13-
#define _MOVE_RANGE(__it1,__it2,__in) std::move(__it1,__it2,__in)
34+
#define _MOVE_RANGE(__it1, __it2, __in) std::move(__it1, __it2, __in)
1435
#else
1536
#define _MOVE(__val) (__val)
16-
#define _MOVE_RANGE(__it1,__it2,__in) std::copy(__it1,__it2,__in)
37+
#define _MOVE_RANGE(__it1, __it2, __in) std::copy(__it1, __it2, __in)
1738
#endif
1839

1940

2041
template<class T>
2142
inline void mark_position(List_Ref<T> &x, List_Ref<int> &markers) {
2243
int s = x.ref().size();
23-
if (s!=0 && (markers.ref().empty() || s != markers.ref().back()) )
44+
if (s != 0 && (markers.ref().empty() || s != markers.ref().back()) )
2445
markers.ref().push_back(s);
2546
}
2647

2748

2849
// append with no sort Pareto
2950
template<class T, typename Compare>
30-
inline void join_step(List_Ref<T> &answers, typename List_Ref<T>::iterator &i_begin,
31-
typename List_Ref<T>::iterator &i_end, Compare &c, const bool keep_equal)
32-
{
33-
34-
// basic security tests
51+
inline void join_step(
52+
List_Ref<T> &answers, typename List_Ref<T>::iterator &i_begin,
53+
typename List_Ref<T>::iterator &i_end, Compare &c, const bool keep_equal) {
54+
// basic security tests
3555
if (i_begin == i_end)
3656
return;
37-
57+
3858
if (isEmpty(answers)) {
3959
_MOVE_RANGE(i_begin, i_end, std::back_inserter(answers.ref()));
4060
return;
4161
}
42-
62+
4363
// do the real work
4464
const int dim = c.dim;
45-
46-
for(typename List_Ref<T>::iterator in = i_begin; in != i_end; in++) {
47-
65+
66+
for (typename List_Ref<T>::iterator in = i_begin; in != i_end; in++) {
4867
bool add = true;
49-
for (typename List_Ref<T>::iterator answer = answers.ref().begin(); answer!=answers.ref().end(); ){
50-
51-
bool less = false;
68+
for (typename List_Ref<T>::iterator answer = answers.ref().begin();
69+
answer != answers.ref().end();) {
70+
bool less = false;
5271
bool better = false;
5372
for (int i = 1; i<= dim; ++i) {
5473
int res = c(*answer, *in, i);
55-
switch(res) {
74+
switch (res) {
5675
case 1:
5776
better = true;
5877
break;
@@ -62,71 +81,70 @@ inline void join_step(List_Ref<T> &answers, typename List_Ref<T>::iterator &i_be
6281
default:
6382
break;
6483
}
65-
84+
6685
if (better && less) {
6786
break;
6887
}
6988
}
70-
71-
if (better && less) { // no domination
89+
90+
if (better && less) { // no domination
7291
++answer;
73-
} else if (better || (!better && !less && !keep_equal) ) { // answer is always better or equal or all values equal
92+
} else if (better || (!better && !less && !keep_equal)) {
93+
// answer is always better or equal or all values equal
7494
add = false;
7595
break;
76-
} else if (less){ // less && !better
96+
} else if (less) { // less && !better
7797
// remove from answer list
7898
answer = erase_element(answers, answer);
7999
} else {
80100
++answer;
81101
}
82102
}
83-
84-
if (add == true)
85-
{
103+
104+
if (add == true) {
86105
answers.ref().push_back(_MOVE(*in));
87-
}
106+
}
88107
}
89-
90108
}
91109

92110

93111
template<class T, typename Compare>
94-
inline void join_marked_multi_to_two_all(List_Ref<T> &x, List_Ref<int> &markers, Compare &c, const bool keep_equal) {
95-
112+
inline void join_marked_multi_to_two_all(
113+
List_Ref<T> &x, List_Ref<int> &markers, Compare &c, const bool keep_equal) {
96114
std::deque<List_Ref<T> > merges;
97-
115+
98116
typename List_Ref<T>::iterator s1_start, middle, s2_end;
99-
117+
100118
typename List_Ref<int>::iterator p1 = markers.ref().begin();
101119
typename List_Ref<int>::iterator p2 = markers.ref().begin();
102120
typename List_Ref<int>::iterator x_end = markers.ref().end();
103121
p2++;
104-
122+
105123
s1_start = x.ref().begin();
106124
int start = 0;
107-
108-
for(; p2 != x_end && p1 != x_end ; p1+=2, p2+=2) {
109125

126+
for (; p2 != x_end && p1 != x_end ; p1+=2, p2+=2) {
110127
// get iterator
111128
middle = x.ref().begin();
112129
std::advance(middle, *p1);
113130

114131
s2_end = x.ref().begin();
115132
std::advance(s2_end, *p2);
116-
133+
117134
// do the actual join
118135
List_Ref<T> e;
119136
merges.push_back(e);
120-
121-
if ( (*p1-start) > (*p2 - *p1) ) { // first list longer than second
122-
123-
_MOVE_RANGE(s1_start, middle, std::back_inserter(merges.back().ref()));
137+
138+
if ( (*p1-start) > (*p2 - *p1) ) { // first list longer than second
139+
_MOVE_RANGE(s1_start, middle, std::back_inserter(
140+
merges.back().ref()));
124141
join_step(merges.back(), middle, s2_end, c, keep_equal);
125142
} else {
126-
_MOVE_RANGE(middle, s2_end, std::back_inserter(merges.back().ref()));
143+
_MOVE_RANGE(middle, s2_end, std::back_inserter(
144+
merges.back().ref()));
127145
join_step(merges.back(), s1_start, middle, c, keep_equal);
128146
}
129-
147+
130148
s1_start = s2_end;
131149
start = *p2;
132150
}
@@ -139,19 +157,17 @@ inline void join_marked_multi_to_two_all(List_Ref<T> &x, List_Ref<int> &markers,
139157
merges.push_back(e);
140158
_MOVE_RANGE(s1_start, end, std::back_inserter(merges.back().ref()));
141159
}
142-
143-
160+
161+
144162
while (merges.size() > 1) {
145-
146163
std::deque<List_Ref<T> > new_merges;
147-
164+
148165
typename List_Ref<List_Ref<T> >::iterator m1 = merges.begin();
149166
typename List_Ref<List_Ref<T> >::iterator m2 = merges.begin();
150167
typename List_Ref<List_Ref<T> >::iterator m_end = merges.end();
151168
++m2;
152-
153-
for(; m2 != m_end && m1 != m_end ; m1+=2, m2+=2) {
154169

170+
for (; m2 != m_end && m1 != m_end ; m1+=2, m2+=2) {
155171
// do the actual join
156172
typename List_Ref<T>::iterator s2_s = m2->ref().begin();
157173
typename List_Ref<T>::iterator s2_e = m2->ref().end();
@@ -163,24 +179,22 @@ inline void join_marked_multi_to_two_all(List_Ref<T> &x, List_Ref<int> &markers,
163179
if (m1 != m_end) {
164180
new_merges.push_back(_MOVE(*m1));
165181
}
166-
182+
167183
merges = _MOVE(new_merges);
168184
}
169-
185+
170186
x = _MOVE(merges.front());
171187
}
172188

173189

174190
template<class T, typename Compare>
175-
inline void join_marked(List_Ref<T> &x, List_Ref<int> &markers, Compare &c, const bool keep_equal)
176-
{
191+
inline void join_marked(
192+
List_Ref<T> &x, List_Ref<int> &markers, Compare &c, const bool keep_equal) {
177193
if (markers.ref().size() <= 1) {
178194
return;
179195
}
180-
196+
181197
join_marked_multi_to_two_all(x, markers, c, keep_equal);
182-
183198
}
184199

185-
#endif /* PARETO_0_NOSORT_BLOCK_HH */
186-
200+
#endif // RTLIB_ADP_SPECIALIZATION_PARETO_0_NOSORT_BLOCK_HH_

0 commit comments

Comments
 (0)