879: def __replace_next_larger(enum, value, last_index = nil)
880:
881: if enum.empty? or (value > enum[-1])
882: enum << value
883: return enum.size - 1
884: end
885:
886:
887: last_index ||= enum.size
888: first_index = 0
889: while (first_index <= last_index)
890: ii = (first_index + last_index) >> 1
891:
892: found = enum[ii]
893:
894: if value == found
895: return nil
896: elsif value > found
897: first_index = ii + 1
898: else
899: last_index = ii - 1
900: end
901: end
902:
903:
904:
905: enum[first_index] = value
906: return first_index
907: end