@Override protected int compare(int i, int j) { // increasing docID order: // NOTE: we can have ties here, when the same docID was updated in the same segment, in which case we rely on sort being // stable and preserving original order so the last update to that docID wins return Long.compare(docs.get(i)>>>1, docs.get(j)>>>1); } }.sort(0, size);
@Override public final int nextDoc() { if (idx >= size) { return doc = DocIdSetIterator.NO_MORE_DOCS; } long longDoc = docs.get(idx); ++idx; for (; idx < size; idx++) { // scan forward to last update to this doc final long nextLongDoc = docs.get(idx); if ((longDoc >>> 1) != (nextLongDoc >>> 1)) { break; } longDoc = nextLongDoc; } hasValue = (longDoc & HAS_VALUE_MASK) > 0; if (hasValue) { set(idx - 1); } doc = (int)(longDoc >> SHIFT); return doc; }
@Override protected int compare(int i, int j) { // increasing docID order: // NOTE: we can have ties here, when the same docID was updated in the same segment, in which case we rely on sort being // stable and preserving original order so the last update to that docID wins return Long.compare(docs.get(i)>>>1, docs.get(j)>>>1); } }.sort(0, size);
@Override int nextDoc() { if (idx >= size) { offset = -1; return doc = DocIdSetIterator.NO_MORE_DOCS; } doc = (int) docs.get(idx); ++idx; while (idx < size && docs.get(idx) == doc) { ++idx; } // idx points to the "next" element long prevIdx = idx - 1; // cannot change 'value' here because nextDoc is called before the // value is used, and it's a waste to clone the BytesRef when we // obtain the value offset = (int) offsets.get(prevIdx); length = (int) lengths.get(prevIdx); return doc; }
@Override int nextDoc() { if (idx >= size) { offset = -1; return doc = DocIdSetIterator.NO_MORE_DOCS; } doc = (int) docs.get(idx); ++idx; while (idx < size && docs.get(idx) == doc) { ++idx; } // idx points to the "next" element long prevIdx = idx - 1; // cannot change 'value' here because nextDoc is called before the // value is used, and it's a waste to clone the BytesRef when we // obtain the value offset = (int) offsets.get(prevIdx); length = (int) lengths.get(prevIdx); return doc; }
@Override public void merge(DocValuesFieldUpdates other) { assert other instanceof NumericDocValuesFieldUpdates; NumericDocValuesFieldUpdates otherUpdates = (NumericDocValuesFieldUpdates) other; if (otherUpdates.size > Integer.MAX_VALUE - size) { throw new IllegalStateException( "cannot support more than Integer.MAX_VALUE doc/value entries; size=" + size + " other.size=" + otherUpdates.size); } docs = docs.grow(size + otherUpdates.size); values = values.grow(size + otherUpdates.size); for (int i = 0; i < otherUpdates.size; i++) { int doc = (int) otherUpdates.docs.get(i); docs.set(size, doc); values.set(size, otherUpdates.values.get(i)); ++size; } }
@Override public void merge(DocValuesFieldUpdates other) { assert other instanceof NumericDocValuesFieldUpdates; NumericDocValuesFieldUpdates otherUpdates = (NumericDocValuesFieldUpdates) other; if (otherUpdates.size > Integer.MAX_VALUE - size) { throw new IllegalStateException( "cannot support more than Integer.MAX_VALUE doc/value entries; size=" + size + " other.size=" + otherUpdates.size); } docs = docs.grow(size + otherUpdates.size); values = values.grow(size + otherUpdates.size); for (int i = 0; i < otherUpdates.size; i++) { int doc = (int) otherUpdates.docs.get(i); docs.set(size, doc); values.set(size, otherUpdates.values.get(i)); ++size; } }
@Override protected void swap(int i, int j) { long tmpDoc = docs.get(j); docs.set(j, docs.get(i)); docs.set(i, tmpDoc); long tmpOffset = offsets.get(j); offsets.set(j, offsets.get(i)); offsets.set(i, tmpOffset); long tmpLength = lengths.get(j); lengths.set(j, lengths.get(i)); lengths.set(i, tmpLength); }
@Override protected void swap(int i, int j) { long tmpDoc = docs.get(j); docs.set(j, docs.get(i)); docs.set(i, tmpDoc); long tmpOffset = offsets.get(j); offsets.set(j, offsets.get(i)); offsets.set(i, tmpOffset); long tmpLength = lengths.get(j); lengths.set(j, lengths.get(i)); lengths.set(i, tmpLength); }
@Override public void merge(DocValuesFieldUpdates other) { BinaryDocValuesFieldUpdates otherUpdates = (BinaryDocValuesFieldUpdates) other; if (otherUpdates.size > Integer.MAX_VALUE - size) { throw new IllegalStateException( "cannot support more than Integer.MAX_VALUE doc/value entries; size=" + size + " other.size=" + otherUpdates.size); } final int newSize = size + otherUpdates.size; docs = docs.grow(newSize); offsets = offsets.grow(newSize); lengths = lengths.grow(newSize); for (int i = 0; i < otherUpdates.size; i++) { int doc = (int) otherUpdates.docs.get(i); docs.set(size, doc); offsets.set(size, values.length() + otherUpdates.offsets.get(i)); // correct relative offset lengths.set(size, otherUpdates.lengths.get(i)); ++size; } values.append(otherUpdates.values); }