Java Code Examples for java.nio.LongBuffer#put()

The following examples show how to use java.nio.LongBuffer#put() . 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: BufferUtil.java    From RoaringBitmap with Apache License 2.0 6 votes vote down vote up
/**
 * flip bits at start, start+1,..., end-1
 *
 * @param bitmap array of words to be modified
 * @param start first index to be modified (inclusive)
 * @param end last index to be modified (exclusive)
 */
public static void flipBitmapRange(LongBuffer bitmap, int start, int end) {
  if (isBackedBySimpleArray(bitmap)) {
    Util.flipBitmapRange(bitmap.array(), start, end);
    return;
  }
  if (start == end) {
    return;
  }
  int firstword = start / 64;
  int endword = (end - 1) / 64;
  bitmap.put(firstword, bitmap.get(firstword) ^ ~(~0L << start));
  for (int i = firstword; i < endword; i++) {
    bitmap.put(i, ~bitmap.get(i));
  }
  bitmap.put(endword, bitmap.get(endword) ^ (~0L >>> -end));
}
 
Example 2
Source File: ArrayUtils.java    From pixymeta-android with Eclipse Public License 1.0 6 votes vote down vote up
public static byte[] toByteArray(long[] data, boolean bigEndian) {
	
	ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 8);
	
	if (bigEndian) {
		byteBuffer.order(ByteOrder.BIG_ENDIAN);
	} else {
		byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
	}
       
	LongBuffer longBuffer = byteBuffer.asLongBuffer();
       longBuffer.put(data);

       byte[] array = byteBuffer.array();

	return array;
}
 
Example 3
Source File: BufferUtil.java    From RoaringBitmap with Apache License 2.0 6 votes vote down vote up
/**
 * set bits at start, start+1,..., end-1
 *
 * @param bitmap array of words to be modified
 * @param start first index to be modified (inclusive)
 * @param end last index to be modified (exclusive)
 */
public static void setBitmapRange(LongBuffer bitmap, int start, int end) {
  if (isBackedBySimpleArray(bitmap)) {
    Util.setBitmapRange(bitmap.array(), start, end);
    return;
  }
  if (start == end) {
    return;
  }
  int firstword = start / 64;
  int endword = (end - 1) / 64;
  if (firstword == endword) {
    bitmap.put(firstword, bitmap.get(firstword) | ((~0L << start) & (~0L >>> -end)));

    return;
  }
  bitmap.put(firstword, bitmap.get(firstword) | (~0L << start));
  for (int i = firstword + 1; i < endword; i++) {
    bitmap.put(i, ~0L);
  }
  bitmap.put(endword, bitmap.get(endword) | (~0L >>> -end));
}
 
Example 4
Source File: ArrayUtils.java    From icafe with Eclipse Public License 1.0 6 votes vote down vote up
public static byte[] toByteArray(long[] data, boolean bigEndian) {
	
	ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 8);
	
	if (bigEndian) {
		byteBuffer.order(ByteOrder.BIG_ENDIAN);
	} else {
		byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
	}
       
	LongBuffer longBuffer = byteBuffer.asLongBuffer();
       longBuffer.put(data);

       byte[] array = byteBuffer.array();

	return array;
}
 
Example 5
Source File: TestMappeableBitmapContainer.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Test
public void xorBitmap2() {
  LongBuffer buffer = LongBuffer.allocate(MAX_CAPACITY / 64);
  for (int i = 0; i < 128; i++) {
    buffer.put(~0L);
  }
  MappeableContainer bc = new MappeableBitmapContainer(buffer.asReadOnlyBuffer(), 8192);
  MappeableContainer bc2 = new MappeableBitmapContainer();
  bc2 = bc2.add(5000, 8192);
  bc = bc.xor(bc2);
  assertEquals(5000, bc.getCardinality());
  for (char i = 0; i < 5000; i++) {
    assertTrue(bc.contains(i));
  }
}
 
Example 6
Source File: BinUtils.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public static byte[] longToByteArray(long inLong) {
	byte[] bArray = new byte[8];
	ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
	LongBuffer lBuffer = bBuffer.asLongBuffer();
	lBuffer.put(inLong);
	return bArray;
}
 
