Skip to content

Commit 9cdf271

Browse files
committed
[iss-45]
1 parent 294d963 commit 9cdf271

8 files changed

Lines changed: 327 additions & 276 deletions

File tree

eval/main.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,37 @@ void parseEvalProgramFromFile(std::string fname, Impl impl, bool debug)
6262
std::cout << "Parsing succeeded\n";
6363
std::cout << "-------------------------\n";
6464
std::cout << ">>>>>> Eval result <<<<<<\n";
65-
std::cout << "-------------------------\n\n";
65+
std::cout << "-------------------------\n";
6666

6767
std::shared_ptr<SBG::LIB::SetAF> set_fact
6868
= std::make_shared<SBG::LIB::UnordAF>();
69-
7069
switch (impl.set_impl_) {
70+
case 1:
71+
std::cout << ">>>>>> Ordered Sets <<<<<<\n";
72+
std::cout << "-------------------------\n\n";
73+
set_fact = std::make_shared<SBG::LIB::OrdAF>();
74+
break;
7175
case 2:
76+
std::cout << ">>>>>> Ordered Dense Sets <<<<<<\n";
77+
std::cout << "-------------------------\n\n";
7278
set_fact = std::make_shared<SBG::LIB::OrdDenseAF>();
79+
break;
7380

7481
default:
82+
std::cout << ">>>>>> Unordered Sets <<<<<<\n";
83+
std::cout << "-------------------------\n\n";
7584
break;
7685
}
7786

