public List<IndexEntry> generateOrderedIndexArrayByMergingLogIterator(final LogEntryIterator segmentLogIterator,
                                                                          final LogEntryIterator confLogIterator) {
        LogEntry segmentEntry = null, confEntry = null;
        int segmentPosition = -1, confPosition = -1;
        final List<IndexEntry> indexEntries = new ArrayList<>();
        while (true) {
            // Pull next entry
            if (segmentEntry == null && segmentLogIterator != null && segmentLogIterator.hasNext()) {
                segmentEntry = segmentLogIterator.next();
                segmentPosition = segmentLogIterator.getReadPosition();
            }
            if (confEntry == null && confLogIterator != null && confLogIterator.hasNext()) {
                confEntry = confLogIterator.next();
                confPosition = confLogIterator.getReadPosition();
            }
            if (segmentEntry == null && confEntry == null) {
                break;
            }
            // Merge
            if (segmentEntry != null && confEntry != null) {
                if (segmentEntry.getId().getIndex() < confEntry.getId().getIndex()) {
                    indexEntries.add(new IndexEntry(segmentEntry.getId().getIndex(), segmentPosition,
                        IndexType.IndexSegment.getType()));
                    segmentEntry = null;
                } else {
                    indexEntries.add(new IndexEntry(confEntry.getId().getIndex(), confPosition, IndexType.IndexConf
                        .getType()));
                    confEntry = null;
                }
            } else {
                indexEntries.add(segmentEntry != null ? new IndexEntry(segmentEntry.getId().getIndex(),
                    segmentPosition, IndexType.IndexSegment.getType()) : new IndexEntry(confEntry.getId().getIndex(),
                    confPosition, IndexType.IndexConf.getType()));
                segmentEntry = confEntry = null;
            }
        }
        return indexEntries;
    }
Generate ordered index entry array by using tow-way merging algorithm
@param segmentLogIterator segment log iterator
@param confLogIterator conf log iterator
@return ordered index entry array
jraft-extension/java-log-storage-impl/src/main/java/com/alipay/sofa/jraft/storage/LogitLogStorage.java