pool_balancing 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/pool_balancing.rb +7 -7
- data/pool_balancing.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/pool_balancing.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class PoolBalancing
|
2
2
|
def self.balance(values, nbpools)
|
3
|
-
values.sort! { |a,b| b <=> a }
|
3
|
+
values.sort! { |a,b| b[0] <=> a[0] }
|
4
4
|
pools = Array.new( nbpools ) { Array.new }
|
5
5
|
poolsum = Array.new( nbpools, 0 )
|
6
6
|
out = Array.new
|
@@ -8,7 +8,7 @@ class PoolBalancing
|
|
8
8
|
ind = 0; dir = 1
|
9
9
|
values.each do |val|
|
10
10
|
pools[ind] << val
|
11
|
-
poolsum[ind] += val
|
11
|
+
poolsum[ind] += val[0]
|
12
12
|
ind += dir;
|
13
13
|
if( ind == nbpools ) then ind = nbpools-1; dir = -1; end
|
14
14
|
if( ind == -1 ) then ind = 0; dir = 1; end
|
@@ -17,17 +17,17 @@ class PoolBalancing
|
|
17
17
|
while out.length < (nbpools-1)
|
18
18
|
minmax = poolsum.each_with_index.minmax.map{ |t| t[1] }
|
19
19
|
diff = poolsum[minmax[1]] - poolsum[minmax[0]]
|
20
|
-
return pools if diff <= 1 && out.empty?
|
20
|
+
return pools.map { |p| p.map { |v| v[1] } } if diff <= 1 && out.empty?
|
21
21
|
|
22
22
|
ind = 0
|
23
23
|
delete = true
|
24
24
|
while ind < pools[minmax[1]].length && delete == true
|
25
|
-
maxval = pools[minmax[1]][ind]
|
26
|
-
minval = pools[minmax[0]][ind]
|
25
|
+
maxval = pools[minmax[1]][ind][0]
|
26
|
+
minval = pools[minmax[0]][ind][0]
|
27
27
|
|
28
28
|
if (poolsum[minmax[1]] - 2 * maxval + 2 * minval - poolsum[minmax[0]]).abs < diff
|
29
|
-
pools[minmax[1]][ind] = minval
|
30
|
-
pools[minmax[0]][ind] = maxval
|
29
|
+
pools[minmax[1]][ind][0] = minval
|
30
|
+
pools[minmax[0]][ind][0] = maxval
|
31
31
|
poolsum[minmax[1]] += (minval - maxval)
|
32
32
|
poolsum[minmax[0]] += (maxval - minval)
|
33
33
|
delete = false
|
data/pool_balancing.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pool_balancing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash:
|
128
|
+
hash: -1707228460819962080
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
none: false
|
131
131
|
requirements:
|