Module: Continuum

Defined in:
lib/active_support/vendor/memcache-client-1.7.4/memcache.rb

Defined Under Namespace

Classes: Entry

Constant Summary collapse

POINTS_PER_SERVER =

this is the default in libmemcached

160

Class Method Summary collapse

Class Method Details

.binary_search(ary, value, &block) ⇒ Object

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



1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
# File '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