/** Calls {@code LongBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ public LongBufferIndexer(LongBuffer buffer) { this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); }
@Override public int getSizeInBytes() { return this.bitmap.limit() * 8; }
@Override public int hashCode() { long hash = 0; int len = this.bitmap.limit(); for (int k = 0; k < len; ++k) { hash += 31 * hash + this.bitmap.get(k); } return (int) hash; }
/** * Construct a new BitmapContainer backed by the provided LongBuffer. * * @param array LongBuffer where the data is stored * @param initCardinality cardinality (number of values stored) */ public MappeableBitmapContainer(final LongBuffer array, final int initCardinality) { if (array.limit() != MAX_CAPACITY / 64) { throw new RuntimeException("Mismatch between buffer and storage requirements: " + array.limit() + " vs. " + MAX_CAPACITY / 64); } this.cardinality = initCardinality; this.bitmap = array; }
/** Returns a string representing the state of this long buffer. * * @return a string representing the state of this long buffer. * @since Android 1.0 */ public String toString () { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(", status: capacity="); //$NON-NLS-1$ sb.append(capacity()); sb.append(" position="); //$NON-NLS-1$ sb.append(position()); sb.append(" limit="); //$NON-NLS-1$ sb.append(limit()); return sb.toString(); } }
/** Returns a string representing the state of this long buffer. * * @return a string representing the state of this long buffer. * @since Android 1.0 */ public String toString () { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(", status: capacity="); //$NON-NLS-1$ sb.append(capacity()); sb.append(" position="); //$NON-NLS-1$ sb.append(position()); sb.append(" limit="); //$NON-NLS-1$ sb.append(limit()); return sb.toString(); } }
@Override public void clear() { if (cardinality != 0) { cardinality = 0; int len = this.bitmap.limit(); for (int k = 0; k < len; ++k) { bitmap.put(k, 0); } } }
/** * Create a copy of the content of this container as a long array. This creates a copy. * * @return copy of the content as a long array */ public long[] toLongArray() { long[] answer = new long[bitmap.limit()]; bitmap.rewind(); bitmap.get(answer); return answer; }
@Override protected void writeArray(DataOutput out) throws IOException { // little endian int len = this.bitmap.limit(); if (BufferUtil.isBackedBySimpleArray(bitmap)) { long[] b = bitmap.array(); for (int k = 0; k < len; ++k) { out.writeLong(Long.reverseBytes(b[k])); } } else { for (int k = 0; k < len; ++k) { final long w = bitmap.get(k); out.writeLong(Long.reverseBytes(w)); } } }
protected static void fillArrayXOR(short[] container, LongBuffer bitmap1, LongBuffer bitmap2) { int pos = 0; if (bitmap1.limit() != bitmap2.limit()) { throw new IllegalArgumentException("not supported"); } if (BufferUtil.isBackedBySimpleArray(bitmap1) && BufferUtil.isBackedBySimpleArray(bitmap2)) { org.roaringbitmap.Util.fillArrayXOR(container, bitmap1.array(), bitmap2.array()); } else { int len = bitmap1.limit(); for (int k = 0; k < len; ++k) { long bitset = bitmap1.get(k) ^ bitmap2.get(k); while (bitset != 0) { container[pos++] = (short) (k * 64 + numberOfTrailingZeros(bitset)); bitset &= (bitset - 1); } } } }
/** * Recomputes the cardinality of the bitmap. */ protected void computeCardinality() { this.cardinality = 0; if (BufferUtil.isBackedBySimpleArray(bitmap)) { long[] b = this.bitmap.array(); for (int k = 0; k < b.length; k++) { this.cardinality += Long.bitCount(b[k]); } } else { int m = this.bitmap.limit(); for (int k = 0; k < m; k++) { this.cardinality += Long.bitCount(this.bitmap.get(k)); } } }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // little endian this.cardinality = 0; int len = this.bitmap.limit(); if (BufferUtil.isBackedBySimpleArray(bitmap)) { long[] b = this.bitmap.array(); for (int k = 0; k < len; ++k) { long w = Long.reverseBytes(in.readLong()); b[k] = w; this.cardinality += Long.bitCount(w); } } else { for (int k = 0; k < len; ++k) { long w = Long.reverseBytes(in.readLong()); bitmap.put(k, w); this.cardinality += Long.bitCount(w); } } }
@Override public int last() { assertNonEmpty(cardinality == 0); long lastNonZeroWord; int i = bitmap.limit() - 1; if(BufferUtil.isBackedBySimpleArray(bitmap)) { long[] array = this.bitmap.array(); while(i > 0 && array[i] == 0) { --i; } lastNonZeroWord = array[i]; } else { while(i > 0 && bitmap.get(i) == 0) { --i; } lastNonZeroWord = bitmap.get(i); } return (i + 1) * 64 - Long.numberOfLeadingZeros(lastNonZeroWord) - 1; }
@Override public int andCardinality(final MappeableBitmapContainer value2) { int newCardinality = 0; if (BufferUtil.isBackedBySimpleArray(this.bitmap) && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { long[] b1 = this.bitmap.array(); long[] b2 = value2.bitmap.array(); for (int k = 0; k < b1.length; ++k) { newCardinality += Long.bitCount(b1[k] & b2[k]); } } else { final int size = this.bitmap.limit(); for (int k = 0; k < size; ++k) { newCardinality += Long.bitCount(this.bitmap.get(k) & value2.bitmap.get(k)); } } return newCardinality; }
protected MappeableContainer ilazyor(MappeableBitmapContainer x) { if (BufferUtil.isBackedBySimpleArray(x.bitmap)) { long[] b = this.bitmap.array(); long[] b2 = x.bitmap.array(); for (int k = 0; k < b.length; k++) { b[k] |= b2[k]; } } else { final int m = this.bitmap.limit(); for (int k = 0; k < m; k++) { this.bitmap.put(k, this.bitmap.get(k) | x.bitmap.get(k)); } } this.cardinality = -1;// invalid return this; }
@Override public void setArg(int index, long l) { LongBuffer buf = Utils.tempBuffers[0].b16l; buf.position(0); buf.limit(1); buf.put(0, l); int ret = cl.clSetKernelArg(kernel, index, 8, buf); Utils.checkError(ret, "clSetKernelArg"); }
@Override public void setArg(int index, long l) { LongBuffer buf = Utils.tempBuffers[0].b16l; buf.position(0); buf.limit(1); buf.put(0, l); int ret = CL10.clSetKernelArg(kernel, index, buf); Utils.checkError(ret, "clSetKernelArg"); }
MappeableBitmapContainer(int newCardinality, LongBuffer newBitmap) { this.cardinality = newCardinality; LongBuffer tmp = newBitmap.duplicate(); // for thread safety this.bitmap = LongBuffer.allocate(tmp.limit()); tmp.rewind(); this.bitmap.put(tmp); }
/** * Fill a buffer with a repeated value. * * @param buffer the buffer to fill * @param value the value to fill * @param count the number of longs to fill * @return the buffer instance */ public static LongBuffer fill(LongBuffer buffer, long value, int count) { if (count > buffer.remaining()) { throw msg.bufferUnderflow(); } if (buffer.hasArray()) { final int offs = buffer.arrayOffset(); Arrays.fill(buffer.array(), offs + buffer.position(), offs + buffer.limit(), value); skip(buffer, count); } else { for (int i = count; i > 0; i--) { buffer.put(value); } } return buffer; }
/** * For direct buffers, calls {@link Pointer#Pointer(Buffer)}, while for buffers * backed with an array, allocates enough memory for the array and copies it. * * @param buffer the Buffer to reference or copy * @see #put(long[]) */ public LongPointer(LongBuffer buffer) { super(buffer); if (buffer != null && !buffer.isDirect() && buffer.hasArray()) { long[] array = buffer.array(); allocateArray(array.length - buffer.arrayOffset()); put(array, buffer.arrayOffset(), array.length - buffer.arrayOffset()); position(buffer.position()); limit(buffer.limit()); } } /**