@@ -26,6 +26,7 @@ Author: Daniel Poetzl
26
26
#include < tuple>
27
27
#include < type_traits>
28
28
#include < vector>
29
+ #include < set>
29
30
30
31
#include " as_const.h"
31
32
#include " irep.h"
@@ -54,6 +55,11 @@ Author: Daniel Poetzl
54
55
typename equalT> \
55
56
type sharing_mapt<keyT, valueT, fail_if_equal, hashT, equalT>
56
57
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
+
57
63
// / Macro to abbreviate the out-of-class definitions of methods of sharing_mapt
58
64
// / with a return type that is defined within the class.
59
65
// /
@@ -363,6 +369,17 @@ class sharing_mapt
363
369
// / View of the key-value pairs in the map. A view is a list of pairs with
364
370
// / the components being const references to the keys and values in the map.
365
371
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
+ }
366
383
367
384
class delta_view_itemt
368
385
{
@@ -413,7 +430,7 @@ class sharing_mapt
413
430
// / - Best case: O(N + H)
414
431
// /
415
432
// / \param [out] view: Empty view
416
- void get_view (viewt &view ) const ;
433
+ template < class V > void get_view (V& ) const ;
417
434
viewt get_view () const
418
435
{
419
436
viewt result;
@@ -459,6 +476,9 @@ class sharing_mapt
459
476
delta_viewt &delta_view,
460
477
const bool only_common = true ) const ;
461
478
479
+ delta_viewt get_delta_view (
480
+ const sharing_mapt &other, const bool only_common=true ) const ;
481
+
462
482
// / Call a function for every key-value pair in the map.
463
483
// /
464
484
// / Complexity: as \ref sharing_mapt::get_view
@@ -785,15 +805,15 @@ ::get_sharing_stats_map(Iterator begin, Iterator end)
785
805
}
786
806
#endif
787
807
788
- SHARING_MAPT (void )::get_view(viewt &view) const
808
+ SHARING_MAPTV (void , view_type )::get_view(view_type &view) const
789
809
{
790
810
SM_ASSERT (view.empty ());
791
811
792
812
if (empty ())
793
813
return ;
794
814
795
815
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));
797
817
};
798
818
799
819
iterate(map, f);
@@ -1068,6 +1088,15 @@ ::get_delta_view(
1068
1088
while (!stack.empty ());
1069
1089
}
1070
1090
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
+
1071
1100
SHARING_MAPT2 (, nodet &)::get_leaf_node(const key_type &k)
1072
1101
{
1073
1102
SM_ASSERT (has_key (k));
0 commit comments