rdblue commented on a change in pull request #117: Sorts bin packing by weights 
in descending order
URL: https://github.com/apache/incubator-iceberg/pull/117#discussion_r266528832
 
 

 ##########
 File path: core/src/main/java/com/netflix/iceberg/util/BinPacking.java
 ##########
 @@ -107,7 +113,22 @@ public boolean hasNext() {
           bins.addLast(bin);
 
           if (bins.size() > lookback) {
-            return ImmutableList.copyOf(bins.removeFirst().items());
+            if (expensiveTaskFirst) {
+              Bin maxBin = null;
+
+              // Iterate through all bins looking for one with maximum weight, 
taking O(n) time.
+              for (Bin currBin : bins) {
+                maxBin = maxBin == null ? currBin : (maxBin.weight() >= 
currBin.weight() ? maxBin : currBin);
+              }
+              // Sanity checks: we have resolved maxBin and removed it from 
list of bins.
+              if (maxBin != null && bins.remove(maxBin)) {
 
 Review comment:
   I agree here, too. I think this block can be simplified quite a bit.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to