private int readIntoMap(
        Dex.Section in,
        TableOfContents.Section section,
        IndexMap indexMap,
        int index,
        TreeMap<T, List<Integer>> values,
        int dex) {
      int offset = in != null ? in.getPosition() : -1;
      if (index < section.size) {
        T v = read(in, indexMap, index);
        List<Integer> l = values.get(v);
        if (l == null) {
          l = new ArrayList<Integer>();
          values.put(v, l);
        }
        l.add(dex);
      }
      return offset;
    }
Merges already-sorted sections, reading one value from each dex into memory at a time.
android/android_framework/dex-maker/src/main/java/com/android/dx/merge/DexMerger.java