Remove SingleValueDocValuesFieldUpdates abstract class

This commit is contained in:
Ignacio Vera 2024-12-11 17:32:53 +01:00
parent b9385a8a29
commit 4d8771b0fe
2 changed files with 88 additions and 110 deletions

View File

@ -20,13 +20,10 @@ import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.BitSet;
import org.apache.lucene.util.BitSetIterator;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IntroSorter;
import org.apache.lucene.util.PriorityQueue;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.SparseFixedBitSet;
import org.apache.lucene.util.packed.PackedInts;
import org.apache.lucene.util.packed.PagedMutable;
@ -480,107 +477,4 @@ abstract class DocValuesFieldUpdates implements Accountable {
return hasValue;
}
}
abstract static class SingleValueDocValuesFieldUpdates extends DocValuesFieldUpdates {
private final BitSet bitSet;
private BitSet hasNoValue;
private boolean hasAtLeastOneValue;
protected SingleValueDocValuesFieldUpdates(
int maxDoc, long delGen, String field, DocValuesType type) {
super(maxDoc, delGen, field, type);
this.bitSet = new SparseFixedBitSet(maxDoc);
}
@Override
void add(int doc, long value) {
assert longValue() == value;
bitSet.set(doc);
this.hasAtLeastOneValue = true;
if (hasNoValue != null) {
hasNoValue.clear(doc);
}
}
@Override
void add(int doc, BytesRef value) {
assert binaryValue().equals(value);
bitSet.set(doc);
this.hasAtLeastOneValue = true;
if (hasNoValue != null) {
hasNoValue.clear(doc);
}
}
@Override
synchronized void reset(int doc) {
bitSet.set(doc);
this.hasAtLeastOneValue = true;
if (hasNoValue == null) {
hasNoValue = new SparseFixedBitSet(maxDoc);
}
hasNoValue.set(doc);
}
@Override
void add(int docId, Iterator iterator) {
throw new UnsupportedOperationException();
}
protected abstract BytesRef binaryValue();
protected abstract long longValue();
@Override
synchronized boolean any() {
return super.any() || hasAtLeastOneValue;
}
@Override
public long ramBytesUsed() {
return super.ramBytesUsed()
+ bitSet.ramBytesUsed()
+ (hasNoValue == null ? 0 : hasNoValue.ramBytesUsed());
}
@Override
Iterator iterator() {
BitSetIterator iterator = new BitSetIterator(bitSet, maxDoc);
return new DocValuesFieldUpdates.Iterator() {
@Override
public int docID() {
return iterator.docID();
}
@Override
public int nextDoc() {
return iterator.nextDoc();
}
@Override
long longValue() {
return SingleValueDocValuesFieldUpdates.this.longValue();
}
@Override
BytesRef binaryValue() {
return SingleValueDocValuesFieldUpdates.this.binaryValue();
}
@Override
long delGen() {
return delGen;
}
@Override
boolean hasValue() {
if (hasNoValue != null) {
return hasNoValue.get(docID()) == false;
}
return true;
}
};
}
}
}

View File

@ -17,8 +17,11 @@
package org.apache.lucene.index;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.util.BitSet;
import org.apache.lucene.util.BitSetIterator;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.SparseFixedBitSet;
import org.apache.lucene.util.packed.AbstractPagedMutable;
import org.apache.lucene.util.packed.PackedInts;
import org.apache.lucene.util.packed.PagedGrowableWriter;
@ -130,23 +133,104 @@ final class NumericDocValuesFieldUpdates extends DocValuesFieldUpdates {
+ RamUsageEstimator.NUM_BYTES_OBJECT_REF;
}
static class SingleValueNumericDocValuesFieldUpdates extends SingleValueDocValuesFieldUpdates {
static class SingleValueNumericDocValuesFieldUpdates extends DocValuesFieldUpdates {
private final long value;
private final BitSet bitSet;
private BitSet hasNoValue;
private boolean hasAtLeastOneValue;
SingleValueNumericDocValuesFieldUpdates(long delGen, String field, int maxDoc, long value) {
super(maxDoc, delGen, field, DocValuesType.NUMERIC);
this.bitSet = new SparseFixedBitSet(maxDoc);
this.value = value;
}
// pkg private for testing
long longValue() {
return value;
}
@Override
protected BytesRef binaryValue() {
void add(int doc, long value) {
assert this.value == value;
bitSet.set(doc);
this.hasAtLeastOneValue = true;
if (hasNoValue != null) {
hasNoValue.clear(doc);
}
}
@Override
void add(int doc, BytesRef value) {
throw new UnsupportedOperationException();
}
@Override
protected long longValue() {
return value;
synchronized void reset(int doc) {
bitSet.set(doc);
this.hasAtLeastOneValue = true;
if (hasNoValue == null) {
hasNoValue = new SparseFixedBitSet(maxDoc);
}
hasNoValue.set(doc);
}
@Override
void add(int docId, Iterator iterator) {
throw new UnsupportedOperationException();
}
@Override
synchronized boolean any() {
return super.any() || hasAtLeastOneValue;
}
@Override
public long ramBytesUsed() {
return super.ramBytesUsed()
+ bitSet.ramBytesUsed()
+ (hasNoValue == null ? 0 : hasNoValue.ramBytesUsed());
}
@Override
Iterator iterator() {
BitSetIterator iterator = new BitSetIterator(bitSet, maxDoc);
return new DocValuesFieldUpdates.Iterator() {
@Override
public int docID() {
return iterator.docID();
}
@Override
public int nextDoc() {
return iterator.nextDoc();
}
@Override
long longValue() {
return value;
}
@Override
BytesRef binaryValue() {
throw new UnsupportedOperationException();
}
@Override
long delGen() {
return delGen;
}
@Override
boolean hasValue() {
if (hasNoValue != null) {
return hasNoValue.get(docID()) == false;
}
return true;
}
};
}
}
}