Sha256: 6320dc9e22adf7dc47105df83e2e2ac55b019af2052358008ade40974c936592
Contents?: true
Size: 879 Bytes
Versions: 5
Compression:
Stored size: 879 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 ? range.end : other.end) - (range.begin > other.begin ? range.begin : other.begin) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems