avoid casting to int when comparing longs

This commit is contained in:
Craig Raw 2020-10-27 11:11:15 +02:00
parent 401d3b8bfb
commit 67c76c3b28
2 changed files with 2 additions and 2 deletions

View file

@ -34,7 +34,7 @@ public class BnBUtxoSelector implements UtxoSelector {
return Collections.emptyList(); return Collections.emptyList();
} }
utxoPool.sort((a, b) -> (int)(b.getEffectiveValue() - a.getEffectiveValue())); utxoPool.sort((a, b) -> Long.compare(b.getEffectiveValue(), a.getEffectiveValue()));
long currentWasteValue = 0; long currentWasteValue = 0;
ArrayDeque<Boolean> bestSelection = null; ArrayDeque<Boolean> bestSelection = null;

View file

@ -50,7 +50,7 @@ public class KnapsackUtxoSelector implements UtxoSelector {
//We now have a list of UTXOs that are all smaller than the target + MIN_CHANGE, but together sum to greater than actualTargetValue //We now have a list of UTXOs that are all smaller than the target + MIN_CHANGE, but together sum to greater than actualTargetValue
// Solve subset sum by stochastic approximation // Solve subset sum by stochastic approximation
applicableGroups.sort((a, b) -> (int)(b.getEffectiveValue() - a.getEffectiveValue())); applicableGroups.sort((a, b) -> Long.compare(b.getEffectiveValue(), a.getEffectiveValue()));
boolean[] bestSelection = new boolean[applicableGroups.size()]; boolean[] bestSelection = new boolean[applicableGroups.size()];
long bestValue = findApproximateBestSubset(applicableGroups, totalLower, actualTargetValue, bestSelection); long bestValue = findApproximateBestSubset(applicableGroups, totalLower, actualTargetValue, bestSelection);