if (edit.isDelete) {
if (cmp != 0) throw new RuntimeException("Unexpected");
cur = cur.next();
} else {
MemDocRec newRec = new MemDocRec(prefix,
new SlicedBytes(edit.term,prefixLen),
edit.docId, null, null, 0);
result.append(newRec);
}
editIdx++;
} else { // means it's a segment push
BoundedDocRec subSegment = cur.down();
int startIdx = editIdx;
for(;editIdx<editLength; editIdx++) {
edit = edits.get(editIdx);
cmp = cur.compareTo(edit);
if (cmp <= 0) break;
}
applyDocEdits(edits.subList(startIdx, editIdx), subSegment, result);
if (edit.isDelete && cmp == 0) {
// do not add tail
editIdx++;
} else {
MemDocRec tail = new MemDocRec(cur.dr);
tail.down = null;
tail.downCt = 0;
result.append(tail);
}
cur = cur.next();
}
edit = (editIdx < edits.size()) ? edits.get(editIdx) : null;
}
}
while (cur != null) {
result.append(new MemDocRec(cur.dr));
cur = cur.next();
}
while (editIdx < edits.size()) {
edit = edits.get(editIdx++);
MemDocRec newRec = new MemDocRec(prefix,
new SlicedBytes(edit.term,prefixLen),
edit.docId, null, null, 0);
result.append(newRec);
}
}