Module: Continuum
- Defined in:
- lib/memcache.rb
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- POINTS_PER_SERVER =
this is the default in libmemcached
160
Class Method Summary collapse
-
.binary_search(ary, value, &block) ⇒ Object
Find the closest index in Continuum with value <= the given value.
Class Method Details
.binary_search(ary, value, &block) ⇒ Object
Find the closest index in Continuum with value <= the given value
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 |
# File 'lib/memcache.rb', line 1111 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 |