Java Code Examples for java.nio.LongBuffer#position()
The following examples show how to use
java.nio.LongBuffer#position() .
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: BitMapOps.java From succinct with Apache License 2.0 | 6 votes |
/** * Get value at specified index of serialized bitmap. * * @param bitmap Serialized bitmap. * @param pos Position into bitmap. * @param bits Width in bits of value. * @return Value at specified position. */ public static long getValPos(LongBuffer bitmap, int pos, int bits) { assert (pos >= 0); int basePos = bitmap.position(); long val; long s = (long) pos; long e = s + (bits - 1); if ((s / 64) == (e / 64)) { val = bitmap.get(basePos + (int) (s / 64L)) << (s % 64); val = val >>> (63 - e % 64 + s % 64); } else { val = bitmap.get(basePos + (int) (s / 64L)) << (s % 64); val = val >>> (s % 64 - (e % 64 + 1)); val = val | (bitmap.get(basePos + (int) (e / 64L)) >>> (63 - e % 64)); } assert (val >= 0); return val; }
Example 2
Source File: LongNioDataBuffer.java From java with Apache License 2.0 | 5 votes |
@Override public LongDataBuffer slice(long index, long size) { Validator.sliceArgs(this, index, size); LongBuffer sliceBuf = buf.duplicate(); sliceBuf.position((int)index); sliceBuf.limit((int)index + (int)size); return new LongNioDataBuffer(sliceBuf.slice()); }
Example 3
Source File: LongDZBP.java From metrics with Apache License 2.0 | 5 votes |
public void compress(LongBuffer src, LongOutputStream dst) { // Output length of original array. When input array is empty, make // empty output for memory efficiency. final int srcLen = src.remaining(); if (srcLen == 0) { return; } dst.write(srcLen); // Output first int, and set it as delta's initial context. final long first = src.get(); dst.write(first); DZEncodeFilter filter = new DZEncodeFilter(first); // Compress intermediate blocks. final int chunkSize = this.bitPack.getBlockSize(); final int chunkRemain = src.remaining() % chunkSize; LongBuffer window = src.slice(); window.limit(window.limit() - chunkRemain); this.bitPack.compress(window, dst, filter); src.position(src.position() + window.position()); // Compress last block. if (chunkRemain > 0) { long[] last = new long[chunkSize]; src.get(last, 0, chunkRemain); // Padding extended area by last value. It make delta zigzag // efficient. Arrays.fill(last, chunkRemain, last.length, last[chunkRemain - 1]); this.bitPack.compress(LongBuffer.wrap(last), dst, filter); } }
Example 4
Source File: LongBitPacking.java From metrics with Apache License 2.0 | 5 votes |
public void pack0( LongBuffer src, LongOutputStream dst, int len) { src.position(src.position() + len); }
Example 5
Source File: LongBitPacking.java From metrics with Apache License 2.0 | 5 votes |
public void compress( LongBuffer src, LongOutputStream dst, LongFilter filter) { int srclen = src.limit() - src.position(); while (src.remaining() >= this.blockLen * this.blockNum) { compressChunk(src, dst, filter); } return; }
Example 6
Source File: CodecUtils.java From metrics with Apache License 2.0 | 5 votes |
public static void encodeBlockPack( LongBuffer src, LongFilterFactory filterFactory, LongBitPacking packer, LongOutputStream dst) { // Output length of original array. When input array is empty, make // empty output for memory efficiency. final int srcLen = src.remaining(); if (srcLen == 0) { return; } dst.write(srcLen); // Output first int, and set it as delta's initial context. final long first = src.get(); dst.write(first); LongFilter filter = filterFactory.newFilter(first); // Compress intermediate blocks. final int chunkSize = packer.getBlockSize(); final int chunkRemain = src.remaining() % chunkSize; LongBuffer window = src.slice(); window.limit(window.limit() - chunkRemain); packer.compress(window, dst, filter); src.position(src.position() + window.position()); // Compress last block. if (chunkRemain > 0) { long[] last = new long[chunkSize]; src.get(last, 0, chunkRemain); // Padding extended area by last value. It make delta zigzag // efficient. Arrays.fill(last, chunkRemain, last.length, last[chunkRemain - 1]); packer.compress(LongBuffer.wrap(last), dst, filter); } }
Example 7
Source File: FloatHistogram.java From t-digest with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("WeakerAccess") public long[] getCompressedCounts() { LongBuffer buf = LongBuffer.allocate(counts.length); Simple64.compress(buf, counts, 0, counts.length); long[] r = new long[buf.position()]; buf.flip(); buf.get(r); return r; }
Example 8
Source File: DictionaryOps.java From succinct with Apache License 2.0 | 4 votes |
/** * Get rank1 at specified index of serialized dictionary. * * @param buf ByteBuffer containing serialized Dictionary. * @param startPos Starting position within ByteBuffer. * @param i Index to compute rank1. * @return Value of rank1. */ public static long getRank1(ByteBuffer buf, int startPos, int i) { if (i < 0) { return 0; } int l3Idx = (int) (i / CommonUtils.two32); int l2Idx = i / 2048; int l1Idx = (i % 512); int rem = ((i % 2048) / 512); int blockClass, blockOffset; buf.position(startPos); LongBuffer dictBuf = buf.asLongBuffer(); long size = dictBuf.get(); int l3_size = (int) (size / CommonUtils.two32) + 1; int l12_size = (int) (size / 2048) + 1; int basePos = dictBuf.position(); long rank_l3 = dictBuf.get(basePos + l3Idx); long pos_l3 = dictBuf.get(basePos + l3_size + l3Idx); long rank_l12 = dictBuf.get(basePos + l3_size + l3_size + l2Idx); long pos_l12 = dictBuf.get(basePos + l3_size + l3_size + l12_size + l2Idx); dictBuf.position(basePos + l3_size + l3_size + l12_size + l12_size); long res = rank_l3 + GETRANKL2(rank_l12); long pos = pos_l3 + GETPOSL2(pos_l12); switch (rem) { case 1: res += GETRANKL1(rank_l12, 1); pos += GETPOSL1(pos_l12, 1); break; case 2: res += GETRANKL1(rank_l12, 1) + GETRANKL1(rank_l12, 2); pos += GETPOSL1(pos_l12, 1) + GETPOSL1(pos_l12, 2); break; case 3: res += GETRANKL1(rank_l12, 1) + GETRANKL1(rank_l12, 2) + GETRANKL1(rank_l12, 3); pos += GETPOSL1(pos_l12, 1) + GETPOSL1(pos_l12, 2) + GETPOSL1(pos_l12, 3); break; default: break; } dictBuf.get(); // TODO: Could remove this field altogether // Popcount while (l1Idx >= 16) { blockClass = (int) BitMapOps.getValPos(dictBuf, (int) pos, 4); pos += 4; blockOffset = (int) ((blockClass == 0) ? BitMapOps.getBit(dictBuf, (int) pos) * 16 : 0); pos += Tables.offsetBits[blockClass]; res += blockClass + blockOffset; l1Idx -= 16; } blockClass = (int) BitMapOps.getValPos(dictBuf, (int) pos, 4); pos += 4; blockOffset = (int) BitMapOps.getValPos(dictBuf, (int) pos, Tables.offsetBits[blockClass]); res += Tables.smallRank[Tables.decodeTable[blockClass][blockOffset]][l1Idx]; return res; }
Example 9
Source File: NioBufferInvocations.java From bazel with Apache License 2.0 | 4 votes |
public static LongBuffer getLongBufferPosition(LongBuffer buffer, int position) { return buffer.position(position); }