class TypeProf::CodeRangeTable

Constants

Entry

Public Class Methods

new(list = []) click to toggle source
# File typeprof-0.21.3/lib/typeprof/code-range.rb, line 104
def initialize(list = [])
  @list = list # Array[Entry]
end

Public Instance Methods

[](loc) click to toggle source
# File typeprof-0.21.3/lib/typeprof/code-range.rb, line 133
def [](loc)
  e = @list.bsearch {|e| e.range.last > loc }
  if e && e.range.contain_loc?(loc)
    return e.children[loc] || e.value
  end
  return nil
end
[]=(range, value) click to toggle source
# File typeprof-0.21.3/lib/typeprof/code-range.rb, line 108
def []=(range, value)
  i_b = @list.bsearch_index {|e| e.range.last > range.first } || @list.size
  i_e = @list.bsearch_index {|e| e.range.first >= range.last } || @list.size
  if i_b < i_e
    # for all i in i_b...i_e, @list[i] overlaps with the range
    if i_e - i_b == 1
      if range.contain?(@list[i_b].range)
        @list[i_b] = Entry[range, value, CodeRangeTable.new(@list[i_b, 1])]
      elsif @list[i_b].range.contain?(range)
        @list[i_b].children[range] = value
      else
        raise
      end
    else
      if range.contain?(@list[i_b].range) && range.contain?(@list[i_e - 1].range)
        @list[i_b...i_e] = [Entry[range, value, CodeRangeTable.new(@list[i_b...i_e])]]
      else
        raise
      end
    end
  else
    @list[i_b, 0] = [Entry[range, value, CodeRangeTable.new]]
  end
end