Search in sources :

Example 61 with ShortBuffer

use of java.nio.ShortBuffer in project RoaringBitmap by RoaringBitmap.

the class TestUtil method testIterateUntil.

@Test
public void testIterateUntil() {
    ShortBuffer data = ShortBuffer.wrap(new short[] { 0, 3, 16, 18, 21, 29, 30, -342 });
    Assert.assertEquals(1, BufferUtil.iterateUntil(data, 0, data.limit(), BufferUtil.toIntUnsigned((short) 3)));
    Assert.assertEquals(5, BufferUtil.iterateUntil(data, 0, data.limit(), BufferUtil.toIntUnsigned((short) 28)));
    Assert.assertEquals(5, BufferUtil.iterateUntil(data, 0, data.limit(), BufferUtil.toIntUnsigned((short) 29)));
    Assert.assertEquals(7, BufferUtil.iterateUntil(data, 0, data.limit(), BufferUtil.toIntUnsigned((short) -342)));
}
Also used : ShortBuffer(java.nio.ShortBuffer) Test(org.junit.Test)

Example 62 with ShortBuffer

use of java.nio.ShortBuffer in project RoaringBitmap by RoaringBitmap.

the class TestUtil method testUnsignedIntersects.

@Test
public void testUnsignedIntersects() {
    ShortBuffer data1 = ShortBuffer.wrap(new short[] { -100, -98, -96, -94, -92, -90, -88, -86, -84, -82, -80 });
    ShortBuffer data2 = ShortBuffer.wrap(new short[] { -99, -97, -95, -93, -91, -89, -87, -85, -83, -81, -79 });
    ShortBuffer data3 = ShortBuffer.wrap(new short[] { -99, -97, -95, -93, -91, -89, -87, -85, -83, -81, -80 });
    ShortBuffer data4 = ShortBuffer.wrap(new short[] {});
    ShortBuffer data5 = ShortBuffer.wrap(new short[] {});
    Assert.assertFalse(BufferUtil.unsignedIntersects(data1, data1.limit(), data2, data2.limit()));
    Assert.assertTrue(BufferUtil.unsignedIntersects(data1, data1.limit(), data3, data3.limit()));
    Assert.assertFalse(BufferUtil.unsignedIntersects(data4, data4.limit(), data5, data5.limit()));
}
Also used : ShortBuffer(java.nio.ShortBuffer) Test(org.junit.Test)

Example 63 with ShortBuffer

use of java.nio.ShortBuffer in project RoaringBitmap by RoaringBitmap.

the class TestUtil method testCopy.

@Test
public void testCopy() {
    ShortBuffer sb = ShortBuffer.allocate(64);
    sb.position(32);
    ShortBuffer slice = sb.slice();
    ShortBuffer dest = ShortBuffer.allocate(64);
    for (int k = 0; k < 32; ++k) slice.put(k, (short) k);
    BufferUtil.arraycopy(slice, 16, dest, 16, 16);
    for (int k = 16; k < 32; ++k) Assert.assertEquals((short) k, dest.get(k));
    BufferUtil.arraycopy(slice, 0, dest, 16, 16);
    for (int k = 16; k < 32; ++k) Assert.assertEquals((short) (k - 16), dest.get(k));
    BufferUtil.arraycopy(slice, 16, dest, 0, 16);
    for (int k = 0; k < 16; ++k) Assert.assertEquals((short) (k + 16), dest.get(k));
}
Also used : ShortBuffer(java.nio.ShortBuffer) Test(org.junit.Test)

Example 64 with ShortBuffer

use of java.nio.ShortBuffer in project RoaringBitmap by RoaringBitmap.

the class ReverseRunContainerShortIterator method toShortBuffer.

/**
 * Return the content of this container as a ShortBuffer. This creates a copy and might be
 * relatively slow.
 *
 * @return the ShortBuffer
 */
public ShortBuffer toShortBuffer() {
    ShortBuffer sb = ShortBuffer.allocate(this.nbrruns * 2);
    sb.put(this.valueslength, 0, this.nbrruns * 2);
    return sb;
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 65 with ShortBuffer

use of java.nio.ShortBuffer in project RoaringBitmap by RoaringBitmap.

the class ImmutableRoaringArray method getContainerAtIndex.

@Override
public MappeableContainer getContainerAtIndex(int i) {
    // sad but ByteBuffer is not thread-safe so it is either a
    ByteBuffer tmp = buffer.duplicate();
    // duplicate or a lock
    // note that tmp will indeed be garbage-collected some time after the end of this function
    tmp.order(buffer.order());
    tmp.position(getOffsetContainer(i));
    boolean hasrun = hasRunCompression();
    if (isRunContainer(i, hasrun)) {
        // first, we have a short giving the number of runs
        int nbrruns = BufferUtil.toIntUnsigned(tmp.getShort());
        final ShortBuffer shortArray = tmp.asShortBuffer();
        shortArray.limit(2 * nbrruns);
        return new MappeableRunContainer(shortArray, nbrruns);
    }
    int cardinality = getCardinality(i);
    // if not a
    final boolean isBitmap = cardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE;
    // runcontainer
    if (isBitmap) {
        final LongBuffer bitmapArray = tmp.asLongBuffer();
        bitmapArray.limit(MappeableBitmapContainer.MAX_CAPACITY / 64);
        return new MappeableBitmapContainer(bitmapArray, cardinality);
    } else {
        final ShortBuffer shortArray = tmp.asShortBuffer();
        shortArray.limit(cardinality);
        return new MappeableArrayContainer(shortArray, cardinality);
    }
}
Also used : LongBuffer(java.nio.LongBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Aggregations

ShortBuffer (java.nio.ShortBuffer)227 ByteBuffer (java.nio.ByteBuffer)78 FloatBuffer (java.nio.FloatBuffer)54 IntBuffer (java.nio.IntBuffer)45 DoubleBuffer (java.nio.DoubleBuffer)23 LongBuffer (java.nio.LongBuffer)16 Test (org.junit.Test)14 Buffer (java.nio.Buffer)11 BufferOverflowException (java.nio.BufferOverflowException)11 CharBuffer (java.nio.CharBuffer)11 VertexBuffer (com.jme3.scene.VertexBuffer)8 BufferUnderflowException (java.nio.BufferUnderflowException)7 BytePointer (org.bytedeco.javacpp.BytePointer)7 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)6 IOException (java.io.IOException)5 Vector3f (com.jme3.math.Vector3f)4 ArrayList (java.util.ArrayList)4 Bitmap (android.graphics.Bitmap)3 Mesh (com.jme3.scene.Mesh)3 InvalidMarkException (java.nio.InvalidMarkException)3