Example 7
Source File: NameGenerator.java    From yawp with MIT License 5 votes vote down vote up
private static byte[] toByteArray(UUID uuid) {
    byte[] byteArray = new byte[(Long.SIZE / Byte.SIZE) * 2];
    ByteBuffer buffer = ByteBuffer.wrap(byteArray);
    LongBuffer longBuffer = buffer.asLongBuffer();
    longBuffer.put(new long[]{uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()});
    return byteArray;
}
 
Example 8
Source File: LongTensorTypeSupport.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public void writeField(LongBuffer buffer, Field field) {
  Utils.checkState(
      field.getType() == Field.Type.LONG,
      Utils.format("Not a Long scalar, it is {}", field.getType())
  );
  buffer.put(field.getValueAsLong());
}
 
Example 9
Source File: RandomAccessLongStreamTest.java    From succinct with Apache License 2.0 5 votes vote down vote up
public void testPosition() throws Exception {
  LongBuffer buf = LongBuffer.allocate(10);
  for (int i = 0; i < 10; i++) {
    buf.put(i);
  }
  FSDataInputStream is = TestUtils.getStream(buf);
  RandomAccessLongStream bs = new RandomAccessLongStream(is, 0, 80);
  bs.position(3);
  assertEquals(bs.position(), 3);
}
 
Example 10
Source File: StorageUtilities.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void controlInfoToByteArray(final byte[] data, final int offset,
                                          final byte controlByte, final long position) {

   data[offset] = controlByte;
   final ByteBuffer bBuffer = ByteBuffer.wrap(data, offset + 1, 8);
   final LongBuffer lBuffer = bBuffer.asLongBuffer();
   lBuffer.put(0, position);
}
 
Example 11
Source File: BufferUtil.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
/**
 * Intersects the bitmap with the array, returning the cardinality of the result
 * @param bitmap the bitmap, modified
 * @param array the array, not modified
 * @param length how much of the array to consume
 * @return the size of the intersection, i.e. how many bits still set in the bitmap
 */
public static int intersectArrayIntoBitmap(LongBuffer bitmap, CharBuffer array, int length) {
  if (isBackedBySimpleArray(bitmap)) {
    return intersectArrayIntoBitmap(bitmap.array(), array, length);
  }
  int lastWordIndex = 0;
  int wordIndex = 0;
  long word = 0L;
  int cardinality = 0;
  for (int i = 0; i < length; ++i) {
    wordIndex = array.get(i) >>> 6;
    if (wordIndex != lastWordIndex) {
      long lastWord = bitmap.get(lastWordIndex);
      lastWord &= word;
      bitmap.put(lastWordIndex, lastWord);
      cardinality += Long.bitCount(lastWord);
      word = 0L;
      for (int j = lastWordIndex + 1; j < wordIndex; ++j) {
        bitmap.put(j, 0L);
      }
      lastWordIndex = wordIndex;
    }
    word |= 1L << array.get(i);
  }
  if (word != 0L) {
    long currentWord = bitmap.get(wordIndex);
    currentWord &= word;
    bitmap.put(wordIndex, currentWord);
    cardinality += Long.bitCount(currentWord);
  }
  if (wordIndex < bitmap.limit()) {
    for (int j = wordIndex + 1; j < bitmap.limit(); ++j) {
      bitmap.put(j, 0L);
    }
  }
  return cardinality;
}
 
Example 12
Source File: NotesOriginatorIdStruct.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a new universal id stored by this OID
 * 
 * @param unid new universal id
 */
