class IndexBaseBuilder {

    private final TreeMap<String, Integer> baseByIndex = new TreeMap<>();

    public void allocate(String index, IntIndexedContainer shards) {<FILL_FUNCTION_BODY>}

    public TreeMap<String, Integer> build() {
        int currentBase = 0;
        for (Map.Entry<String, Integer> entry : baseByIndex.entrySet()) {
            Integer maxId = entry.getValue();
            entry.setValue(currentBase);
            currentBase += maxId + 1;
        }
        return baseByIndex;
    }

    private static int getMax(IntIndexedContainer shards) {
        int max = -1;
        for (IntCursor shard: shards) {
            if (shard.value > max) {
                max = shard.value;
            }
        }
        return max;
    }
}

        if (shards.isEmpty()) {
            return;
        }
        Integer currentMax = baseByIndex.get(index);
        int newMax = getMax(shards);
        if (currentMax == null || currentMax < newMax) {
            baseByIndex.put(index, newMax);
        }
    
<no_super_class>