From a1a3bd430bb03776ab5e422efa2b89f96b07380f Mon Sep 17 00:00:00 2001 From: Archivist Date: Sun, 12 Aug 2018 13:31:12 +0200 Subject: [PATCH] Added an history feature --- README.md | 4 ++-- shard.yml | 2 +- src/crystal-scatter/metaring.cr | 25 +++++++++++++++++++++++++ src/crystal-scatter/version.cr | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a65e178..1b42596 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # crystal-scatter - +Release candidate for v0.1 "John Scott" ## Installation @@ -10,7 +10,7 @@ Add this to your application's `shard.yml`: dependencies: crystal-scatter: git: https://git.nekoit.xyz/Archivist/crystal-scatter - version: ~> 0.1.0-rc1 + version: ~> 0.1.0-rc2 ``` ## Usage diff --git a/shard.yml b/shard.yml index afa8c91..aab8963 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: crystal-scatter -version: 0.1.0-rc1 +version: 0.1.0-rc2 authors: - Ludovic 'Archivist' Lagouardette diff --git a/src/crystal-scatter/metaring.cr b/src/crystal-scatter/metaring.cr index 18898ae..196f542 100644 --- a/src/crystal-scatter/metaring.cr +++ b/src/crystal-scatter/metaring.cr @@ -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 \ No newline at end of file diff --git a/src/crystal-scatter/version.cr b/src/crystal-scatter/version.cr index ff11827..34bceb9 100644 --- a/src/crystal-scatter/version.cr +++ b/src/crystal-scatter/version.cr @@ -1,3 +1,3 @@ module Crystal::Scatter - VERSION = "0.1.0-rc1" + VERSION = "0.1.0-rc2" end