7887
SBG::LIB::MapAF map_fact(*set_fact);
7988
std::shared_ptr<SBG::LIB::PWMapAF> fact
8089
= std::make_shared<SBG::LIB::UnordPWMapAF>(map_fact);
8190
switch (impl.pw_impl_) {
91+
case 1:
92+
std::cout << ">>>>>> Ordered PWMaps <<<<<<\n";
93+
std::cout << "-------------------------\n\n";
94+
fact = std::make_shared<SBG::LIB::OrdPWMapAF>(map_fact);
95+
break;
8296
default:
8397
break;
8498
}
@@ -106,6 +120,8 @@ void usage()
106120
std::cout << "-f, --file SBG program file used as input\n";
107121
std::cout << "-s, --set_impl Choose set implementation: 0 unordered sets,\n";
108122
std::cout << " 1 ordered sets, 2 ordered dense sets.\n";
123+
std::cout << "-p, --pwmap_impl Choose pwmap implementation: 0 unordered,\n";
124+
std::cout << " 1 ordered.\n";
109125
std::cout << "-h, --help Display this information and exit\n";
110126
std::cout << "-d, --debug Activate debug info\n";
111127
std::cout << "-v, --version Display version information and exit\n\n";
@@ -232,18 +248,19 @@ void version()
232248
int main(int argc, char**argv)
233249
{
234250
std::string filename;
235-
int opt, set_impl = 0, pw_impl = 0;
251+
int opt, set_impl = 0, pwmap_impl = 0;
236252
extern char* optarg;
237253
bool debug = false;
238254

239255
while (true) {
240256
static struct option long_options[] = {{"file", required_argument, 0, 'f'}
241257
, {"set_impl", required_argument, 0, 's'}
258+
, {"pwmap_impl", required_argument, 0, 'p'}
242259
, {"help", no_argument, 0, 'h'}
243260
, {"debug", no_argument, 0, 'd'}
244261
, {"version", no_argument, 0, 'v'}
245262
, {0, 0, 0, 0}};
246-
opt = getopt_long(argc, argv, "f:s:hdv", long_options, nullptr);
263+
opt = getopt_long(argc, argv, "f:s:p:hdv", long_options, nullptr);
247264
if (opt == EOF)
248265
break;
249266
switch (opt) {
@@ -253,6 +270,9 @@ int main(int argc, char**argv)
253270
case 's':
254271
set_impl = std::stoi(optarg);
255272
break;
273+
case 'p':
274+
pwmap_impl = std::stoi(optarg);
275+
break;
256276
case 'h':
257277
usage();
258278
exit(0);
@@ -272,7 +292,7 @@ int main(int argc, char**argv)
272292
}
273293

274294
if (!filename.empty())
275-
parseEvalProgramFromFile(filename, Impl(set_impl, pw_impl), debug);
295+
parseEvalProgramFromFile(filename, Impl(set_impl, pwmap_impl), debug);
276296
else
277297
SBG::Util::ERROR("A filename should be provided\n");
278298

sbg/interval.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,21 @@ Interval Interval::least(const Interval &other) const
143143
MaybeInterval Interval::compact(const Interval &other) const
144144
{
145145
if (step_ == other.step_) {
146-
if (end_+step_ == other.begin_)
146+
if (end_ + step_ == other.begin_)
147147
return Interval(begin_, step_, other.end_);
148-
149-
else if (other.end_+step_ == begin_)
148+
149+
else if (other.end_ + step_ == begin_)
150150
return Interval(other.begin_, step_, end_);
151-
152-
else if (!intersection(other).isEmpty()) {
153-
NAT new_b = std::min(begin_, other.begin_);
154-
NAT new_e = std::max(end_, other.end_);
155-
return Interval(new_b, step_, new_e);
151+
152+
else {
153+
Interval inter = intersection(other);
154+
if (!inter.isEmpty()) {
155+
if (inter == other)
156+
return {};
157+
NAT new_b = std::min(begin_, other.begin_);
158+
NAT new_e = std::max(end_, other.end_);
159+
return Interval(new_b, step_, new_e);
160+
}
156161
}
157162
}
158163

sbg/multidim_inter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ MultiDimInter::const_iterator MultiDimInter::end() const
5454
}
5555

5656
void MultiDimInter::emplaceBack(Interval i)
57-
{
58-
if (i.isEmpty())
59-
intervals_ = InterVector();
57+
{
58+
if (i.isEmpty()){
59+
intervals_ = InterVector();}
6060
else
6161
intervals_.push_back(i);
6262
return;
@@ -93,6 +93,7 @@ bool MultiDimInter::operator<(const MultiDimInter &other) const
9393
return minElem() < other.minElem();
9494
}
9595

96+
9697
std::ostream &operator<<(std::ostream &out, const MultiDimInter &mdi)
9798
{
9899
std::size_t sz = mdi.arity();

sbg/multidim_inter.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
#ifndef SBG_MULTIDIM_INTERVAL_HPP
2929
#define SBG_MULTIDIM_INTERVAL_HPP
3030

31+
#include <iostream>
3132
#include "sbg/interval.hpp"
3233

34+
35+
3336
namespace SBG {
3437

3538
namespace LIB {
@@ -125,6 +128,7 @@ struct MultiDimInter {
125128
* not an mdi, so no value is returned.
126129
*/
127130
MaybeMDI compact(const MultiDimInter &other) const;
131+
128132
};
129133
std::ostream &operator<<(std::ostream &out, const MultiDimInter &mi);
130134

sbg/natural.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ bool MD_NAT::operator<(const MD_NAT &other) const
6363
return false;
6464
}
6565

66-
bool MD_NAT::menorThan(const MD_NAT &other) const
67-
{
68-
for (unsigned int j = 0; j < arity(); ++j){
69-
if (operator[](j) < other[j])
70-
return true;
71-
}
72-
return false;
73-
}
7466

7567
bool MD_NAT::operator<=(const MD_NAT &other) const
7668
{

sbg/natural.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ struct MD_NAT {
9090
* i for which x1[i] < x2[i] and for every j < i, x1[j] == x2[j].
9191
*/
9292
bool operator<(const MD_NAT &other) const;
93-
bool menorThan(const MD_NAT &other) const;
9493

9594
bool operator<=(const MD_NAT &other) const;
9695

0 commit comments

Comments
 (0)