Skip to content

Commit

Permalink
Remove SingleValueDocValuesFieldUpdates abstract class (#14059)
Browse files Browse the repository at this point in the history
This abstract class has currently one implementation so this removes this indirection.
  • Loading branch information
iverase committed Jan 15, 2025
1 parent 4d26d23 commit fb0ed19
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@

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;

Expand Down Expand Up @@ -480,107 +477,4 @@ final boolean hasValue() {
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;
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -130,23 +133,104 @@ public long ramBytesUsed() {
+ 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;
}
};
}
}
}

0 comments on commit fb0ed19

Please sign in to comment.