LocSet.cpp
Go to the documentation of this file.00001
00015 #include "LocSet.hpp"
00016 #include "Location.hpp"
00017
00018 namespace OA {
00019
00020 static bool debug = false;
00021
00022
00023
00024
00025 void dumpLocSet(LocSet& set, std::ostream& os,
00026 OA_ptr<IRHandlesIRInterface> pIR)
00027 {
00028 os << "LocSet = { ";
00029 LocSet::iterator setIter;
00030 for (setIter=set.begin(); setIter!=set.end(); setIter++) {
00031 OA_ptr<Location> loc = *setIter;
00032 loc->dump(os,pIR);
00033 }
00034 os << " }" << std::endl;
00035 }
00036
00037
00038 OA_ptr<LocSet >
00039 intersectLocSets(LocSet& set1,
00040 LocSet& set2)
00041 {
00042 OA_DEBUG_CTRL_MACRO("DEBUG_LocSet:ALL", debug);
00043
00044 OA_ptr<LocSet> temp; temp = new LocSet;
00045 std::set_intersection(set1.begin(), set1.end(),
00046 set2.begin(), set2.end(),
00047 std::inserter(*temp,temp->end()));
00048 return temp;
00049 }
00050
00051
00052 OA_ptr<LocSet >
00053 unionLocSets(LocSet& set1, LocSet& set2)
00054 {
00055 OA_DEBUG_CTRL_MACRO("DEBUG_LocSet:ALL", debug);
00056
00057 OA_ptr<LocSet> temp; temp = new LocSet;
00058
00059 LocSet::iterator setIter;
00060 int count1=0;
00061 for (setIter=set1.begin(); setIter!=set1.end(); setIter++) {
00062 OA_ptr<Location> loc = *setIter;
00063 count1++;
00064 }
00065
00066 int count2=0;
00067 for (setIter=set2.begin(); setIter!=set2.end(); setIter++) {
00068 OA_ptr<Location> loc = *setIter;
00069 count2++;
00070 }
00071
00072 std::set_union(set1.begin(), set1.end(),
00073 set2.begin(), set2.end(),
00074 std::inserter(*temp,temp->end()));
00075 return temp;
00076 }
00077
00078
00079 bool mayOverlapLocSets(LocSet& set1,
00080 LocSet& set2)
00081 {
00082 OA_DEBUG_CTRL_MACRO("DEBUG_LocSet:ALL", debug);
00083
00084 if (debug) {
00085 std::cout << "mayOverlapLocSets: " << std::endl;
00086 }
00087 LocSet::iterator setIter1;
00088 LocSet::iterator setIter2;
00089 for (setIter1=set1.begin(); setIter1!=set1.end(); setIter1++) {
00090 for (setIter2=set2.begin(); setIter2!=set2.end(); setIter2++) {
00091 OA_ptr<Location> loc1 = *setIter1, loc2 = *setIter2;
00092 loc1 = *setIter1;
00093 loc2 = *setIter2;
00094 if (debug) {
00095 std::cout << "loc1 = ";
00096 loc1->dump(std::cout);
00097 std::cout << "loc2 = ";
00098 loc2->dump(std::cout);
00099 }
00100 if (loc1->mayOverlap(*loc2)) {
00101 return true;
00102 }
00103 }
00104 }
00105
00106 return false;
00107 }
00108
00109
00110 bool subSetOf(LocSet& set1, LocSet& set2)
00111 {
00112 OA_DEBUG_CTRL_MACRO("DEBUG_LocSet:ALL", debug);
00113
00114 bool retval = true;
00115
00116 LocSet::iterator setIter1;
00117 LocSet::iterator setIter2;
00118 for (setIter1=set1.begin(); setIter1!=set1.end(); setIter1++) {
00119 bool found = false;
00120 for (setIter2=set2.begin(); setIter2!=set2.end(); setIter2++) {
00121 OA_ptr<Location> loc1, loc2;
00122 loc1 = *setIter1;
00123 loc2 = *setIter2;
00124 if (loc1 == loc2) {
00125 found = true;
00126 break;
00127 }
00128 }
00129 if (!found) {
00130 retval = false;
00131 break;
00132 }
00133 }
00134
00135 return retval;
00136 }
00137
00138 }