Module: Continuum

Defined in:
lib/memcache.rb,
lib/continuum_native.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



1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
# File 'lib/memcache.rb', line 1159

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