Class: TypeProf::CodeRangeTable
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Inherits: | Object |
Defined in: | lib/typeprof/code-range.rb |
Class Method Summary
- .new(list = []) ⇒ CodeRangeTable constructor
Instance Method Summary
Constructor Details
.new(list = []) ⇒ CodeRangeTable
# File 'lib/typeprof/code-range.rb', line 104
def initialize(list = []) @list = list # Array[Entry] end
Instance Method Details
#[](loc)
[ GitHub ]# File '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)
[ GitHub ]# File '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