Search in sources :

Example 66 with ShortBuffer

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

the class ReverseMappeableArrayContainerShortIterator method inot.

@Override
public // not thread safe! (duh!)
MappeableContainer inot(final int firstOfRange, final int lastOfRange) {
    // TODO: may need to convert to a RunContainer
    // TODO: this can be optimized for performance
    // determine the span of array indices to be affected
    int startIndex = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) firstOfRange);
    if (startIndex < 0) {
        startIndex = -startIndex - 1;
    }
    int lastIndex = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (lastOfRange - 1));
    if (lastIndex < 0) {
        lastIndex = -lastIndex - 1 - 1;
    }
    final int currentValuesInRange = lastIndex - startIndex + 1;
    final int spanToBeFlipped = lastOfRange - firstOfRange;
    final int newValuesInRange = spanToBeFlipped - currentValuesInRange;
    final ShortBuffer buffer = ShortBuffer.allocate(newValuesInRange);
    final int cardinalityChange = newValuesInRange - currentValuesInRange;
    final int newCardinality = cardinality + cardinalityChange;
    if (cardinalityChange > 0) {
        // expansion, right shifting needed
        if (newCardinality > content.limit()) {
            // so big we need a bitmap?
            if (newCardinality > DEFAULT_MAX_SIZE) {
                return toBitmapContainer().inot(firstOfRange, lastOfRange);
            }
            final ShortBuffer co = ShortBuffer.allocate(newCardinality);
            content.rewind();
            co.put(content);
            content = co;
        }
        // slide right the contents after the range
        for (int pos = cardinality - 1; pos > lastIndex; --pos) {
            content.put(pos + cardinalityChange, content.get(pos));
        }
        negateRange(buffer, startIndex, lastIndex, firstOfRange, lastOfRange);
    } else {
        // no expansion needed
        negateRange(buffer, startIndex, lastIndex, firstOfRange, lastOfRange);
        if (cardinalityChange < 0) {
            // Leave array oversize
            for (int i = startIndex + newValuesInRange; i < newCardinality; ++i) {
                content.put(i, content.get(i - cardinalityChange));
            }
        }
    }
    cardinality = newCardinality;
    return this;
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 67 with ShortBuffer

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

the class ReverseMappeableRunContainerShortIterator method copyValuesLength.

private void copyValuesLength(ShortBuffer src, int srcIndex, ShortBuffer dst, int dstIndex, int length) {
    if (BufferUtil.isBackedBySimpleArray(src) && BufferUtil.isBackedBySimpleArray(dst)) {
        // common case.
        System.arraycopy(src.array(), 2 * srcIndex, dst.array(), 2 * dstIndex, 2 * length);
        return;
    }
    // source and destination may overlap
    // consider specialized code for various cases, rather than using a second buffer
    ShortBuffer temp = ShortBuffer.allocate(2 * length);
    for (int i = 0; i < 2 * length; ++i) {
        temp.put(src.get(2 * srcIndex + i));
    }
    temp.flip();
    for (int i = 0; i < 2 * length; ++i) {
        dst.put(2 * dstIndex + i, temp.get());
    }
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 68 with ShortBuffer

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

the class ReverseMappeableRunContainerShortIterator method increaseCapacity.

// not thread safe!
private void increaseCapacity() {
    int newCapacity = (valueslength.capacity() == 0) ? DEFAULT_INIT_SIZE : valueslength.capacity() < 64 ? valueslength.capacity() * 2 : valueslength.capacity() < 1024 ? valueslength.capacity() * 3 / 2 : valueslength.capacity() * 5 / 4;
    final ShortBuffer nv = ShortBuffer.allocate(newCapacity);
    valueslength.rewind();
    nv.put(valueslength);
    valueslength = nv;
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 69 with ShortBuffer

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

the class ReverseMappeableRunContainerShortIterator method copyToOffset.

// Push all values length to the end of the array (resize array if needed)
private void copyToOffset(int offset) {
    final int minCapacity = 2 * (offset + nbrruns);
    if (valueslength.capacity() < minCapacity) {
        // expensive case where we need to reallocate
        int newCapacity = valueslength.capacity();
        while (newCapacity < minCapacity) {
            newCapacity = (newCapacity == 0) ? DEFAULT_INIT_SIZE : newCapacity < 64 ? newCapacity * 2 : newCapacity < 1024 ? newCapacity * 3 / 2 : newCapacity * 5 / 4;
        }
        ShortBuffer newvalueslength = ShortBuffer.allocate(newCapacity);
        copyValuesLength(this.valueslength, 0, newvalueslength, offset, nbrruns);
        this.valueslength = newvalueslength;
    } else {
        // efficient case where we just copy
        copyValuesLength(this.valueslength, 0, this.valueslength, offset, nbrruns);
    }
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 70 with ShortBuffer

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

the class ReverseMappeableRunContainerShortIterator method trim.

@Override
public void trim() {
    if (valueslength.limit() == 2 * nbrruns) {
        return;
    }
    if (BufferUtil.isBackedBySimpleArray(valueslength)) {
        this.valueslength = ShortBuffer.wrap(Arrays.copyOf(valueslength.array(), 2 * nbrruns));
    } else {
        final ShortBuffer co = ShortBuffer.allocate(2 * nbrruns);
        short[] a = co.array();
        for (int k = 0; k < 2 * nbrruns; ++k) {
            a[k] = this.valueslength.get(k);
        }
        this.valueslength = co;
    }
}
Also used : 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