public void setUNID(String unid) {
	if (unid.length()!=32) {
		throw new IllegalArgumentException("Invalid unid: "+unid);
	}
	
	for (int i=0; i<32; i++) {
		char c = unid.charAt(i);
		if ((c>='0' && c<='9') || (c>='A' && c<='F') || (c>='a' && c<='f')) {
			
		}
		else {
			throw new IllegalArgumentException("Invalid unid: "+unid);
		}
	}
	
	write();
	
	Pointer oidPtr = getPointer();
	ByteBuffer data = oidPtr.getByteBuffer(0, 16).order(ByteOrder.LITTLE_ENDIAN);
	LongBuffer longBuffer = data.asLongBuffer();
	
	String firstPart = unid.substring(0, 16);
	long firstPartAsLong = new BigInteger(firstPart, 16).longValue();
	longBuffer.put(0, firstPartAsLong);
	
	String secondPart = unid.substring(16);
	long secondPartAsLong = new BigInteger(secondPart, 16).longValue();
	longBuffer.put(1, secondPartAsLong);
	
	read();
	
	String newWrittenUnid = getUNIDAsString();
	if (!unid.equalsIgnoreCase(newWrittenUnid)) {
		//should not happen ;-)
		throw new IllegalStateException("Error setting new UNID in OID structure. Probably wrong memory alignment. Please contact dev.");
	}
}
 
Example 13
Source File: BinUtils.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public static byte[] longToByteArrayLittleEndian(long inLong) {
	byte[] bArray = new byte[8];
	ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
	bBuffer.order(ByteOrder.LITTLE_ENDIAN);
	LongBuffer lBuffer = bBuffer.asLongBuffer();
	lBuffer.put(inLong);
	return bArray;
}
 
Example 14
Source File: TestMappeableBitmapContainer.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Test
public void andNotBitmap() {
  LongBuffer buffer = LongBuffer.allocate(MAX_CAPACITY / 64);
  buffer.put(~0L);
  MappeableContainer bc = new MappeableBitmapContainer(buffer.asReadOnlyBuffer(), 64);
  MappeableContainer bc2 = new MappeableBitmapContainer();
  bc2 = bc2.add(32, 64);
  bc = bc.andNot(bc2);
  assertEquals(32, bc.getCardinality());
  for (char i = 0; i < 32; i++) {
    assertTrue(bc.contains(i));
  }
}
 
Example 15
Source File: CommandBuffer.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
public void bindVertexInputCmd(long vertexBuffer, long indexBuffer){
	
	LongBuffer offsets = memAllocLong(1);
	offsets.put(0, 0L);
	LongBuffer pVertexBuffers = memAllocLong(1);
	pVertexBuffers.put(0, vertexBuffer);
	
	vkCmdBindVertexBuffers(handle, 0, pVertexBuffers, offsets);
	vkCmdBindIndexBuffer(handle, indexBuffer, 0, VK_INDEX_TYPE_UINT32);
	
	memFree(pVertexBuffers);
	memFree(offsets);
}
 
Example 16
Source File: TestMappeableBitmapContainer.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Test
public void foreach() {
  LongBuffer buffer = LongBuffer.allocate(MAX_CAPACITY / 64);
  buffer.put(~0L);
  MappeableContainer bc = new MappeableBitmapContainer(buffer.asReadOnlyBuffer(), 64);
  bc.forEach((char) 0, new IntConsumer() {
    int expected = 0;

    @Override
    public void accept(int value) {
      assertEquals(value, expected++);
    }
  });
}
 
Example 17
Source File: BGZFBlockIndexer.java    From Hadoop-BAM with MIT License 5 votes vote down vote up
private void index(final File file) throws IOException {
       try (final InputStream in = new FileInputStream(file);
            final OutputStream out = new BufferedOutputStream(new FileOutputStream(file.getPath() + ".bgzfi"))) {

           final LongBuffer lb =
               byteBuffer.order(ByteOrder.BIG_ENDIAN).asLongBuffer();

           long prevPrint = 0;
           pos = 0;

           for (int i = 0;;) {
               if (!skipBlock(in))
                   break;

               if (++i == granularity) {
                   i = 0;
                   lb.put(0, pos);
                   out.write(byteBuffer.array(), 2, 6);

                   if (pos - prevPrint >= PRINT_EVERY) {
                       System.out.print("-");
                       prevPrint = pos;
                   }
               }
           }
           lb.put(0, file.length());
           out.write(byteBuffer.array(), 2, 6);
       }
}
 
