Java Code Examples for java.nio.LongBuffer#wrap()
The following examples show how to use
java.nio.LongBuffer#wrap() .
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: ArrayOpsTest.java From succinct with Apache License 2.0 | 5 votes |
/** * Test method: long getRank1(LongBuffer arrayBuf, int startPos, int size, long i) * * @throws Exception */ public void testGetRank1() throws Exception { long[] data = {2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L, 23L, 29L}; LongBuffer buf = LongBuffer.wrap(data); assertEquals(ArrayOps.getRank1(buf, 0, data.length, 0L), 0L); assertEquals(ArrayOps.getRank1(buf, 0, data.length, 2L), 1L); assertEquals(ArrayOps.getRank1(buf, 0, data.length, 3L), 2L); assertEquals(ArrayOps.getRank1(buf, 0, data.length, 4L), 2L); assertEquals(ArrayOps.getRank1(buf, 0, data.length, 6L), 3L); assertEquals(ArrayOps.getRank1(buf, 0, data.length, 22L), 8L); assertEquals(ArrayOps.getRank1(buf, 0, data.length, 29L), 10L); assertEquals(ArrayOps.getRank1(buf, 0, data.length, 33L), 10L); }
Example 2
Source File: BitmapIteratorBenchmark.java From RoaringBitmap with Apache License 2.0 | 5 votes |
@Setup public void init() { long[] bitmap = new long[1024]; int cardinality = 0; int targetCardinality = (int)(density * 65536); ThreadLocalRandom random = ThreadLocalRandom.current(); while (cardinality < targetCardinality) { int index = random.nextInt(65536); long before = bitmap[index >>> 6]; bitmap[index >>> 6] |= (1L << index); cardinality += Long.bitCount(before ^ bitmap[index >>> 6]); } container = new BitmapContainer(bitmap, cardinality); bufferContainer = new MappeableBitmapContainer(LongBuffer.wrap(bitmap), cardinality); }
Example 3
Source File: TestUtil.java From RoaringBitmap with Apache License 2.0 | 5 votes |
@Test public void testFillArrayANDNOT() { LongBuffer data1 = LongBuffer.wrap(new long[]{1, 2, 4, 8, 16}); LongBuffer data2 = LongBuffer.wrap(new long[]{2, 1, 3, 7, 15}); char[] content = new char[5]; char[] result = {0, 65, 130, 195, 260}; BufferUtil.fillArrayANDNOT(content, data1, data2); assertTrue(Arrays.equals(content, result)); }
Example 4
Source File: TestMappeableBitmapContainer.java From RoaringBitmap with Apache License 2.0 | 5 votes |
@Test public void testNextAbsentEvenBits() { int cardinality = 32 + 1 << 15; MappeableBitmapContainer container = new MappeableBitmapContainer(LongBuffer.wrap(evenBits()), cardinality); for (int i = 0; i < 1 << 10; i+=2) { assertEquals(i + 1, container.nextAbsentValue((char)i)); assertEquals(i + 1, container.nextAbsentValue((char)(i+1))); } }
Example 5
Source File: TestMappeableBitmapContainer.java From RoaringBitmap with Apache License 2.0 | 5 votes |
@Test public void testContainsRangeSubWord() { long[] bitmap = evenBits(); bitmap[bitmap.length - 1] = ~((1L << 63) | 1L); int cardinality = 32 + 32 + 16 + 1 << 15; MappeableBitmapContainer container = new MappeableBitmapContainer(LongBuffer.wrap(bitmap), cardinality); assertFalse(container.contains(64 * 1023, 64 * 1024)); assertFalse(container.contains(64 * 1023, 64 * 1024 - 1)); assertTrue(container.contains(1 + 64 * 1023, 64 * 1024 - 1)); assertTrue(container.contains(1 + 64 * 1023, 64 * 1024 - 2)); assertFalse(container.contains(64 * 1023, 64 * 1023 + 2)); assertTrue(container.contains(64 * 1023 + 1, 64 * 1023 + 2)); }
Example 6
Source File: TestMappeableBitmapContainer.java From RoaringBitmap with Apache License 2.0 | 5 votes |
@Test public void testContainsRangeMultiWord() { long[] bitmap = evenBits(); bitmap[10] = -1L; bitmap[11] = -1L; bitmap[12] |= ((1L << 32) - 1); int cardinality = 32 + 32 + 16 + 1 << 15; MappeableBitmapContainer container = new MappeableBitmapContainer(LongBuffer.wrap(bitmap), cardinality); assertTrue(container.contains(0, 1)); assertFalse(container.contains(64 * 10, (64 * 13) - 30)); assertTrue(container.contains(64 * 10, (64 * 13) - 31)); assertTrue(container.contains(1 + 64 * 10, (64 * 13) - 32)); assertTrue(container.contains(64 * 10, 64 * 12)); assertFalse(container.contains(64 * 10, 2 + 64 * 13)); }
Example 7
Source File: TestMappeableBitmapContainer.java From RoaringBitmap with Apache License 2.0 | 5 votes |
@Test public void testContainsRangeSingleWord() { long[] bitmap = evenBits(); bitmap[10] = -1L; int cardinality = 32 + 1 << 15; MappeableBitmapContainer container = new MappeableBitmapContainer(LongBuffer.wrap(bitmap), cardinality); assertTrue(container.contains(0, 1)); assertTrue(container.contains(64 * 10, 64 * 11)); assertFalse(container.contains(64 * 10, 2 + 64 * 11)); assertTrue(container.contains(1 + 64 * 10, (64 * 11) - 1)); }
Example 8
Source File: BufferBitSetUtil.java From RoaringBitmap with Apache License 2.0 | 5 votes |
private static MappeableContainer containerOf(final int from, final int to, final int blockCardinality, final long[] words) { // find the best container available if (blockCardinality <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { // containers with DEFAULT_MAX_SIZE or less integers should be // ArrayContainers return arrayContainerOf(from, to, blockCardinality, words); } else { // otherwise use bitmap container return new MappeableBitmapContainer( LongBuffer.wrap(Arrays.copyOfRange(words, from, from + BLOCK_LENGTH)), blockCardinality); } }
Example 9
Source File: NioBufferRefConverterTest.java From bazel with Apache License 2.0 | 5 votes |
@Test public void methodOfNioBufferWithCovariantTypes_afterDesugarInvocationOfLongBufferMethod( @RuntimeMethodHandle(className = "NioBufferInvocations", memberName = "getLongBufferPosition") MethodHandle after) throws Throwable { LongBuffer buffer = LongBuffer.wrap(new long[] {10L, 20L, 30L}); int expectedPos = 2; LongBuffer result = (LongBuffer) after.invoke(buffer, expectedPos); assertThat(result.position()).isEqualTo(expectedPos); }
Example 10
Source File: JnaUtils.java From djl with Apache License 2.0 | 5 votes |
public static long[] getGpuMemory(Device device) { if (!Device.Type.GPU.equals(device.getDeviceType())) { throw new IllegalArgumentException("Only GPU device is allowed."); } int deviceId = device.getDeviceId(); long[] ret = new long[2]; LongBuffer freeMem = LongBuffer.wrap(ret, 0, 1); LongBuffer totalMem = LongBuffer.wrap(ret, 1, 1); checkCall(LIB.MXGetGPUMemoryInformation64(deviceId, freeMem, totalMem)); return ret; }
Example 11
Source File: CodecUtils.java From metrics with Apache License 2.0 | 5 votes |
public static void decodeBlockPack( LongBuffer src, LongFilterFactory filterFactory, LongBitPacking packer, LongOutputStream dst) { // Fetch length of original array. if (!src.hasRemaining()) { return; } final int outLen = (int)src.get() - 1; // Fetch and output first int, and set it as delta's initial context. final long first = src.get(); dst.write(first); LongFilter filter = filterFactory.newFilter(first); // Decompress intermediate blocks. final int chunkSize = packer.getBlockSize(); final int chunkNum = outLen / chunkSize; if (chunkNum > 0) { packer.decompress(src, dst, filter, chunkNum); } // Decompress last block. final int chunkRemain = outLen % chunkSize; if (chunkRemain > 0) { long[] last = new long[chunkSize]; LongBuffer buf = LongBuffer.wrap(last); packer.decompress(src, new LongBufferOutputStream(buf), filter, 1); dst.write(last, 0, chunkRemain); } }
Example 12
Source File: LongDZBP.java From metrics with Apache License 2.0 | 5 votes |
public void decompress(LongBuffer src, LongOutputStream dst) { // Fetch length of original array. if (!src.hasRemaining()) { return; } final int outLen = (int)src.get() - 1; // Fetch and output first int, and set it as delta's initial context. final long first = src.get(); dst.write(first); DZDecodeFilter filter = new DZDecodeFilter(first); // Decompress intermediate blocks. final int chunkSize = this.bitPack.getBlockSize(); final int chunkNum = outLen / chunkSize; if (chunkNum > 0) { this.bitPack.decompress(src, dst, filter, chunkNum); } // Decompress last block. final int chunkRemain = outLen % chunkSize; if (chunkRemain > 0) { long[] last = new long[chunkSize]; LongBuffer buf = LongBuffer.wrap(last); this.bitPack.decompress(src, new LongBufferOutputStream(buf), filter, 1); dst.write(last, 0, chunkRemain); } }
Example 13
Source File: DataBuffers.java From java with Apache License 2.0 | 5 votes |
/** * Create a buffer from an array of longs into a data buffer. * * @param array array of longs * @param readOnly true if the buffer created must be read-only * @param makeCopy true if the array must be copied, false will wrap the provided array * @return a new buffer */ public static LongDataBuffer of(long[] array, boolean readOnly, boolean makeCopy) { long[] bufferArray = makeCopy ? Arrays.copyOf(array, array.length) : array; if (RawDataBufferFactory.canBeUsed()) { return RawDataBufferFactory.create(bufferArray, readOnly); } LongBuffer buf = LongBuffer.wrap(bufferArray); return NioDataBufferFactory.create(readOnly ? buf.asReadOnlyBuffer() : buf); }
Example 14
Source File: ThreadSafeLongBuffer.java From succinct with Apache License 2.0 | 4 votes |
public static ThreadSafeLongBuffer wrap(long[] array) { return new ThreadSafeLongBuffer(LongBuffer.wrap(array)); }
Example 15
Source File: cl_abstract_properties.java From Concurnas with MIT License | 4 votes |
/** * Creates new, empty cl_abstract_properties */ cl_abstract_properties() { super(LongBuffer.wrap(new long[]{0})); }
Example 16
Source File: LongArrayInputStream.java From metrics with Apache License 2.0 | 4 votes |
public LongArrayInputStream(long[] array, int off, int len) { this.buffer = LongBuffer.wrap(array, off, len); }
Example 17
Source File: UnsafeMemoryHandle.java From java with Apache License 2.0 | 4 votes |
LongBuffer toArrayLongBuffer() { return LongBuffer.wrap((long[])object, (int)((byteOffset - UnsafeReference.UNSAFE.arrayBaseOffset(long[].class)) / scale), (int)size); }
Example 18
Source File: BitMap.java From succinct with Apache License 2.0 | 2 votes |
/** * Serializes bitmap array data as a LongBuffer. * * @return Serialized bitmap array data as LongBuffer. */ public LongBuffer getLongBuffer() { return LongBuffer.wrap(data); }