Skip to content

Commit 2e58221

Browse files
committed
Redefined OrdPWMap
1 parent cd372f5 commit 2e58221

5 files changed

Lines changed: 588 additions & 818 deletions

File tree

sbg/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ target_sources(
1515
linear_expr.cpp
1616
map.cpp
1717
map_detail.cpp
18+
map_entry.cpp
1819
multidim_inter.cpp
1920
natural.cpp
21+
ord_pwmap.cpp
2022
ord_set.cpp
2123
ord_unidim_dense_set.cpp
2224
pw_map.cpp
@@ -25,11 +27,10 @@ target_sources(
2527
sbg.cpp
2628
set.cpp
2729
set_fact.cpp
30+
set_perimeter.cpp
2831
unord_pwmap.cpp
2932
unord_set.cpp
3033
#dom_ord_pwmap.cpp
31-
#map_entry.cpp
32-
#ord_pwmap.cpp
3334
)
3435

3536
add_custom_target(sbg-doc

sbg/map_entry.cpp

Lines changed: 16 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -23,101 +23,33 @@ namespace SBG {
2323

2424
namespace 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

sbg/map_entry.hpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,38 @@
2323
2424
******************************************************************************/
2525

26-
#ifndef SBG_MAP_ENTRY_HPP
27-
#define SBG_MAP_ENTRY_HPP
26+
#ifndef SBGRAPH_SBG_MAP_ENTRY_HPP_
27+
#define SBGRAPH_SBG_MAP_ENTRY_HPP_
2828

2929
#include "sbg/map.hpp"
30+
#include "sbg/set_perimeter.hpp"
3031

3132
namespace SBG {
3233

3334
namespace LIB {
3435

35-
namespace Internal {
36+
namespace detail {
3637

37-
using SetPerimeter = std::pair<MD_NAT, MD_NAT>;
38-
using MapEntry = std::pair<Map, SetPerimeter>;
39-
using OrdMapCollection = std::vector<MapEntry>;
38+
class MapEntry {
39+
public:
40+
MapEntry(const Map& m);
41+
MapEntry(Map&& m);
4042

41-
SetPerimeter calculatePerimeter(const Set &s);
42-
bool doInt(const SetPerimeter& p1, const SetPerimeter& p2);
43-
MapEntry createMapEntry(const Map& m);
44-
bool operator<(const MapEntry& mpe1, const MapEntry& mpe2);
45-
void emplaceBack(OrdMapCollection& ord_pw, const MapEntry& entry);
46-
void emplaceBack(OrdMapCollection& ord_pw, const Map& m);
47-
void emplaceHint(OrdMapCollection& ord_pw, const Map& m, NAT hint);
48-
void advanceHint(OrdMapCollection& ord_pw, const MD_NAT crit, NAT& hint);
43+
const Map& map() const;
44+
const SetPerimeter& perimeter() const;
4945

50-
} // namespace Internal
46+
bool operator==(const MapEntry& other) const;
47+
bool operator<(const MapEntry& other) const;
48+
49+
private:
50+
Map _map;
51+
SetPerimeter _perimeter;
52+
};
53+
54+
} // namespace detail
5155

5256
} // namespace LIB
5357

5458
} // namespace SBG
5559

56-
#endif
60+
#endif // SBGRAPH_SBG_MAP_ENTRY_HPP_

0 commit comments

Comments
 (0)