use of org.apache.lucene.util.mutable.MutableValueInt in project lucene-solr by apache.
the class IntDocValues method getValueFiller.
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueInt mval = new MutableValueInt();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) throws IOException {
mval.value = intVal(doc);
mval.exists = exists(doc);
}
};
}
use of org.apache.lucene.util.mutable.MutableValueInt in project lucene-solr by apache.
the class IntFieldSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final NumericDocValues arr = getNumericDocValues(context, readerContext);
return new IntDocValues(this) {
int lastDocID;
private int getValueForDoc(int doc) throws IOException {
if (doc < lastDocID) {
throw new IllegalArgumentException("docs were sent out-of-order: lastDocID=" + lastDocID + " vs docID=" + doc);
}
lastDocID = doc;
int curDocID = arr.docID();
if (doc > curDocID) {
curDocID = arr.advance(doc);
}
if (doc == curDocID) {
return (int) arr.longValue();
} else {
return 0;
}
}
@Override
public int intVal(int doc) throws IOException {
return getValueForDoc(doc);
}
@Override
public String strVal(int doc) throws IOException {
return Integer.toString(intVal(doc));
}
@Override
public boolean exists(int doc) throws IOException {
getValueForDoc(doc);
return arr.docID() == doc;
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueInt mval = new MutableValueInt();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) throws IOException {
mval.value = getValueForDoc(doc);
mval.exists = arr.docID() == doc;
}
};
}
};
}
use of org.apache.lucene.util.mutable.MutableValueInt in project lucene-solr by apache.
the class OrdFieldSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final int off = readerContext.docBase;
final LeafReader r;
Object o = context.get("searcher");
if (o instanceof SolrIndexSearcher) {
SolrIndexSearcher is = (SolrIndexSearcher) o;
SchemaField sf = is.getSchema().getFieldOrNull(field);
if (sf != null && sf.hasDocValues() == false && sf.multiValued() == false && sf.getType().getNumberType() != null) {
// it's a single-valued numeric field: we must currently create insanity :(
List<LeafReaderContext> leaves = is.getIndexReader().leaves();
LeafReader[] insaneLeaves = new LeafReader[leaves.size()];
int upto = 0;
for (LeafReaderContext raw : leaves) {
insaneLeaves[upto++] = Insanity.wrapInsanity(raw.reader(), field);
}
r = SlowCompositeReaderWrapper.wrap(new MultiReader(insaneLeaves));
} else {
// reuse ordinalmap
r = ((SolrIndexSearcher) o).getSlowAtomicReader();
}
} else {
IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader();
r = SlowCompositeReaderWrapper.wrap(topReader);
}
// if it's e.g. tokenized/multivalued, emulate old behavior of single-valued fc
final SortedDocValues sindex = SortedSetSelector.wrap(DocValues.getSortedSet(r, field), SortedSetSelector.Type.MIN);
return new IntDocValues(this) {
private int lastDocID;
private int getOrdForDoc(int docID) throws IOException {
if (docID < lastDocID) {
throw new IllegalArgumentException("docs out of order: lastDocID=" + lastDocID + " docID=" + docID);
}
if (docID > sindex.docID()) {
sindex.advance(docID);
}
if (docID == sindex.docID()) {
return sindex.ordValue();
} else {
return -1;
}
}
protected String toTerm(String readableValue) {
return readableValue;
}
@Override
public int intVal(int doc) throws IOException {
return getOrdForDoc(doc + off);
}
@Override
public int ordVal(int doc) throws IOException {
return getOrdForDoc(doc + off);
}
@Override
public int numOrd() {
return sindex.getValueCount();
}
@Override
public boolean exists(int doc) throws IOException {
return getOrdForDoc(doc + off) != 0;
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueInt mval = new MutableValueInt();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) throws IOException {
mval.value = getOrdForDoc(doc);
mval.exists = mval.value != 0;
}
};
}
};
}
use of org.apache.lucene.util.mutable.MutableValueInt in project crate by crate.
the class CopyOnWriteHashMap method copyAndPut.
/**
* Associate <code>key</code> with <code>value</code> and return a new copy
* of the hash table. The current hash table is not modified.
*/
public CopyOnWriteHashMap<K, V> copyAndPut(K key, V value) {
if (key == null) {
throw new IllegalArgumentException("null keys are not supported");
}
if (value == null) {
throw new IllegalArgumentException("null values are not supported");
}
final int hash = key.hashCode();
final MutableValueInt newValue = new MutableValueInt();
final InnerNode<K, V> newRoot = root.put(key, hash, TOTAL_HASH_BITS, value, newValue);
final int newSize = size + newValue.value;
return new CopyOnWriteHashMap<>(newRoot, newSize);
}
Aggregations