@Override protected PagedMutable newUnfilledCopy(long newSize) { return new PagedMutable(newSize, pageSize(), bitsPerValue, format); }
/** * Create a new {@link PagedMutable} instance. * * @param size the number of values to store. * @param pageSize the number of values per page * @param bitsPerValue the number of bits per value * @param acceptableOverheadRatio an acceptable overhead ratio */ public PagedMutable(long size, int pageSize, int bitsPerValue, float acceptableOverheadRatio) { this(size, pageSize, PackedInts.fastestFormatAndBits(pageSize, bitsPerValue, acceptableOverheadRatio)); fillPages(); }
private synchronized int addInternal(int doc, long hasValueMask) { if (finished) { throw new IllegalStateException("already finished"); } assert doc < maxDoc; // TODO: if the Sorter interface changes to take long indexes, we can remove that limitation if (size == Integer.MAX_VALUE) { throw new IllegalStateException("cannot support more than Integer.MAX_VALUE doc/value entries"); } // grow the structures to have room for more elements if (docs.size() == size) { grow(size+1); } docs.set(size, (((long)doc) << SHIFT) | hasValueMask); ++size; return size-1; }
@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 add(int doc, Object value) { // TODO: if the Sorter interface changes to take long indexes, we can remove that limitation if (size == Integer.MAX_VALUE) { throw new IllegalStateException("cannot support more than Integer.MAX_VALUE doc/value entries"); } Long val = (Long) value; // grow the structures to have room for more elements if (docs.size() == size) { docs = docs.grow(size + 1); values = values.grow(size + 1); } docs.set(size, doc); values.set(size, val.longValue()); ++size; }
@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);
protected DocValuesFieldUpdates(int maxDoc, long delGen, String field, DocValuesType type) { this.maxDoc = maxDoc; this.delGen = delGen; this.field = field; if (type == null) { throw new NullPointerException("DocValuesType must not be null"); } this.type = type; bitsPerValue = PackedInts.bitsRequired(maxDoc - 1) + SHIFT; docs = new PagedMutable(1, PAGE_SIZE, bitsPerValue, PackedInts.COMPACT); }
protected void grow(int size) { docs = docs.grow(size); }
/** Freezes internal data structures and sorts updates by docID for efficient iteration. */ final synchronized void finish() { if (finished) { throw new IllegalStateException("already finished"); } finished = true; // shrink wrap if (size < docs.size()) { resize(size); } new InPlaceMergeSorter() { @Override protected void swap(int i, int j) { DocValuesFieldUpdates.this.swap(i, j); } @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 long ramBytesUsed() { return docs.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + 2 * Integer.BYTES + 2 + Long.BYTES + RamUsageEstimator.NUM_BYTES_OBJECT_REF; }
protected void resize(int size) { docs = docs.resize(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 public void add(int doc, Object value) { // TODO: if the Sorter interface changes to take long indexes, we can remove that limitation if (size == Integer.MAX_VALUE) { throw new IllegalStateException("cannot support more than Integer.MAX_VALUE doc/value entries"); } Long val = (Long) value; // grow the structures to have room for more elements if (docs.size() == size) { docs = docs.grow(size + 1); values = values.grow(size + 1); } docs.set(size, doc); values.set(size, val.longValue()); ++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; }
private synchronized int addInternal(int doc, long hasValueMask) { if (finished) { throw new IllegalStateException("already finished"); } assert doc < maxDoc; // TODO: if the Sorter interface changes to take long indexes, we can remove that limitation if (size == Integer.MAX_VALUE) { throw new IllegalStateException("cannot support more than Integer.MAX_VALUE doc/value entries"); } // grow the structures to have room for more elements if (docs.size() == size) { grow(size+1); } docs.set(size, (((long)doc) << SHIFT) | hasValueMask); ++size; return size-1; }
protected DocValuesFieldUpdates(int maxDoc, long delGen, String field, DocValuesType type) { this.maxDoc = maxDoc; this.delGen = delGen; this.field = field; if (type == null) { throw new NullPointerException("DocValuesType must not be null"); } this.type = type; bitsPerValue = PackedInts.bitsRequired(maxDoc - 1) + SHIFT; docs = new PagedMutable(1, PAGE_SIZE, bitsPerValue, PackedInts.COMPACT); }
protected void grow(int size) { docs = docs.grow(size); }
/** Freezes internal data structures and sorts updates by docID for efficient iteration. */ final synchronized void finish() { if (finished) { throw new IllegalStateException("already finished"); } finished = true; // shrink wrap if (size < docs.size()) { resize(size); } new InPlaceMergeSorter() { @Override protected void swap(int i, int j) { DocValuesFieldUpdates.this.swap(i, j); } @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 long ramBytesUsed() { return docs.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + 2 * Integer.BYTES + 2 + Long.BYTES + RamUsageEstimator.NUM_BYTES_OBJECT_REF; }