| 140 | } |
| 141 | |
| 142 | bool |
| 143 | LUBndSet::intersect_full(Space& home, int mi, int ma) { |
| 144 | RangeList* p = nullptr; |
| 145 | RangeList* c = fst(); |
| 146 | |
| 147 | assert(c != nullptr); // Never intersect with an empty set |
| 148 | |
| 149 | // Skip ranges that are before mi |
| 150 | while (c != nullptr && c->max() < mi) { |
| 151 | _size -= c->width(); |
| 152 | RangeList *nc = c->next(); |
| 153 | p=c; c=nc; |
| 154 | } |
| 155 | if (c == nullptr) { |
| 156 | // Delete entire domain |
| 157 | fst()->dispose(home, lst()); |
| 158 | fst(nullptr); lst(nullptr); |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | bool changed = false; |
| 163 | if (c != fst()) { |
| 164 | fst()->dispose(home, p); |
| 165 | fst(c); |
| 166 | p = nullptr; |
| 167 | changed = true; |
| 168 | } |
| 169 | // We have found the first range that intersects with [mi,ma] |
| 170 | if (mi > c->min()) { |
| 171 | _size -= mi-c->min(); |
| 172 | c->min(mi); |
| 173 | changed = true; |
| 174 | } |
| 175 | |
| 176 | while (c != nullptr && c->max() <= ma) { |
| 177 | RangeList *nc = c->next(); |
| 178 | p=c; c=nc; |
| 179 | } |
| 180 | |
| 181 | if (c == nullptr) |
| 182 | return changed; |
| 183 | |
| 184 | RangeList* newlst = p; |
| 185 | if (ma >= c->min()) { |
| 186 | _size -= c->max() - ma; |
| 187 | c->max(ma); |
| 188 | newlst = c; |
| 189 | RangeList* nc = c->next(); |
| 190 | c->next(nullptr); |
| 191 | p=c; c=nc; |
| 192 | } else if (p != nullptr) { |
| 193 | p->next(nullptr); |
| 194 | } |
| 195 | if (c != nullptr) { |
| 196 | for (RangeList* cc = c ; cc != nullptr; cc = cc->next()) |
| 197 | _size -= cc->width(); |
| 198 | c->dispose(home, lst()); |
| 199 | } |