Split two-element array into proper variables

This commit is contained in:
Yannick Welsch 2015-12-28 10:02:52 +01:00
parent c6cf84336f
commit 507bb11345
1 changed files with 5 additions and 4 deletions

View File

@ -173,7 +173,8 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
private final float indexBalance; private final float indexBalance;
private final float shardBalance; private final float shardBalance;
private final float[] theta; private final float theta0;
private final float theta1;
public WeightFunction(float indexBalance, float shardBalance) { public WeightFunction(float indexBalance, float shardBalance) {
@ -181,7 +182,8 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
if (sum <= 0.0f) { if (sum <= 0.0f) {
throw new IllegalArgumentException("Balance factors must sum to a value > 0 but was: " + sum); throw new IllegalArgumentException("Balance factors must sum to a value > 0 but was: " + sum);
} }
theta = new float[]{shardBalance / sum, indexBalance / sum}; theta0 = shardBalance / sum;
theta1 = indexBalance / sum;
this.indexBalance = indexBalance; this.indexBalance = indexBalance;
this.shardBalance = shardBalance; this.shardBalance = shardBalance;
} }
@ -189,8 +191,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
public float weight(Operation operation, Balancer balancer, ModelNode node, String index) { public float weight(Operation operation, Balancer balancer, ModelNode node, String index) {
final float weightShard = (node.numShards() - balancer.avgShardsPerNode()); final float weightShard = (node.numShards() - balancer.avgShardsPerNode());
final float weightIndex = (node.numShards(index) - balancer.avgShardsPerNode(index)); final float weightIndex = (node.numShards(index) - balancer.avgShardsPerNode(index));
assert theta != null; return theta0 * weightShard + theta1 * weightIndex;
return theta[0] * weightShard + theta[1] * weightIndex;
} }
} }