@Override
            public int allocate(Bucket<?> bucket) {
                int index = -1;
                int lowestSize = Integer.MAX_VALUE;

                for (BucketPartition<?> partition : bucket.getPartitions()) {
                    int size = partition.size();
                    int i = partition.getPartitionIndex();

                    if (size == 0) {
                        return i;
                    }

                    if (size < lowestSize) {
                        lowestSize = size;
                        index = i;
                    }
                }

                if (index == -1) {
                    throw new AssertionError();
                }
                return index;
            }
Some standard partitioning strategies for use in {@link Bucket}s.
helper/src/main/java/me/lucko/helper/bucket/partitioning/PartitioningStrategies.java