vendor/gems/diff-lcs-1.1.2/lib/diff/lcs.rb
def __replace_next_larger(enum, value, last_index = nil)
        # Off the end?
      if enum.empty? or (value > enum[-1])
        enum << value
        return enum.size - 1
      end

        # Binary search for the insertion point
      last_index ||= enum.size
      first_index = 0
      while (first_index <= last_index)
        ii = (first_index + last_index) >> 1

        found = enum[ii]

        if value == found
          return nil
        elsif value > found
          first_index = ii + 1
        else
          last_index = ii - 1
        end
      end

        # The insertion point is in first_index; overwrite the next larger
        # value.
      enum[first_index] = value
      return first_index
    end
# Find the place at which +value+ would normally be inserted into the
# Enumerable. If that place is already occupied by +value+, do nothing
# and return +nil+. If the place does not exist (i.e., it is off the end
# of the Enumerable), add it to the end. Otherwise, replace the element
# at that point with +value+. It is assumed that the Enumerable's values
# are numeric.
#
# This operation preserves the sort order.
Find the place at which +value+ would normally be inserted into the
Enumerable. If that place is already occupied by +value+, do nothing
and return +nil+. If the place does not exist , add it to the end. Otherwise, replace the element
at that point with +value+. It is assumed that the Enumerable's values
are numeric.

This operation preserves the sort order.
Find the place at which + value + would normally be inserted into the Enumerable . If that place is already occupied by + value + do nothing and return + nil + . If the place does not exist add it to the end . Otherwise replace the element at that point with + value + . It is assumed that the Enumerable ' s values are numeric . This operation preserves the sort order .
def __replace_next_larger(enum, value, last_index = nil)
      if enum.empty? or (value > enum[-1])
        enum << value
        return enum.size - 1
      end
      last_index ||= enum.size
      first_index = 0
      while (first_index <= last_index)
        ii = (first_index + last_index) >> 1
        found = enum[ii]
        if value == found
          return nil
        elsif value > found
          first_index = ii + 1
        else
          last_index = ii - 1
        end
      end
      enum[first_index] = value
      return first_index
    end
def __replace_next_larger ( enum , value , last_index = nil ) if enum . empty? or ( value > enum [ - 1 ] ) enum << value return enum . size - 1 end last_index ||= enum . size first_index = 0 while ( first_index <= last_index ) ii = ( first_index + last_index ) >> 1 found = enum [ ii ] if value == found return nil elsif value > found first_index = ii + 1 else last_index = ii - 1 end end enum [ first_index ] = value return first_index end
Find the place at which +value+ would normally be inserted into the
Enumerable.
Find the place at which + value + would normally be inserted into the Enumerable .
# Off the end? # Binary search for the insertion point # The insertion point is in first_index; overwrite the next larger # value.
enum
value
last_index