Sha256: b9cd0297fdccc37c36de8c071c7eb7be1a1f3f4e4ca9b2783f9a9b2896324b1f
Contents?: true
Size: 987 Bytes
Versions: 3
Compression:
Stored size: 987 Bytes
Contents
module Continuum POINTS_PER_SERVER = 160 # this is the default in libmemcached begin require 'binary_search' # try to load native extension rescue LoadError => e puts "Unable to load fast binary search, falling back to pure Ruby: #{e.message}" # slow but pure ruby version # Find the closest index in Continuum with value <= the given value 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 end class Entry attr_reader :value attr_reader :server def initialize(val, srv) @value = val @server = srv end def inspect "<#{value}, #{server.host}:#{server.port}>" end end end
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
mperham-memcache-client-1.6.1 | lib/continuum.rb |
mperham-memcache-client-1.6.2 | lib/continuum.rb |
memcache-client-1.6.2 | lib/continuum.rb |