Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SingleValueDocValuesFieldUpdates abstract class (only one implementation) #14059

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
};
}
}
}
Loading