bool operator == (const Value::Ranges& _left, const Value::Ranges& _right) { Value::Ranges left; coalesce(&left, _left); Value::Ranges right; coalesce(&right, _right); if (left.range_size() == right.range_size()) { for (int i = 0; i < left.range_size(); i++) { // Make sure this range is equal to a range in the right. bool found = false; for (int j = 0; j < right.range_size(); j++) { if (left.range(i).begin() == right.range(j).begin() && left.range(i).end() == right.range(j).end()) { found = true; break; } } if (!found) { return false; } } return true; } return false; }
bool operator <= (const Value::Ranges& _left, const Value::Ranges& _right) { Value::Ranges left; coalesce(&left, _left); Value::Ranges right; coalesce(&right, _right); for (int i = 0; i < left.range_size(); i++) { // Make sure this range is a subset of a range in right. bool matched = false; for (int j = 0; j < right.range_size(); j++) { if (left.range(i).begin() >= right.range(j).begin() && left.range(i).end() <= right.range(j).end()) { matched = true; break; } } if (!matched) { return false; } } return true; }
Value::Ranges operator + (const Value::Ranges& left, const Value::Ranges& right) { Value::Ranges result; for (int i = 0; i < left.range_size(); i++) { coalesce(&result, left.range(i)); } for (int i = 0; i < right.range_size(); i++) { coalesce(&result, right.range(i)); } return result; }
// Coalesce the given un-coalesced 'uranges' into already coalesced 'ranges'. static void coalesce(Value::Ranges* ranges, const Value::Ranges& uranges) { // Note that we assume that ranges has already been coalesced. for (int i = 0; i < uranges.range_size(); i++) { coalesce(ranges, uranges.range(i)); } }