@@ -341,7 +341,6 @@ PWMapStratPtr DomOrdPWMap::inverse() const
341341 Internal::emplaceBack (res, inv);
342342 }
343343 }
344-
345344 std::sort (res.begin (),res.end (), operator <);
346345
347346 return std::make_unique<DomOrdPWMap>(res);
@@ -353,29 +352,28 @@ PWMapStratPtr DomOrdPWMap::composition(const PWMapStrategy& other) const
353352 DomOrdPWMapCRef othr = static_cast <DomOrdPWMapCRef>(other);
354353
355354 NAT global_pos = 0 ;
356- for (const MapEntry& o_mpe : othr.pieces_ ) {
357- const auto & o_m = o_mpe .first ;
358- auto img = o_m .image ();
355+ for (const MapEntry& other_mpe : othr.pieces_ ) {
356+ const Map& other_map = other_mpe .first ;
357+ Set img = other_map .image ();
359358
360- SetPerimeter i_sp = calculatePerimeter (img);
361- auto i_max_per = i_sp.second ;
362-
363- advanceHint (res, o_mpe.second .first , global_pos);
364-
365- for (const MapEntry& t_mpe : pieces_) {
366- const auto & t_m = t_mpe.first ;
367- const SetPerimeter& t_sp = t_mpe.second ;
368- auto t_min_per = t_sp.first ;
359+ SetPerimeter image_sp = calculatePerimeter (img);
360+ MD_NAT image_max = image_sp.second ;
361+ advanceHint (res, other_mpe.second .first , global_pos);
362+
363+ for (const MapEntry& this_mpe : pieces_) {
364+ const Map& this_map = this_mpe.first ;
365+ const SetPerimeter& this_sp = this_mpe.second ;
366+ MD_NAT this_min = this_sp.first ;
369367
370- if (doInt (t_sp, i_sp )) {
371- auto res_com = t_m .composition (o_m );
372- if (!res_com .isEmpty ()) {
373- emplaceHint (res, res_com , global_pos);
368+ if (doInt (this_sp, image_sp )) {
369+ Map composition = this_map .composition (other_map );
370+ if (!composition .isEmpty ()) {
371+ emplaceHint (res, composition , global_pos);
374372 }
375373 continue ;
376374 }
377375
378- if (i_max_per < t_min_per ) {
376+ if (image_max < this_min ) {
379377 break ;
380378 }
381379 }
@@ -455,7 +453,6 @@ PWMapStratPtr DomOrdPWMap::concatenation(const PWMapStrategy& other) const
455453
456454 auto it1 = pieces_.begin (), it2 = othr.pieces_ .begin ();
457455 auto end1 = pieces_.end (), end2 = othr.pieces_ .end ();
458-
459456
460457 for (; it1 != end1 && it2 != end2;) {
461458 auto min_per_m1 = it1->second .first ;
@@ -490,26 +487,25 @@ PWMapStratPtr DomOrdPWMap::combine(const PWMapStrategy& other) const
490487 OrdMapCollection res = pieces_;
491488
492489 NAT global_pos = 0 ;
493-
494- SetPerimeter t_sp = calculatePerimeter (dom ());
495-
496- for (const MapEntry& o_mpe : othr.pieces_ ) {
497- const Map& o_m = o_mpe.first ;
498- const SetPerimeter& o_sp = o_mpe.second ;
499- Map res_comb (o_m.dom (), o_m.exp ());
500-
501- if (doInt (o_sp, t_sp)){
502- Set dom_o_m = o_m.dom (), new_dom = dom_o_m.difference (dom ());
503- if (new_dom.isEmpty ())
490+ SetPerimeter this_sp = calculatePerimeter (dom ());
491+ for (const MapEntry& other_mpe : othr.pieces_ ) {
492+ const Map& other_map = other_mpe.first ;
493+ const SetPerimeter& other_sp = other_mpe.second ;
494+
495+ // There is intersection of domains
496+ Map exclusive_other (other_map.dom (), other_map.exp ());
497+ if (doInt (other_sp, this_sp)) {
498+ Set new_dom = other_map.dom ().difference (dom ());
499+ if (new_dom.isEmpty ()) {
504500 continue ;
505- res_comb = Map (new_dom, o_m.exp ());
501+ }
502+ exclusive_other = Map (new_dom, other_map.exp ());
506503 }
507-
508- advanceHint (res, o_sp.first , global_pos);
509- emplaceHint (res, res_comb, global_pos);
504+ advanceHint (res, other_sp.first , global_pos);
505+ emplaceHint (res, exclusive_other, global_pos);
510506 }
511507
512- return std::make_unique<DomOrdPWMap>(res);
508+ return std::make_unique<DomOrdPWMap>(res);
513509}
514510
515511PWMapStratPtr DomOrdPWMap::reduce (const Interval& i, const LExp& le) const
@@ -596,23 +592,24 @@ PWMapStratPtr DomOrdPWMap::reduce(const Map& map) const
596592 if (!was_reduced)
597593 not_reduced.emplaceBack (dom_piece);
598594 }
599-
600- if (!not_reduced.isEmpty ())
601- Internal::emplaceBack (res, Map (not_reduced, e)); // Add unreduced subpieces
595+
596+ // Add not reduced subpieces
597+ if (!not_reduced.isEmpty ())
598+ Internal::emplaceBack (res, Map (not_reduced, e));
602599
603600 return std::make_unique<DomOrdPWMap>(res);
604601}
605602
606603PWMapStratPtr DomOrdPWMap::reduce () const
607604{
608605 OrdMapCollection res;
606+
609607 for (const MapEntry& mpe : pieces_) {
610608 PWMapStratPtr ith = reduce (mpe.first );
611609 DomOrdPWMap *ith_c = static_cast <DomOrdPWMap *>(ith.get ());
612610 for (const MapEntry& mpe_ith_elem : ith_c->pieces_ )
613611 Internal::emplaceBack (res, mpe_ith_elem);
614612 }
615-
616613 std::sort (res.begin (), res.end (), operator <);
617614
618615 return std::make_unique<DomOrdPWMap>(res);
@@ -693,12 +690,10 @@ PWMapStratPtr DomOrdPWMap::firstInv(const Set& subdom) const
693690 const SetPerimeter& t_sp = t_mpe.second ;
694691 auto t_min_per = t_sp.first ;
695692
696-
697693 if (doInt (t_sp, short_sp)) {
698694 Set img = t_m.image (subdom);
699695
700696 if (!img.isEmpty ()) {
701-
702697 if (!visited.isEmpty ()) {
703698 SetPerimeter i_sp = calculatePerimeter (img);
704699 SetPerimeter v_sp = calculatePerimeter (visited);
0 commit comments