# File lib/rubytorrent/package.rb, line 134 def fill(r) raise ArgumentError, "#{r} outside of domain #@domain" unless @domain.rss? r Covering.new(@domain, @ranges.inject([]) do |set, x| ## r contains the result of the continuing merge. if r is nil, ## then we've already added it, so we just copy x. if r.nil? then set + [x] else ## otoh, if r is there, we try and merge in the current ## element. if r.rcont? x ## if we can merge, keep the union in r and don't add ## anything r = r.runion x set ## if we can't merge it, we'll see if it's time to add it. we ## know that r and x don't overlap because r.mergable?(x) was ## false, so we can simply compare the start points to see ## whether it should come before x. elsif r.first < x.first s = set + [r, x] # add both r = nil s else set + [x] ## no merging or adding, so we just copy x. end end ## if 'r' still hasn't been added, it should be the last element, ## we add it here. end.push(r).compact) end