module Parslet::Source::RangeSearch
Mixin for arrays that implicitly give a number of ranges, where one range begins where the other one ends.
Example: [10, 20, 30] # would describe [0, 10], (10, 20], (20, 30]
Public Instance Methods
find_mid(left, right)
click to toggle source
# File lib/parslet/source/line_cache.rb, line 67 def find_mid(left, right) # NOTE: Jonathan Hinkle reported that when mathn is required, just # dividing and relying on the integer truncation is not enough. left + ((right - left) / 2).floor end
lbound(bound)
click to toggle source
Scans the array for the first number that is > than bound. Returns the index of that number.
# File lib/parslet/source/line_cache.rb, line 76 def lbound(bound) return nil if empty? return nil unless last > bound left = 0 right = size - 1 loop do mid = find_mid(left, right) if self[mid] > bound right = mid else # assert: self[mid] <= bound left = mid+1 end if right <= left return right end end end