class method self.binary_search

Ruby on Rails 2.3.18

Since v2.3.18 Last seen in v2.3.18

Signature

self.binary_search(ary, value, &block)

Find the closest index in Continuum with value <= the given value

Parameters

ary req
value req
block block
Source
# File activesupport/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb, line 1073
  def self.binary_search(ary, value, &block)
    upper = ary.size - 1
    lower = 0
    idx = 0

    while(lower <= upper) do
      idx = (lower + upper) / 2
      comp = ary[idx].value <=> value

      if comp == 0
        return idx
      elsif comp > 0
        upper = idx - 1
      else
        lower = idx + 1
      end
    end
    return upper
  end

Defined in activesupport/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb line 1073 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Continuum

Type at least 2 characters to search.

↑↓ navigate · open · esc close