Skip to content

Commit fc1c8c4

Browse files
committed
add public access to bijection key_val iterator
Signed-off-by: Lev Nachmanson <[email protected]>
1 parent 8b5510b commit fc1c8c4

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/math/lp/dioph_eq.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,23 @@ namespace lp {
6060
iv(const mpq& v, unsigned j) : m_coeff(v), m_j(j) {}
6161
};
6262

63-
struct bijection {
63+
class bijection {
6464
std::unordered_map<unsigned, unsigned> m_map;
6565
std::unordered_map<unsigned, unsigned> m_rev_map;
66+
public:
67+
auto map_begin() const { return m_map.begin(); }
68+
auto map_end() const { return m_map.end(); }
69+
70+
// Iterator helper
71+
struct map_it {
72+
const bijection& m_bij;
73+
auto begin() const { return m_bij.map_begin(); }
74+
auto end() const { return m_bij.map_end(); }
75+
};
6676

77+
78+
// Add a method to get iterators over the key->val map (complementing key_val)
79+
map_it key_val_pairs() const { return {*this}; }
6780
void add(unsigned a, unsigned b) {
6881
SASSERT(!contains(m_map, a) && !contains(m_rev_map, b));
6982
m_map[a] = b;
@@ -968,8 +981,8 @@ namespace lp {
968981
void remove_irrelevant_fresh_defs() {
969982
std_vector<unsigned> xt_to_remove;
970983
std_vector<unsigned> rows_to_remove_the_defs_from;
971-
for (const auto& p : m_fresh_k2xt_terms.m_bij.m_rev_map) {
972-
unsigned xt = p.first;
984+
for (const auto& p : m_fresh_k2xt_terms.m_bij.key_val_pairs()) {
985+
unsigned xt = p.second;
973986
if (xt >= m_e_matrix.column_count()) {
974987
xt_to_remove.push_back(xt);
975988
rows_to_remove_the_defs_from.push_back(m_fresh_k2xt_terms.get_by_val(xt).second);

0 commit comments

Comments
 (0)