Sha256: df850359eb3daa9ce445d9cb538cf4e1f828be6fd06164a6973c8ed96098363a
Contents?: true
Size: 837 Bytes
Versions: 4
Compression:
Stored size: 837 Bytes
Contents
# This file is distributed under New Relic's license terms. # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. # frozen_string_literal: true module NewRelic module Agent module RangeExtensions module_function def intersects?(r1, r2) r1.begin > r2.begin ? r2.cover?(r1.begin) : r1.cover?(r2.begin) end # Computes the amount of overlap between range and an array of ranges. # For efficiency, it assumes that range intersects with each of the # ranges in the ranges array. def compute_overlap(range, ranges) ranges.inject(0) do |memo, other| next memo unless intersects?(range, other) memo += ([range.end, other.end].min) - ([range.begin, other.begin].max) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems