Intersect our bitmap with the complement of the RHS and return true if ours changed.
| 941 | // Intersect our bitmap with the complement of the RHS and return true |
| 942 | // if ours changed. |
| 943 | bool intersectWithComplement(const SparseBitVector &RHS) |
| 944 | { |
| 945 | if (this == &RHS) |
| 946 | { |
| 947 | if (!empty()) |
| 948 | { |
| 949 | clear(); |
| 950 | return true; |
| 951 | } |
| 952 | return false; |
| 953 | } |
| 954 | |
| 955 | bool changed = false; |
| 956 | ElementListIter Iter1 = Elements.begin(); |
| 957 | ElementListConstIter Iter2 = RHS.Elements.begin(); |
| 958 | |
| 959 | // If either our bitmap or RHS is empty, we are done |
| 960 | if (Elements.empty() || RHS.Elements.empty()) |
| 961 | return false; |
| 962 | |
| 963 | // Loop through, intersecting as we go, erasing elements when necessary. |
| 964 | while (Iter2 != RHS.Elements.end()) |
| 965 | { |
| 966 | if (Iter1 == Elements.end()) |
| 967 | { |
| 968 | CurrElementIter = Elements.begin(); |
| 969 | return changed; |
| 970 | } |
| 971 | |
| 972 | if (Iter1->index() > Iter2->index()) |
| 973 | { |
| 974 | ++Iter2; |
| 975 | } |
| 976 | else if (Iter1->index() == Iter2->index()) |
| 977 | { |
| 978 | bool BecameZero; |
| 979 | changed |= Iter1->intersectWithComplement(*Iter2, BecameZero); |
| 980 | if (BecameZero) |
| 981 | { |
| 982 | ElementListIter IterTmp = Iter1; |
| 983 | ++Iter1; |
| 984 | Elements.erase(IterTmp); |
| 985 | } |
| 986 | else |
| 987 | { |
| 988 | ++Iter1; |
| 989 | } |
| 990 | ++Iter2; |
| 991 | } |
| 992 | else |
| 993 | { |
| 994 | ++Iter1; |
| 995 | } |
| 996 | } |
| 997 | CurrElementIter = Elements.begin(); |
| 998 | return changed; |
| 999 | } |
| 1000 |