src/common/values.cpp
// Coalesce the given 'range' into already coalesced 'ranges'.
Coalesce the given 'range' into already coalesced 'ranges'.
Coalesce the given ' range ' into already coalesced ' ranges ' .
static void coalesce(Value::Ranges* ranges, const Value::Range& range)
{
  Value::Ranges result;
  Value::Range temp = range;
  for (int i = 0; i < ranges->range_size(); i++) {
    const Value::Range& current = ranges->range(i);
    if (current.begin() <= range.end() + 1 &&
        current.end() >= range.begin() - 1) {
      temp.set_begin(min(temp.begin(), min(range.begin(), current.begin())));
      temp.set_end(max(temp.end(), max(range.end(), current.end())));
    } else { 
      result.add_range()->MergeFrom(current);
    }
  }
  result.add_range()->MergeFrom(temp);
  *ranges = result;
}
static void coalesce ( Value :: Ranges * ranges , const Value :: Range & range ) { Value :: Ranges result ; Value :: Range temp = range ; for ( int i = 0 ; i < ranges -> range_size ( ) ; i ++ ) { const Value :: Range & current = ranges -> range ( i ) ; if ( current . begin ( ) <= range . end ( ) + 1 && current . end ( ) >= range . begin ( ) - 1 ) { temp . set_begin ( min ( temp . begin ( ) , min ( range . begin ( ) , current . begin ( ) ) ) ) ; temp . set_end ( max ( temp . end ( ) , max ( range . end ( ) , current . end ( ) ) ) ) ; } else { result . add_range ( ) -> MergeFrom ( current ) ; } } result . add_range ( ) -> MergeFrom ( temp ) ; * ranges = result ; }
Coalesce the given 'range' into already coalesced 'ranges'.
Coalesce the given ' range ' into already coalesced ' ranges ' .
// Note that we assume that ranges has already been coalesced. // Check if current and range overlap. Note, we only need to // compare with range and not with temp to check for overlap // because we expect ranges to be coalesced to begin with! // current:   |   | // range:       |   | // range:   |   | // Update temp with new boundaries. // No overlap.