@@ -23,101 +23,33 @@ namespace SBG {
2323
2424namespace LIB {
2525
26- namespace Internal {
26+ namespace detail {
2727
28- SetPerimeter calculatePerimeter (const Set& s)
29- {
30- std::size_t ar = s.arity ();
31- MD_NAT min_per (ar, Inf);
32- MD_NAT max_per (ar, 0 );
33-
34- for (const SetPiece& mdi : s) {
35- MD_NAT candidate_min = mdi.minElem ();
36- MD_NAT candidate_max = mdi.maxElem ();
37- for (size_t i = 0 ; i < ar; ++i) {
38- min_per[i] = std::min (min_per[i], candidate_min[i]);
39- max_per[i] = std::max (max_per[i], candidate_max[i]);
40- }
41- }
42-
43- return {min_per, max_per};
44- }
28+ // //////////////////////////////////////////////////////////////////////////////
29+ // Map entry -------------------------------------------------------------------
30+ // //////////////////////////////////////////////////////////////////////////////
4531
46- bool doInt (const SetPerimeter& p1, const SetPerimeter& p2)
47- {
48- const auto min_per_p1 = p1.first ;
49- const auto max_per_p1 = p1.second ;
50- const auto min_per_p2 = p2.first ;
51- const auto max_per_p2 = p2.second ;
52- const unsigned int arity = max_per_p1.arity ();
53-
54- for (unsigned int j = 0 ; j < arity; ++j) {
55- if (max_per_p1[j] < min_per_p2[j] || max_per_p2[j] < min_per_p1[j]) {
56- return false ; // No intersection
57- }
58- }
59-
60- return true ; // Intersection detected
61- }
62-
63- MapEntry createMapEntry (const Map& m)
64- {
65- return {m, calculatePerimeter (m.dom ())};
66- }
32+ MapEntry::MapEntry (const Map& m)
33+ : _map(m), _perimeter(m.domain().perimeter()) {}
6734
68- bool operator <(const MapEntry& mpe1, const MapEntry& mpe2)
69- {
70- return mpe1.second .first < mpe2.second .first ;
71- }
35+ MapEntry::MapEntry (Map&& m)
36+ : _map(std::move(m)), _perimeter(m.domain().perimeter()) {}
7237
73- void emplaceBack (OrdMapCollection& ord_pw, const MapEntry& entry)
74- {
75- if (!entry.first .isEmpty ()) {
76- ord_pw.emplace_back (entry);
77- }
78- }
38+ const Map& MapEntry::map () const { return _map; }
7939
80- void emplaceBack (OrdMapCollection& ord_pw, const Map& m)
81- {
82- if (!m.isEmpty ()) {
83- ord_pw.emplace_back (createMapEntry (m));
84- }
85- }
40+ const SetPerimeter& MapEntry::perimeter () const { return _perimeter; }
8641
87- void emplaceHint (OrdMapCollection& ord_pw, const Map& m, NAT hint)
42+ bool MapEntry:: operator ==( const MapEntry& other) const
8843{
89- if (!m.isEmpty ()) {
90- auto it = ord_pw.begin ();
91- std::advance (it, hint);
92- auto end = ord_pw.end ();
93- MapEntry mpe = createMapEntry (m);
94- while (it != end) {
95- if (it->second .first < mpe.second .first ) {
96- ++it;
97- } else {
98- break ;
99- }
100- }
101- ord_pw.emplace (it, mpe);
102- }
44+ return _map == other._map ;
10345}
10446
105- void advanceHint (OrdMapCollection& ord_pw, const MD_NAT crit, NAT& hint)
47+ bool MapEntry:: operator <( const MapEntry& other) const
10648{
107- auto it = ord_pw.begin ();
108- std::advance (it, hint);
109- auto end = ord_pw.end ();
110- while (it != end) {
111- if (it->second .first < crit) {
112- ++it;
113- ++hint;
114- } else {
115- break ;
116- }
117- }
49+ return _perimeter.min () < other._perimeter .min ();
11850}
119-
120- } // namespace Internal
51+
52+ } // namespace detail
12153
12254} // namespace LIB
12355
0 commit comments