Skip to content

Commit fe6a3e7

Browse files
committed
Redefined OrderedSet
1 parent 375a2ba commit fe6a3e7

13 files changed

Lines changed: 539 additions & 624 deletions

algorithms/scc/minreach_scc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ SCCData MinReachSCC::calculate(const DirectedSBG& dsbg)
7272
oldE = _dsbg.E();
7373
rmap = sccStep();
7474
Ediff = oldE.difference(_dsbg.E());
75-
deleted_edges = std::move(deleted_edges).disjointCup(std::move(Ediff));
75+
deleted_edges = std::move(deleted_edges).disjointCup(Ediff);
7676
} while (Ediff != SET_FACT.createSet());
7777
rmap.compact();
7878

eval/user_impl_map.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
#include "algorithms/scc/scc_fact.hpp"
2121
#include "eval/user_impl_map.hpp"
22+
#include "sbg/pw_map.hpp"
2223
#include "sbg/pwmap_fact.hpp"
24+
#include "sbg/set.hpp"
2325
#include "sbg/set_fact.hpp"
2426
#include "util/debug.hpp"
2527

sbg/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ target_sources(
1717
map_detail.cpp
1818
multidim_inter.cpp
1919
natural.cpp
20+
ord_set.cpp
2021
ord_unidim_dense_set.cpp
2122
pw_map.cpp
2223
pwmap_fact.cpp
@@ -26,7 +27,6 @@ target_sources(
2627
set_fact.cpp
2728
unord_pwmap.cpp
2829
unord_set.cpp
29-
#ord_set.cpp
3030
#dom_ord_pwmap.cpp
3131
#map_entry.cpp
3232
#ord_pwmap.cpp

sbg/map_detail.cpp

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -89,30 +89,23 @@ CompactSetImpl compactImage(const CompactSetImpl& s, const Expr& expr
8989
return result;
9090
}
9191

92-
UnorderedSet image(const UnorderedSet& s, const ExpressionImpl& expr
93-
, bool is_injective)
94-
{
95-
return compactImage<UnorderedSet, MultiDimInter, ExpressionImpl>(
96-
s, expr, is_injective);
97-
}
98-
99-
OrdUnidimDenseSet image(const OrdUnidimDenseSet& s
100-
, const LinearExpr& linear_expr, bool is_injective)
101-
{
102-
return compactImage<OrdUnidimDenseSet, Interval, LinearExpr>(
103-
s, linear_expr, is_injective);
104-
}
105-
10692
Set MapDetail::image(const Set& s, const Expression& expr)
10793
{
10894
auto image_evaluator = Overload {
10995
[&](const UnorderedSet& a)
11096
{
111-
return Set{detail::image(a, expr._impl, expr.isInjective())};
97+
return Set{detail::compactImage<UnorderedSet, MultiDimInter
98+
, ExpressionImpl>(a, expr._impl, expr.isInjective())};
11299
},
113100
[&](const OrdUnidimDenseSet& a)
114101
{
115-
return Set{detail::image(a, expr._impl[0], expr.isInjective())};
102+
return Set{detail::compactImage<OrdUnidimDenseSet, Interval, LinearExpr>(
103+
a, expr._impl[0], expr.isInjective())};
104+
},
105+
[&](const OrderedSet& a)
106+
{
107+
return Set{detail::compactImage<OrderedSet, MultiDimInter
108+
, ExpressionImpl>(a, expr._impl, expr.isInjective())};
116109
},
117110
[&](const auto& a) { return Set{SetKind::kUnordered}; }
118111
};
@@ -159,29 +152,23 @@ CompactSetImpl compactPreImage(const CompactSetImpl& s, const Expr& expr)
159152
return result;
160153
}
161154

162-
UnorderedSet preImage(const UnorderedSet& s, const ExpressionImpl& linear_expr)
163-
{
164-
return compactPreImage<UnorderedSet, MultiDimInter, ExpressionImpl>(
165-
s, linear_expr);
166-
}
167-
168-
OrdUnidimDenseSet preImage(const OrdUnidimDenseSet& s
169-
, const LinearExpr& linear_expr)
170-
{
171-
return compactPreImage<OrdUnidimDenseSet, Interval, LinearExpr>(
172-
s, linear_expr);
173-
}
174-
175155
Set MapDetail::preImage(const Set& s, const Expression& expr)
176156
{
177157
auto pre_image_evaluator = Overload {
178158
[&](const UnorderedSet& a)
179159
{
180-
return Set{detail::preImage(a, expr._impl)};
160+
return Set{detail::compactPreImage<UnorderedSet, MultiDimInter
161+
, ExpressionImpl>(a, expr._impl)};
181162
},
182163
[&](const OrdUnidimDenseSet& a)
183164
{
184-
return Set{detail::preImage(a, expr._impl[0])};
165+
return Set{detail::compactPreImage<OrdUnidimDenseSet, Interval
166+
, LinearExpr>(a, expr._impl[0])};
167+
},
168+
[&](const OrderedSet& a)
169+
{
170+
return Set{detail::compactPreImage<OrderedSet, MultiDimInter
171+
, ExpressionImpl>(a, expr._impl)};
185172
},
186173
[&](const auto& a) { return Set{SetKind::kUnordered}; }
187174
};
@@ -289,6 +276,12 @@ Set MapDetail::lessImage(const Expression& expr1, const Expression& expr2)
289276
a.pushBack(detail::lessImage(expr1._impl[0], expr2._impl[0]));
290277
return Set{a};
291278
},
279+
[&](OrderedSet& a)
280+
{
281+
detail::lessImage<OrderedSet, MultiDimInter, ExpressionImpl>(
282+
expr1._impl, expr2._impl, a);
283+
return Set{a};
284+
},
292285
[&](auto& a) { return Set{SetKind::kUnordered}; }
293286
};
294287
return std::visit(less_image_evaluator, result._impl);
@@ -392,7 +385,9 @@ AtomicMapVector reduce(const MultiDimInter& mdi, const ExpressionImpl& expr
392385
return reduce(reducible_interval, reducible_expr);
393386
}
394387

395-
MapVector MapDetail::reduce(const UnorderedSet& s, const ExpressionImpl& expr)
388+
template<typename SetMDIImpl>
389+
MapVector MapDetail::MDICollectionReduce(const SetMDIImpl& s
390+
, const ExpressionImpl& expr)
396391
{
397392
MapVector result;
398393

@@ -443,13 +438,22 @@ MapVector MapDetail::reduce(const Map& m)
443438
return result;
444439
}
445440

446-
result = std::visit([&](const auto& a)
441+
auto reduce_evaluator = Overload {
442+
[&](const UnorderedSet& a)
443+
{
444+
return MDICollectionReduce<UnorderedSet>(a, law._impl);
445+
},
446+
[&](const OrdUnidimDenseSet& a)
447447
{
448448
return reduce(a, law._impl);
449-
}
450-
, domain._impl);
451-
452-
return result;
449+
},
450+
[&](const OrderedSet& a)
451+
{
452+
return MDICollectionReduce<OrderedSet>(a, law._impl);
453+
},
454+
[&](const auto& a) { return Set{SetKind::kUnordered}; }
455+
};
456+
return std::visit(reduce_evaluator, m.domain()._impl);
453457
}
454458

455459
} // namespace detail

sbg/map_detail.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ class MapDetail {
5353
static MapVector reduce(const Map& m);
5454

5555
private:
56-
static MapVector reduce(const UnorderedSet& s, const ExpressionImpl& expr);
56+
template<typename SetMDIImpl>
57+
static MapVector MDICollectionReduce(const SetMDIImpl& s
58+
, const ExpressionImpl& expr);
5759
static MapVector reduce(const OrdUnidimDenseSet& s
5860
, const ExpressionImpl& expr);
5961
};

0 commit comments

Comments
 (0)