lets_shard 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7ad5ad3bc12b55db4816cd5b729704a502f6365ee135f0bc8b789d9e0aed18b
4
- data.tar.gz: 7d08482f4ee12152db3ae2d09ac33400fd748844a34a44fc8aae088e13d63a41
3
+ metadata.gz: 5bf3cd5a20aaac93d6dda2fbba8f687b2329df22686d4beff2e0e4a2d77e4fa6
4
+ data.tar.gz: a3fd4bbd36b608a9b4f7ca804efe6b73a39fdce95637cc4b34a167d34b227efb
5
5
  SHA512:
6
- metadata.gz: 1b15660bfda65b7d4637c7c1a27f4cdf706318a1228e8693c1fc93c770b5ab84728835c86286e8a645be061eea147120482e87ce777ad9b021d60bdf23112242
7
- data.tar.gz: 214e8d1f9b116f9b0fa7305e398ceb384db071692d6da170242fb2278b4735697075f762f870c6909c9473fcc7bdec30f5851c8b164ab5fb03c6b3c9f4b254d8
6
+ metadata.gz: 31398727fda887d14c046b617400e23d71900fb18f47fd52589029dbaa3e2b6cb15522c1d39394029f4880a8ca29b80b7d1f83714de590464719ba9bd812888e
7
+ data.tar.gz: 63d6183bb1982df8c23fed7206fd42e9cf0a9111e973e8f54ed542e58fc487c9b04a1fdcb0d1e5dba97d510f50f855764ecc48aa1686b5032ef9a935d83bfd00
@@ -12,7 +12,7 @@ class LetsShard
12
12
 
13
13
  @objects = objects
14
14
  @weights = weights.any? ? weights : Array.new(@objects.size, 1)
15
- @slots = @objects.size < DEFAULT_SLOTS ? DEFAULT_SLOTS : @objects.size
15
+ @slots = [DEFAULT_SLOTS, weights.sum].max
16
16
 
17
17
  set_unit_weight!
18
18
  set_remainder_slots!
@@ -41,8 +41,9 @@ class LetsShard
41
41
  end_slot = start_slot + (@weights[index] * @unit_weight) - 1
42
42
 
43
43
  if @remainder_slots > 0
44
- end_slot += 1
45
- @remainder_slots -= 1
44
+ slots_to_add = [@weights[index], @remainder_slots].min
45
+ end_slot += slots_to_add
46
+ @remainder_slots -= slots_to_add
46
47
  end
47
48
 
48
49
  @shards << Shard.new(object, start_slot, end_slot)
@@ -51,12 +52,16 @@ class LetsShard
51
52
  end
52
53
  end
53
54
 
55
+ def weights_sum
56
+ @weights.inject(0, :+)
57
+ end
58
+
54
59
  def set_unit_weight!
55
- @unit_weight = @slots / @weights.inject(0, :+)
60
+ @unit_weight = @slots / weights_sum
56
61
  end
57
62
 
58
63
  def set_remainder_slots!
59
- @remainder_slots = @slots - (@unit_weight * @objects.size)
64
+ @remainder_slots = @slots - (@unit_weight * weights_sum)
60
65
  end
61
66
 
62
67
  def get_hkey(key)
@@ -1,3 +1,3 @@
1
1
  class LetsShard
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lets_shard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - oshboul