module Sprockets::SourceMapUtils

def bsearch_mappings(mappings, offset, from = 0, to = mappings.size - 1)

Returns mapping Hash object.

offset - Array [line, column]
mappings - Array of mapping Hash objects

Public: Search Array of mappings for closest offset.
def bsearch_mappings(mappings, offset, from = 0, to = mappings.size - 1)
  mid = (from + to) / 2
  if from > to
    return from < 1 ? nil : mappings[from-1]
  end
  case compare_source_offsets(offset, mappings[mid][:generated])
  when 0
    mappings[mid]
  when -1
    bsearch_mappings(mappings, offset, from, mid - 1)
  when 1
    bsearch_mappings(mappings, offset, mid + 1, to)
  end
end