@@ -370,23 +370,35 @@ class sharing_mapt
370
370
{
371
371
public:
372
372
delta_view_itemt (
373
- const bool in_both,
374
373
const key_type &k,
375
374
const mapped_type &m,
376
- const mapped_type &other_m) :
377
- in_both (in_both),
378
- k (k),
379
- m (m),
380
- other_m (other_m) {}
375
+ const mapped_type &other_m)
376
+ : k(k), m(m), other_m(&other_m)
377
+ {
378
+ }
381
379
382
- // if true key is in both maps, if false key is only in the map
383
- // from which the view was obtained
384
- const bool in_both;
380
+ delta_view_itemt (const key_type &k, const mapped_type &m)
381
+ : k(k), m(m), other_m(nullptr )
382
+ {
383
+ }
385
384
386
385
const key_type &k;
387
386
388
387
const mapped_type &m;
389
- const mapped_type &other_m;
388
+
389
+ bool is_in_both_maps () const
390
+ {
391
+ return other_m != nullptr ;
392
+ }
393
+
394
+ const mapped_type &get_other_map_value () const
395
+ {
396
+ PRECONDITION (is_in_both_maps ());
397
+ return *other_m;
398
+ }
399
+
400
+ private:
401
+ const mapped_type *other_m;
390
402
};
391
403
392
404
// / Delta view of the key-value pairs in two maps. A delta view of two maps is
@@ -411,13 +423,12 @@ class sharing_mapt
411
423
// / the maps that are contained in subtrees that are not shared between them.
412
424
// /
413
425
// / A delta view is represented as a list of structs, with each struct having
414
- // / four members (`in_both`, `key`, `value1`, `value2`). The elements `key`,
415
- // / `value1`, and `value2` are const references to the corresponding elements
416
- // / in the map. The first element indicates whether the key exists in both
417
- // / maps, the second element is the key, the third element is the mapped value
418
- // / of the first map, and the fourth element is the mapped value of the second
419
- // / map, or a dummy element if the key exists only in the first map (in which
420
- // / case `in_both` is false).
426
+ // / three members (`key`, `value1`, `value2`). The elements `key`, `value1`,
427
+ // / and `value2` are const references to the corresponding elements in the
428
+ // / map, with the third being absent if the key only existed in the queried
429
+ // / map. The first element is the key, the second element is the mapped value
430
+ // / of the first map, and the third element is the mapped value of the second
431
+ // / map if present.
421
432
// /
422
433
// / Calling `A.delta_view(B, ...)` yields a view such that for each element in
423
434
// / the view one of two things holds:
@@ -540,9 +551,6 @@ class sharing_mapt
540
551
std::set<const void *> &marked,
541
552
bool mark = true ) const ;
542
553
543
- // dummy element returned when no element was found
544
- static mapped_type dummy;
545
-
546
554
static const std::string not_found_msg;
547
555
548
556
// config
@@ -765,7 +773,7 @@ SHARING_MAPT(void)
765
773
::gather_all(const innert &n, delta_viewt &delta_view) const
766
774
{
767
775
auto f = [&delta_view](const key_type &k, const mapped_type &m) {
768
- delta_view.push_back (delta_view_itemt (false , k, m, dummy ));
776
+ delta_view.push_back (delta_view_itemt (k, m));
769
777
};
770
778
771
779
iterate(n, f);
@@ -895,12 +903,12 @@ ::get_delta_view(
895
903
{
896
904
if (!l1.shares_with (*p))
897
905
{
898
- delta_view.push_back ({true , k1, l1.get_value (), p->get_value ()});
906
+ delta_view.push_back ({k1, l1.get_value (), p->get_value ()});
899
907
}
900
908
}
901
909
else if (!only_common)
902
910
{
903
- delta_view.push_back ({false , l1.get_key (), l1. get_value (), dummy });
911
+ delta_view.push_back ({k1 , l1.get_value ()});
904
912
}
905
913
}
906
914
}
@@ -1053,8 +1061,6 @@ SHARING_MAPT2(optionalt<std::reference_wrapper<const, mapped_type>>)::find(
1053
1061
1054
1062
SHARING_MAPT (const std::string)::not_found_msg="key not found";
1055
1063
1056
- SHARING_MAPT2 (, mapped_type)::dummy;
1057
-
1058
1064
SHARING_MAPT (const std::size_t )::bits = 18;
1059
1065
SHARING_MAPT (const std::size_t )::chunk = 3;
1060
1066
0 commit comments