private void encodeValues(int count) throws IOException { out.reset(buffer); long lastOrd = 0; for (int i = 0; i < count; i++) { long ord = ords.next().longValue(); out.writeVLong(ord - lastOrd); lastOrd = ord; } }
void add(long value, int docID) throws IOException { if (valueCount >= maxValuesSortInHeap) { if (writer == null) { switchToOffline(); } scratchBytesOutput.reset(scratchBytes); scratchBytesOutput.writeLong(value); scratchBytesOutput.writeVInt(docID); scratchBytesOutput.writeVLong(valueCount); writer.write(scratchBytes, 0, scratchBytes.length); } else { // Not too many points added yet, continue using heap: heapWriter.append(value, valueCount, docID); } valueCount++; globalMaxValue = Math.max(value, globalMaxValue); globalMinValue = Math.min(value, globalMinValue); }
/** If the current segment has too many points then we switchover to temp files / offline sort. */ private void switchToOffline() throws IOException { // For each .add we just append to this input file, then in .finish we sort this input and resursively build the tree: tempInput = Files.createTempFile(OfflineSorter.getDefaultTempDir(), "in", ""); writer = new OfflineSorter.ByteSequencesWriter(tempInput); for(int i=0;i<valueCount;i++) { scratchBytesOutput.reset(scratchBytes); scratchBytesOutput.writeLong(heapWriter.values[i]); scratchBytesOutput.writeVInt(heapWriter.docIDs[i]); scratchBytesOutput.writeVLong(i); // TODO: can/should OfflineSorter optimize the fixed-width case? writer.write(scratchBytes, 0, scratchBytes.length); } heapWriter = null; }
/** If the current segment has too many points then we switchover to temp files / offline sort. */ private void switchToOffline() throws IOException { // For each .add we just append to this input file, then in .finish we sort this input and resursively build the tree: tempInput = Files.createTempFile(OfflineSorter.getDefaultTempDir(), "in", ""); writer = new OfflineSorter.ByteSequencesWriter(tempInput); for(int i=0;i<pointCount;i++) { scratchBytesOutput.reset(scratchBytes); scratchBytesOutput.writeInt(heapWriter.latEncs[i]); scratchBytesOutput.writeInt(heapWriter.lonEncs[i]); scratchBytesOutput.writeVInt(heapWriter.docIDs[i]); scratchBytesOutput.writeVLong(i); // TODO: can/should OfflineSorter optimize the fixed-width case? writer.write(scratchBytes, 0, scratchBytes.length); } heapWriter = null; }
/** If the current segment has too many points then we switchover to temp files / offline sort. */ private void switchToOffline() throws IOException { // For each .add we just append to this input file, then in .finish we sort this input and resursively build the tree: tempInput = Files.createTempFile(OfflineSorter.getDefaultTempDir(), "in", ""); writer = new OfflineSorter.ByteSequencesWriter(tempInput); for(int i=0;i<pointCount;i++) { scratchBytesOutput.reset(scratchBytes); scratchBytesOutput.writeInt(heapWriter.xs[i]); scratchBytesOutput.writeInt(heapWriter.ys[i]); scratchBytesOutput.writeInt(heapWriter.zs[i]); scratchBytesOutput.writeVInt(heapWriter.docIDs[i]); scratchBytesOutput.writeVLong(i); // TODO: can/should OfflineSorter optimize the fixed-width case? writer.write(scratchBytes, 0, scratchBytes.length); } heapWriter = null; }
void add(int latEnc, int lonEnc, int docID) throws IOException { assert latEnc > Integer.MIN_VALUE; assert latEnc < Integer.MAX_VALUE; assert lonEnc > Integer.MIN_VALUE; assert lonEnc < Integer.MAX_VALUE; if (pointCount >= maxPointsSortInHeap) { if (writer == null) { switchToOffline(); } scratchBytesOutput.reset(scratchBytes); scratchBytesOutput.writeInt(latEnc); scratchBytesOutput.writeInt(lonEnc); scratchBytesOutput.writeVInt(docID); scratchBytesOutput.writeVLong(pointCount); writer.write(scratchBytes, 0, scratchBytes.length); } else { // Not too many points added yet, continue using heap: heapWriter.append(latEnc, lonEnc, pointCount, docID); } pointCount++; }
public void add(int x, int y, int z, int docID) throws IOException { if (pointCount >= maxPointsSortInHeap) { if (writer == null) { switchToOffline(); } scratchBytesOutput.reset(scratchBytes); scratchBytesOutput.writeInt(x); scratchBytesOutput.writeInt(y); scratchBytesOutput.writeInt(z); scratchBytesOutput.writeVInt(docID); scratchBytesOutput.writeVLong(pointCount); writer.write(scratchBytes, 0, scratchBytes.length); } else { // Not too many points added yet, continue using heap: heapWriter.append(x, y, z, pointCount, docID); } pointCount++; }