|
|
@ -91,6 +91,31 @@ module Crystal::Scatter |
|
|
|
end |
|
|
|
return slices |
|
|
|
end |
|
|
|
|
|
|
|
def get_slices_for(data : String, n_last = 1 : Int32) |
|
|
|
n_rings = Array(Ring).new |
|
|
|
@lock.synchronize do |
|
|
|
t = @rings.size-n_last |
|
|
|
n_rings = @rings.skip( t > 0 ? t : 1 ) |
|
|
|
end |
|
|
|
h = hash_impl data |
|
|
|
space=UInt64::MAX/@shards |
|
|
|
targets = Array(UInt64).new |
|
|
|
(1..@shards).each do |
|
|
|
targets << h |
|
|
|
h+=space |
|
|
|
end |
|
|
|
|
|
|
|
ret = Array(Array(Slice)).new |
|
|
|
n_rings.each do |ring| |
|
|
|
slices = Array(Slice).new |
|
|
|
targets.each do |h| |
|
|
|
slices << get_slice_from_hash(ring, h) |
|
|
|
end |
|
|
|
ret << slices |
|
|
|
end |
|
|
|
return ret |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |