mirror of https://github.com/apache/lucene.git
Move MergeState.DocMap to a FunctionalInterface (#12836)
This change converts MergeState to an interface to make use of lambda expressions.
This commit is contained in:
parent
0ec7fdb3b5
commit
981339be04
|
@ -5199,12 +5199,9 @@ public class IndexWriter
|
||||||
for (CodecReader reader : mergeReaders) {
|
for (CodecReader reader : mergeReaders) {
|
||||||
final int currentDocBase = docBase;
|
final int currentDocBase = docBase;
|
||||||
reorderDocMaps[i] =
|
reorderDocMaps[i] =
|
||||||
new MergeState.DocMap() {
|
docID -> {
|
||||||
@Override
|
Objects.checkIndex(docID, reader.maxDoc());
|
||||||
public int get(int docID) {
|
return docMap.oldToNew(currentDocBase + docID);
|
||||||
Objects.checkIndex(docID, reader.maxDoc());
|
|
||||||
return docMap.oldToNew(currentDocBase + docID);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
i++;
|
i++;
|
||||||
docBase += reader.maxDoc();
|
docBase += reader.maxDoc();
|
||||||
|
@ -5236,15 +5233,7 @@ public class IndexWriter
|
||||||
docMaps = new MergeState.DocMap[reorderDocMaps.length];
|
docMaps = new MergeState.DocMap[reorderDocMaps.length];
|
||||||
for (int i = 0; i < docMaps.length; ++i) {
|
for (int i = 0; i < docMaps.length; ++i) {
|
||||||
MergeState.DocMap reorderDocMap = reorderDocMaps[i];
|
MergeState.DocMap reorderDocMap = reorderDocMaps[i];
|
||||||
docMaps[i] =
|
docMaps[i] = docID -> compactionDocMap.get(reorderDocMap.get(docID));
|
||||||
new MergeState.DocMap() {
|
|
||||||
@Override
|
|
||||||
public int get(int docID) {
|
|
||||||
int reorderedDocId = reorderDocMap.get(docID);
|
|
||||||
int compactedDocId = compactionDocMap.get(reorderedDocId);
|
|
||||||
return compactedDocId;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,16 +177,13 @@ public class MergeState {
|
||||||
|
|
||||||
final int docBase = totalDocs;
|
final int docBase = totalDocs;
|
||||||
docMaps[i] =
|
docMaps[i] =
|
||||||
new DocMap() {
|
docID -> {
|
||||||
@Override
|
if (liveDocs == null) {
|
||||||
public int get(int docID) {
|
return docBase + docID;
|
||||||
if (liveDocs == null) {
|
} else if (liveDocs.get(docID)) {
|
||||||
return docBase + docID;
|
return docBase + (int) delDocMap.get(docID);
|
||||||
} else if (liveDocs.get(docID)) {
|
} else {
|
||||||
return docBase + (int) delDocMap.get(docID);
|
return -1;
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
totalDocs += reader.numDocs();
|
totalDocs += reader.numDocs();
|
||||||
|
@ -242,13 +239,10 @@ public class MergeState {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A map of doc IDs. */
|
/** A map of doc IDs. */
|
||||||
public abstract static class DocMap {
|
@FunctionalInterface
|
||||||
/** Sole constructor. (For invocation by subclass constructors, typically implicit.) */
|
public interface DocMap {
|
||||||
// Explicitly declared so that we have non-empty javadoc
|
|
||||||
protected DocMap() {}
|
|
||||||
|
|
||||||
/** Return the mapped docID or -1 if the given doc is not mapped. */
|
/** Return the mapped docID or -1 if the given doc is not mapped. */
|
||||||
public abstract int get(int docID);
|
int get(int docID);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PackedLongValues removeDeletes(final int maxDoc, final Bits liveDocs) {
|
static PackedLongValues removeDeletes(final int maxDoc, final Bits liveDocs) {
|
||||||
|
|
|
@ -122,14 +122,11 @@ final class MultiSorter {
|
||||||
final PackedLongValues remapped = builders[i].build();
|
final PackedLongValues remapped = builders[i].build();
|
||||||
final Bits liveDocs = readers.get(i).getLiveDocs();
|
final Bits liveDocs = readers.get(i).getLiveDocs();
|
||||||
docMaps[i] =
|
docMaps[i] =
|
||||||
new MergeState.DocMap() {
|
docID -> {
|
||||||
@Override
|
if (liveDocs == null || liveDocs.get(docID)) {
|
||||||
public int get(int docID) {
|
return (int) remapped.get(docID);
|
||||||
if (liveDocs == null || liveDocs.get(docID)) {
|
} else {
|
||||||
return (int) remapped.get(docID);
|
return -1;
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,16 +60,7 @@ public class TestDocIDMerger extends LuceneTestCase {
|
||||||
for (int i = 0; i < subCount; i++) {
|
for (int i = 0; i < subCount; i++) {
|
||||||
int maxDoc = TestUtil.nextInt(random(), 1, 1000);
|
int maxDoc = TestUtil.nextInt(random(), 1, 1000);
|
||||||
final int docBase = valueStart;
|
final int docBase = valueStart;
|
||||||
subs.add(
|
subs.add(new TestSubUnsorted(docID -> docBase + docID, maxDoc, valueStart));
|
||||||
new TestSubUnsorted(
|
|
||||||
new MergeState.DocMap() {
|
|
||||||
@Override
|
|
||||||
public int get(int docID) {
|
|
||||||
return docBase + docID;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
maxDoc,
|
|
||||||
valueStart));
|
|
||||||
valueStart += maxDoc;
|
valueStart += maxDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,15 +158,12 @@ public class TestDocIDMerger extends LuceneTestCase {
|
||||||
final int[] docMap = completedSubs.get(i);
|
final int[] docMap = completedSubs.get(i);
|
||||||
subs.add(
|
subs.add(
|
||||||
new TestSubSorted(
|
new TestSubSorted(
|
||||||
new MergeState.DocMap() {
|
docID -> {
|
||||||
@Override
|
int mapped = docMap[docID];
|
||||||
public int get(int docID) {
|
if (liveDocs == null || liveDocs.get(mapped)) {
|
||||||
int mapped = docMap[docID];
|
return mapped;
|
||||||
if (liveDocs == null || liveDocs.get(mapped)) {
|
} else {
|
||||||
return mapped;
|
return -1;
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
docMap.length,
|
docMap.length,
|
||||||
|
|
|
@ -734,13 +734,7 @@ public class TestBKD extends LuceneTestCase {
|
||||||
docMaps = new ArrayList<>();
|
docMaps = new ArrayList<>();
|
||||||
}
|
}
|
||||||
final int curDocIDBase = lastDocIDBase;
|
final int curDocIDBase = lastDocIDBase;
|
||||||
docMaps.add(
|
docMaps.add(docID1 -> curDocIDBase + docID1);
|
||||||
new MergeState.DocMap() {
|
|
||||||
@Override
|
|
||||||
public int get(int docID) {
|
|
||||||
return curDocIDBase + docID;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Runnable finalizer = w.finish(out, out, out);
|
Runnable finalizer = w.finish(out, out, out);
|
||||||
toMerge.add(out.getFilePointer());
|
toMerge.add(out.getFilePointer());
|
||||||
finalizer.run();
|
finalizer.run();
|
||||||
|
@ -770,13 +764,7 @@ public class TestBKD extends LuceneTestCase {
|
||||||
toMerge.add(out.getFilePointer());
|
toMerge.add(out.getFilePointer());
|
||||||
finalizer.run();
|
finalizer.run();
|
||||||
final int curDocIDBase = lastDocIDBase;
|
final int curDocIDBase = lastDocIDBase;
|
||||||
docMaps.add(
|
docMaps.add(docID -> curDocIDBase + docID);
|
||||||
new MergeState.DocMap() {
|
|
||||||
@Override
|
|
||||||
public int get(int docID) {
|
|
||||||
return curDocIDBase + docID;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
in = dir.openInput("bkd", IOContext.DEFAULT);
|
in = dir.openInput("bkd", IOContext.DEFAULT);
|
||||||
|
|
Loading…
Reference in New Issue