Example 18
Source File: OffScreenFbo.java    From oreon-engine with GNU General Public License v3.0 4 votes vote down vote up
public OffScreenFbo(VkDevice device, VkPhysicalDeviceMemoryProperties memoryProperties) {

		width = BaseContext.getConfig().getFrameWidth();
		height = BaseContext.getConfig().getFrameHeight();
		int samples = BaseContext.getConfig().getMultisampling_sampleCount();

		VkImageBundle albedoAttachment = new FrameBufferColorAttachment(device, memoryProperties,
				width, height, VK_FORMAT_R16G16B16A16_SNORM, samples);
		
		VkImageBundle worldPositionAttachment = new FrameBufferColorAttachment(device, memoryProperties,
				width, height, VK_FORMAT_R32G32B32A32_SFLOAT, samples);

		VkImageBundle normalAttachment = new FrameBufferColorAttachment(device, memoryProperties,
				width, height, VK_FORMAT_R16G16B16A16_SFLOAT, samples);

		VkImageBundle lightScatteringMaskAttachment = new FrameBufferColorAttachment(device, memoryProperties,
				width, height, VK_FORMAT_R16G16B16A16_SFLOAT, samples);
		
		VkImageBundle specularEmissionAttachment = new FrameBufferColorAttachment(device, memoryProperties,
				width, height, VK_FORMAT_R16G16B16A16_SFLOAT, samples);

		VkImageBundle depthBuffer = new FrameBufferDepthAttachment(device, memoryProperties,
				width, height, VK_FORMAT_D32_SFLOAT, samples);

		attachments.put(Attachment.COLOR, albedoAttachment);
		attachments.put(Attachment.POSITION, worldPositionAttachment);
		attachments.put(Attachment.NORMAL, normalAttachment);
		attachments.put(Attachment.LIGHT_SCATTERING, lightScatteringMaskAttachment);
		attachments.put(Attachment.SPECULAR_EMISSION_DIFFUSE_SSAO_BLOOM, specularEmissionAttachment);
		attachments.put(Attachment.DEPTH, depthBuffer);

		renderPass = new RenderPass(device);
		renderPass.addColorAttachment(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 
				VK_FORMAT_R16G16B16A16_SFLOAT, samples, VK_IMAGE_LAYOUT_UNDEFINED,
				VK_IMAGE_LAYOUT_GENERAL);
		renderPass.addColorAttachment(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 
				VK_FORMAT_R32G32B32A32_SFLOAT, samples, VK_IMAGE_LAYOUT_UNDEFINED,
				VK_IMAGE_LAYOUT_GENERAL);
		renderPass.addColorAttachment(2, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
				VK_FORMAT_R16G16B16A16_SFLOAT, samples, VK_IMAGE_LAYOUT_UNDEFINED,
				VK_IMAGE_LAYOUT_GENERAL);
		renderPass.addColorAttachment(3, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
				VK_FORMAT_R16G16B16A16_SFLOAT, samples, VK_IMAGE_LAYOUT_UNDEFINED,
				VK_IMAGE_LAYOUT_GENERAL);
		renderPass.addColorAttachment(4, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
				VK_FORMAT_R16G16B16A16_SFLOAT, samples, VK_IMAGE_LAYOUT_UNDEFINED,
				VK_IMAGE_LAYOUT_GENERAL);
		renderPass.addDepthAttachment(5, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
				VK_FORMAT_D32_SFLOAT, samples, VK_IMAGE_LAYOUT_UNDEFINED,
				VK_IMAGE_LAYOUT_GENERAL);
		
		renderPass.addSubpassDependency(VK_SUBPASS_EXTERNAL, 0,
				VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
				VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
				VK_ACCESS_MEMORY_READ_BIT,
				VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
				VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
				VK_DEPENDENCY_BY_REGION_BIT);
		renderPass.addSubpassDependency(0, VK_SUBPASS_EXTERNAL,
				VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
				VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
				VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
				VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
				VK_ACCESS_SHADER_READ_BIT,
				VK_DEPENDENCY_BY_REGION_BIT);
		renderPass.createSubpass();
		renderPass.createRenderPass();

		depthAttachmentCount = 1;
		colorAttachmentCount = renderPass.getAttachmentCount()-depthAttachmentCount;

		LongBuffer pImageViews = memAllocLong(renderPass.getAttachmentCount());
		pImageViews.put(0, attachments.get(Attachment.COLOR).getImageView().getHandle());
		pImageViews.put(1, attachments.get(Attachment.POSITION).getImageView().getHandle());
		pImageViews.put(2, attachments.get(Attachment.NORMAL).getImageView().getHandle());
		pImageViews.put(3, attachments.get(Attachment.SPECULAR_EMISSION_DIFFUSE_SSAO_BLOOM).getImageView().getHandle());
		pImageViews.put(4, attachments.get(Attachment.LIGHT_SCATTERING).getImageView().getHandle());
		pImageViews.put(5, attachments.get(Attachment.DEPTH).getImageView().getHandle());
		
		frameBuffer = new VkFrameBuffer(device, width, height, 1, pImageViews, renderPass.getHandle());
	}
 
