Skip to content

Commit 5bfa1d8

Browse files
author
martin
committed
Use sharing_mapt in constant_array_abstract_objectt
1 parent f4531f3 commit 5bfa1d8

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/util/sharing_map.h

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Author: Daniel Poetzl
2626
#include <tuple>
2727
#include <type_traits>
2828
#include <vector>
29+
#include <set>
2930

3031
#include "as_const.h"
3132
#include "irep.h"
@@ -54,6 +55,11 @@ Author: Daniel Poetzl
5455
typename equalT> \
5556
type sharing_mapt<keyT, valueT, fail_if_equal, hashT, equalT>
5657

58+
#define SHARING_MAPTV(R, V) \
59+
template <class keyT, class valueT, class hashT, class predT> \
60+
template <class V> \
61+
R sharing_mapt<keyT, valueT, hashT, predT>
62+
5763
/// Macro to abbreviate the out-of-class definitions of methods of sharing_mapt
5864
/// with a return type that is defined within the class.
5965
///
@@ -363,6 +369,17 @@ class sharing_mapt
363369
/// View of the key-value pairs in the map. A view is a list of pairs with
364370
/// the components being const references to the keys and values in the map.
365371
typedef std::vector<view_itemt> viewt;
372+
typedef std::set<view_itemt> sorted_viewt;
373+
374+
static void insert_view_item(viewt &v, view_itemt &&vi)
375+
{
376+
v.push_back(vi);
377+
}
378+
379+
static void insert_view_item(sorted_viewt &v, view_itemt &&vi)
380+
{
381+
v.insert(vi);
382+
}
366383

367384
class delta_view_itemt
368385
{
@@ -413,7 +430,7 @@ class sharing_mapt
413430
/// - Best case: O(N + H)
414431
///
415432
/// \param [out] view: Empty view
416-
void get_view(viewt &view) const;
433+
template <class V> void get_view(V&) const;
417434
viewt get_view() const
418435
{
419436
viewt result;
@@ -459,6 +476,9 @@ class sharing_mapt
459476
delta_viewt &delta_view,
460477
const bool only_common = true) const;
461478

479+
delta_viewt get_delta_view(
480+
const sharing_mapt &other, const bool only_common=true) const;
481+
462482
/// Call a function for every key-value pair in the map.
463483
///
464484
/// Complexity: as \ref sharing_mapt::get_view
@@ -785,15 +805,15 @@ ::get_sharing_stats_map(Iterator begin, Iterator end)
785805
}
786806
#endif
787807

788-
SHARING_MAPT(void)::get_view(viewt &view) const
808+
SHARING_MAPTV(void, view_type)::get_view(view_type &view) const
789809
{
790810
SM_ASSERT(view.empty());
791811

792812
if(empty())
793813
return;
794814

795815
auto f = [&view](const key_type &k, const mapped_type &m) {
796-
view.push_back(view_itemt(k, m));
816+
insert_view_item(view, view_itemt(k, m));
797817
};
798818

799819
iterate(map, f);
@@ -1068,6 +1088,15 @@ ::get_delta_view(
10681088
while(!stack.empty());
10691089
}
10701090

1091+
SHARING_MAPT2(, delta_viewt)::get_delta_view(
1092+
const sharing_mapt &other,
1093+
const bool only_common) const
1094+
{
1095+
delta_viewt delta_view;
1096+
get_delta_view(other, delta_view, only_common);
1097+
return delta_view;
1098+
}
1099+
10711100
SHARING_MAPT2(, nodet &)::get_leaf_node(const key_type &k)
10721101
{
10731102
SM_ASSERT(has_key(k));

0 commit comments

Comments
 (0)