Java Code Examples for org.apache.lucene.store.DataOutput#writeLong()
The following examples show how to use
org.apache.lucene.store.DataOutput#writeLong() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JaspellLookup.java From lucene-solr with Apache License 2.0 | 6 votes |
private void writeRecursively(DataOutput out, TSTNode node) throws IOException { if (node == null) { return; } out.writeString(new String(new char[] {node.splitchar}, 0, 1)); byte mask = 0; if (node.relatives[TSTNode.LOKID] != null) mask |= LO_KID; if (node.relatives[TSTNode.EQKID] != null) mask |= EQ_KID; if (node.relatives[TSTNode.HIKID] != null) mask |= HI_KID; if (node.data != null) mask |= HAS_VALUE; out.writeByte(mask); if (node.data != null) { out.writeLong(((Number)node.data).longValue()); } writeRecursively(out, node.relatives[TSTNode.LOKID]); writeRecursively(out, node.relatives[TSTNode.EQKID]); writeRecursively(out, node.relatives[TSTNode.HIKID]); }
Example 2
Source File: TSTLookup.java From lucene-solr with Apache License 2.0 | 6 votes |
private void writeRecursively(DataOutput out, TernaryTreeNode node) throws IOException { // write out the current node out.writeString(new String(new char[] {node.splitchar}, 0, 1)); // prepare a mask of kids byte mask = 0; if (node.eqKid != null) mask |= EQ_KID; if (node.loKid != null) mask |= LO_KID; if (node.hiKid != null) mask |= HI_KID; if (node.token != null) mask |= HAS_TOKEN; if (node.val != null) mask |= HAS_VALUE; out.writeByte(mask); if (node.token != null) out.writeString(node.token); if (node.val != null) out.writeLong(((Number)node.val).longValue()); // recurse and write kids if (node.loKid != null) { writeRecursively(out, node.loKid); } if (node.eqKid != null) { writeRecursively(out, node.eqKid); } if (node.hiKid != null) { writeRecursively(out, node.hiKid); } }
Example 3
Source File: CompressingStoredFieldsWriter.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Writes a float in a variable-length format. Writes between one and * five bytes. Small integral values typically take fewer bytes. * <p> * ZFloat --> Header, Bytes*? * <ul> * <li>Header --> {@link DataOutput#writeByte Uint8}. When it is * equal to 0xFF then the value is negative and stored in the next * 8 bytes. When it is equal to 0xFE then the value is stored as a * float in the next 4 bytes. Otherwise if the first bit is set * then the other bits in the header encode the value plus one and * no other bytes are read. Otherwise, the value is a positive float * value whose first byte is the header, and 7 bytes need to be read * to complete it. * <li>Bytes --> Potential additional bytes to read depending on the * header. * </ul> */ static void writeZDouble(DataOutput out, double d) throws IOException { int intVal = (int) d; final long doubleBits = Double.doubleToLongBits(d); if (d == intVal && intVal >= -1 && intVal <= 0x7C && doubleBits != NEGATIVE_ZERO_DOUBLE) { // small integer value [-1..124]: single byte out.writeByte((byte) (0x80 | (intVal + 1))); return; } else if (d == (float) d) { // d has an accurate float representation: 5 bytes out.writeByte((byte) 0xFE); out.writeInt(Float.floatToIntBits((float) d)); } else if ((doubleBits >>> 63) == 0) { // other positive doubles: 8 bytes out.writeLong(doubleBits); } else { // other negative doubles: 9 bytes out.writeByte((byte) 0xFF); out.writeLong(doubleBits); } }
Example 4
Source File: BloomFilter.java From Elasticsearch with Apache License 2.0 | 5 votes |
public static void serilaize(BloomFilter filter, DataOutput out) throws IOException { out.writeInt(0); // version BitArray bits = filter.bits; out.writeInt(bits.data.length); for (long l : bits.data) { out.writeLong(l); } out.writeInt(filter.numHashFunctions); out.writeInt(filter.hashing.type()); // hashType }
Example 5
Source File: SortField.java From lucene-solr with Apache License 2.0 | 5 votes |
private void serialize(DataOutput out) throws IOException { out.writeString(field); out.writeString(type.toString()); out.writeInt(reverse ? 1 : 0); if (missingValue == null) { out.writeInt(0); } else { out.writeInt(1); switch (type) { case STRING: if (missingValue == STRING_LAST) { out.writeInt(0); } else if (missingValue == STRING_FIRST) { out.writeInt(1); } else { throw new IllegalArgumentException("Cannot serialize missing value of " + missingValue + " for type STRING"); } break; case INT: out.writeInt((int)missingValue); break; case LONG: out.writeLong((long)missingValue); break; case FLOAT: out.writeInt(NumericUtils.floatToSortableInt((float)missingValue)); break; case DOUBLE: out.writeLong(NumericUtils.doubleToSortableLong((double)missingValue)); break; default: throw new IllegalArgumentException("Cannot serialize SortField of type " + type); } } }
Example 6
Source File: SortedNumericSortField.java From lucene-solr with Apache License 2.0 | 5 votes |
private void serialize(DataOutput out) throws IOException { out.writeString(getField()); out.writeString(type.toString()); out.writeInt(reverse ? 1 : 0); out.writeInt(selector.ordinal()); if (missingValue == null) { out.writeInt(0); } else { out.writeInt(1); // oh for switch expressions... switch (type) { case INT: out.writeInt((int)missingValue); break; case LONG: out.writeLong((long)missingValue); break; case FLOAT: out.writeInt(NumericUtils.floatToSortableInt((float)missingValue)); break; case DOUBLE: out.writeLong(NumericUtils.doubleToSortableLong((double)missingValue)); break; default: throw new AssertionError(); } } }
Example 7
Source File: Checkpoint.java From crate with Apache License 2.0 | 5 votes |
private void write(DataOutput out) throws IOException { out.writeLong(offset); out.writeInt(numOps); out.writeLong(generation); out.writeLong(minSeqNo); out.writeLong(maxSeqNo); out.writeLong(globalCheckpoint); out.writeLong(minTranslogGeneration); out.writeLong(trimmedAboveSeqNo); }
Example 8
Source File: Checkpoint.java From Elasticsearch with Apache License 2.0 | 4 votes |
private void write(DataOutput out) throws IOException { out.writeLong(offset); out.writeInt(numOps); out.writeLong(generation); }
Example 9
Source File: SimplePrimaryNode.java From lucene-solr with Apache License 2.0 | 4 votes |
/** Flushes all indexing ops to disk and notifies all replicas that they should now copy */ private void handleFlush(DataInput topIn, DataOutput topOut, BufferedOutputStream bos) throws IOException { Thread.currentThread().setName("flush"); int atLeastMarkerCount = topIn.readVInt(); int[] replicaTCPPorts; int[] replicaIDs; synchronized (this) { replicaTCPPorts = this.replicaTCPPorts; replicaIDs = this.replicaIDs; } message("now flush; " + replicaIDs.length + " replicas"); if (flushAndRefresh()) { // Something did get flushed (there were indexing ops since the last flush): verifyAtLeastMarkerCount(atLeastMarkerCount, null); // Tell caller the version before pushing to replicas, so that even if we crash after this, caller will know what version we // (possibly) pushed to some replicas. Alternatively we could make this 2 separate ops? long version = getCopyStateVersion(); message("send flushed version=" + version); topOut.writeLong(version); bos.flush(); // Notify current replicas: for(int i=0;i<replicaIDs.length;i++) { int replicaID = replicaIDs[i]; try (Connection c = new Connection(replicaTCPPorts[i])) { message("send NEW_NRT_POINT to R" + replicaID + " at tcpPort=" + replicaTCPPorts[i]); c.out.writeByte(SimpleReplicaNode.CMD_NEW_NRT_POINT); c.out.writeVLong(version); c.out.writeVLong(primaryGen); c.out.writeInt(tcpPort); c.flush(); // TODO: we should use multicast to broadcast files out to replicas // TODO: ... replicas could copy from one another instead of just primary // TODO: we could also prioritize one replica at a time? } catch (Throwable t) { message("top: failed to connect R" + replicaID + " for newNRTPoint; skipping: " + t.getMessage()); } } } else { // No changes flushed: topOut.writeLong(-getCopyStateVersion()); } }
Example 10
Source File: ForUtil.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * Encode 128 integers from {@code longs} into {@code out}. */ void encode(long[] longs, int bitsPerValue, DataOutput out) throws IOException { final int nextPrimitive; final int numLongs; if (bitsPerValue <= 8) { nextPrimitive = 8; numLongs = BLOCK_SIZE / 8; collapse8(longs); } else if (bitsPerValue <= 16) { nextPrimitive = 16; numLongs = BLOCK_SIZE / 4; collapse16(longs); } else { nextPrimitive = 32; numLongs = BLOCK_SIZE / 2; collapse32(longs); } final int numLongsPerShift = bitsPerValue * 2; int idx = 0; int shift = nextPrimitive - bitsPerValue; for (int i = 0; i < numLongsPerShift; ++i) { tmp[i] = longs[idx++] << shift; } for (shift = shift - bitsPerValue; shift >= 0; shift -= bitsPerValue) { for (int i = 0; i < numLongsPerShift; ++i) { tmp[i] |= longs[idx++] << shift; } } final int remainingBitsPerLong = shift + bitsPerValue; final long maskRemainingBitsPerLong; if (nextPrimitive == 8) { maskRemainingBitsPerLong = mask8(remainingBitsPerLong); } else if (nextPrimitive == 16) { maskRemainingBitsPerLong = mask16(remainingBitsPerLong); } else { maskRemainingBitsPerLong = mask32(remainingBitsPerLong); } int tmpIdx = 0; int remainingBitsPerValue = bitsPerValue; while (idx < numLongs) { if (remainingBitsPerValue > remainingBitsPerLong) { remainingBitsPerValue -= remainingBitsPerLong; tmp[tmpIdx++] |= (longs[idx] >>> remainingBitsPerValue) & maskRemainingBitsPerLong; if (remainingBitsPerValue == 0) { idx++; remainingBitsPerValue = bitsPerValue; } } else { final long mask1, mask2; if (nextPrimitive == 8) { mask1 = mask8(remainingBitsPerValue); mask2 = mask8(remainingBitsPerLong - remainingBitsPerValue); } else if (nextPrimitive == 16) { mask1 = mask16(remainingBitsPerValue); mask2 = mask16(remainingBitsPerLong - remainingBitsPerValue); } else { mask1 = mask32(remainingBitsPerValue); mask2 = mask32(remainingBitsPerLong - remainingBitsPerValue); } tmp[tmpIdx] |= (longs[idx++] & mask1) << (remainingBitsPerLong - remainingBitsPerValue); remainingBitsPerValue = bitsPerValue - remainingBitsPerLong + remainingBitsPerValue; tmp[tmpIdx++] |= (longs[idx] >>> remainingBitsPerValue) & mask2; } } for (int i = 0; i < numLongsPerShift; ++i) { // Java longs are big endian and we want to read little endian longs, so we need to reverse bytes long l = Long.reverseBytes(tmp[i]); out.writeLong(l); } }
Example 11
Source File: FuzzySet.java From lucene-solr with Apache License 2.0 | 3 votes |
/** * Serializes the data set to file using the following format: * <ul> * <li>FuzzySet -->FuzzySetVersion,HashFunctionName,BloomSize, * NumBitSetWords,BitSetWord<sup>NumBitSetWords</sup></li> * <li>HashFunctionName --> {@link DataOutput#writeString(String) String} The * name of a ServiceProvider registered {@link HashFunction}</li> * <li>FuzzySetVersion --> {@link DataOutput#writeInt Uint32} The version number of the {@link FuzzySet} class</li> * <li>BloomSize --> {@link DataOutput#writeInt Uint32} The modulo value used * to project hashes into the field's Bitset</li> * <li>NumBitSetWords --> {@link DataOutput#writeInt Uint32} The number of * longs (as returned from {@link FixedBitSet#getBits})</li> * <li>BitSetWord --> {@link DataOutput#writeLong Long} A long from the array * returned by {@link FixedBitSet#getBits}</li> * </ul> * @param out Data output stream * @throws IOException If there is a low-level I/O error */ public void serialize(DataOutput out) throws IOException { out.writeInt(VERSION_CURRENT); out.writeInt(bloomSize); long[] bits = filter.getBits(); out.writeInt(bits.length); for (int i = 0; i < bits.length; i++) { // Can't used VLong encoding because cant cope with negative numbers // output by FixedBitSet out.writeLong(bits[i]); } }