Example 19
Source File: Water.java    From oreon-engine with GNU General Public License v3.0 4 votes vote down vote up
public ReflectionRefractionFbo(VkDevice device,
		VkPhysicalDeviceMemoryProperties memoryProperties) {
	
	width = BaseContext.getConfig().getFrameWidth()/2;
	height = BaseContext.getConfig().getFrameHeight()/2;
	
	VkImageBundle albedoBuffer = new FrameBufferColorAttachment(device, memoryProperties, width, height,
			VK_FORMAT_R8G8B8A8_UNORM, 1);
	VkImageBundle normalBuffer = new FrameBufferColorAttachment(device, memoryProperties, width, height, 
			VK_FORMAT_R16G16B16A16_UNORM, 1);
	VkImageBundle depthBuffer = new FrameBufferDepthAttachment(device, memoryProperties, width, height,
			VK_FORMAT_D16_UNORM, 1);
	
	attachments.put(Attachment.COLOR, albedoBuffer);
	attachments.put(Attachment.NORMAL, normalBuffer);
	attachments.put(Attachment.DEPTH, depthBuffer);
	
	renderPass = new RenderPass(device);
	renderPass.addColorAttachment(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
			VK_FORMAT_R8G8B8A8_UNORM, 1, VK_IMAGE_LAYOUT_UNDEFINED,
			VK_IMAGE_LAYOUT_GENERAL);
	renderPass.addColorAttachment(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
			VK_FORMAT_R16G16B16A16_UNORM, 1, VK_IMAGE_LAYOUT_UNDEFINED,
			VK_IMAGE_LAYOUT_GENERAL);
	renderPass.addDepthAttachment(2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
			VK_FORMAT_D16_UNORM, 1, VK_IMAGE_LAYOUT_UNDEFINED,
			VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
	
	renderPass.addSubpassDependency(VK_SUBPASS_EXTERNAL, 0,
			VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
    		VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
    		VK_ACCESS_MEMORY_READ_BIT,
    		VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
    		VK_DEPENDENCY_BY_REGION_BIT);
	renderPass.addSubpassDependency(0, VK_SUBPASS_EXTERNAL,
			VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
			VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
    		VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
    		VK_ACCESS_MEMORY_READ_BIT,
    		VK_DEPENDENCY_BY_REGION_BIT);
	
	renderPass.createSubpass();
	renderPass.createRenderPass();
	
	depthAttachmentCount = 1;
	colorAttachmentCount = renderPass.getAttachmentCount()-depthAttachmentCount;
	
	LongBuffer pImageViews = memAllocLong(renderPass.getAttachmentCount());
	pImageViews.put(0, attachments.get(Attachment.COLOR).getImageView().getHandle());
	pImageViews.put(1, attachments.get(Attachment.NORMAL).getImageView().getHandle());
	pImageViews.put(2, attachments.get(Attachment.DEPTH).getImageView().getHandle());
	
	frameBuffer = new VkFrameBuffer(device, width, height, 1,
			pImageViews, renderPass.getHandle());
}
 
Example 20
Source File: ArrayLong.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ByteBuffer getDataAsByteBuffer(ByteOrder order) {
  ByteBuffer bb = super.getDataAsByteBuffer((int) (8 * getSize()), order);
  LongBuffer ib = bb.asLongBuffer();
  ib.put((long[]) get1DJavaArray(getDataType())); // make sure its in canonical order
  return bb;
}