rominparekh 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_r266716242
##########
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:
@rdsr - `bins.remove(maxBin)` returns a `boolean` and would not work as
you've suggested unless I use the index of the bin for removal. But to your
point, I'll work on making this code simpler.
I added the `null` check in case when the head of the bin is `null` but I
now realize, we might never hit this exception. I'll remove this.
----------------------------------------------------------------
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]