public byte getByte(long offset) { checkBounds(offset, offset + 1); return unsafe.getByte(peer + offset); }
public void close() { chunkOffsets.close(); }
@SuppressWarnings("resource") public static OffHeapBitSet deserialize(DataInput in) throws IOException { long byteCount = in.readInt() * 8L; Memory memory = Memory.allocate(byteCount); for (long i = 0; i < byteCount;) { long v = in.readLong(); memory.setByte(i++, (byte) (v >>> 0)); memory.setByte(i++, (byte) (v >>> 8)); memory.setByte(i++, (byte) (v >>> 16)); memory.setByte(i++, (byte) (v >>> 24)); memory.setByte(i++, (byte) (v >>> 32)); memory.setByte(i++, (byte) (v >>> 40)); memory.setByte(i++, (byte) (v >>> 48)); memory.setByte(i++, (byte) (v >>> 56)); } return new OffHeapBitSet(memory); }
/** * Gets the position of the actual index summary entry in our Memory attribute, 'bytes'. * @param index The index of the entry or key to get the position for * @return an offset into our Memory attribute where the actual entry resides */ public int getPositionInSummary(int index) { // The first section of bytes holds a four-byte position for each entry in the summary, so just multiply by 4. return offsets.getInt(index << 2); }
public void close() { bytes.free(); }
public void write(Memory memory, long offset, long length) throws IOException { for (ByteBuffer buffer : memory.asByteBuffers(offset, length)) write(buffer); } }
public int getInt(long offset) { checkBounds(offset, offset + 4); if (unaligned) { return unsafe.getInt(peer + offset); } else { return getIntByByte(peer + offset); } }
public void setShort(long offset, short l) { checkBounds(offset, offset + 2); if (Architecture.IS_UNALIGNED) { unsafe.putShort(peer + offset, l); } else { putShortByByte(peer + offset, l); } }
public void setLong(long offset, long l) { checkBounds(offset, offset + 8); if (Architecture.IS_UNALIGNED) { unsafe.putLong(peer + offset, l); } else { putLongByByte(peer + offset, l); } }
public void readFully(byte[] buffer, int offset, int count) throws IOException { mem.getBytes(position, buffer, offset, count); position += count; }
public static Memory allocate(long bytes) { if (bytes < 0) throw new IllegalArgumentException(); if (Ref.DEBUG_ENABLED) return new SafeMemory(bytes); return new Memory(bytes); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof OffHeapBitSet)) return false; OffHeapBitSet b = (OffHeapBitSet) o; return bytes.equals(b.bytes); }
public OffHeapBitSet(long numBits) { // OpenBitSet.bits2words calculation is there for backward compatibility. long wordCount = OpenBitSet.bits2words(numBits); if (wordCount > Integer.MAX_VALUE) throw new UnsupportedOperationException("Bloom filter size is > 16GB, reduce the bloom_filter_fp_chance"); try { long byteCount = wordCount * 8L; bytes = Memory.allocate(byteCount); } catch (OutOfMemoryError e) { throw new RuntimeException("Out of native memory occured, You can avoid it by increasing the system ram space or by increasing bloom_filter_fp_chance."); } // flush/clear the existing memory. clear(); }
public boolean get(long index) { long i = index >> 3; long bit = index & 0x7; int bitmask = 0x1 << bit; return (bytes.getByte(i) & bitmask) != 0; }