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)));
}
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()));
}
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));
}
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;
}
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);
}
}
Aggregations