/** * Returns this list's capacity. * * @return the capacity of the list. */ public int capacity() { return listBuffer.getInt(capacityOffset()); }
public CompactList(final UnsafeBuffer listBuffer) { this.listBuffer = listBuffer; final int elementMaxLength = listBuffer.getInt(elementMaxLengthOffset()); framedElementLength = framedLength(elementMaxLength); iterator = new CompactListIterator(this); this.allocatedBuffer = null; }
protected void setValue(DirectBuffer buffer, int offset, int length, int idx) { final int elementOffset = elementOffset(framedElementLength, idx); setValue(buffer, offset, length, idx, elementOffset); }
public CompactList(int elementMaxLength, int capacity, BufferAllocator bufferAllocator) { this( bufferAllocator.allocate(requiredBufferCapacity(framedLength(elementMaxLength), capacity)), elementMaxLength, capacity); }
public CompactList(AllocatedBuffer allocatedBuffer, int elementMaxLength, int capacity) { this.allocatedBuffer = allocatedBuffer; framedElementLength = framedLength(elementMaxLength); final int requiredBufferCapacity = requiredBufferCapacity(framedElementLength, capacity); final int bufferCapacity = allocatedBuffer.capacity(); if (bufferCapacity < requiredBufferCapacity) { final String errorMessage = String.format( "Not enough capacity in provided buffer. Has %d, required %d", bufferCapacity, requiredBufferCapacity); throw new IllegalArgumentException(errorMessage); } listBuffer = new UnsafeBuffer(0, 0); listBuffer.wrap(allocatedBuffer.getRawBuffer(), 0, requiredBufferCapacity); // write header listBuffer.putInt(sizeOffset(), 0); listBuffer.putInt(elementMaxLengthOffset(), elementMaxLength); listBuffer.putInt(capacityOffset(), capacity); iterator = new CompactListIterator(this); }
/** * Attach a view of the element to a {@link MutableDirectBuffer} for providing direct access. * * @param idx the element to attach. * @param dstBuffer to which the view of the element is attached. * @return the length of the attached element. */ public int wrap(int idx, MutableDirectBuffer dstBuffer) { final int size = size(); boundsCheckIncludingSize(idx, size); final int elementOffset = elementOffset(framedElementLength, idx); final int length = listBuffer.getInt(elementLengthOffset(elementOffset)); dstBuffer.wrap(listBuffer, elementDataOffset(elementOffset), length); return length; }
protected void setValue(DirectBuffer buffer, int offset, int length, int idx, int elementOffset) { setMemory(elementOffset, framedElementLength, (byte) 0); listBuffer.putInt(elementLengthOffset(elementOffset), length); listBuffer.putBytes(elementDataOffset(elementOffset), buffer, offset, length); }
/** * Returns the number of contained elements by the list. * * @return the number of contained elements. */ public int size() { return listBuffer.getInt(sizeOffset()); }
/** * Returns the maximal element data length. * * @return the maximal element data length. */ public int maxElementDataLength() { return listBuffer.getInt(elementMaxLengthOffset()); }
public CompactList(AllocatedBuffer allocatedBuffer, int elementMaxLength, int capacity) { this.allocatedBuffer = allocatedBuffer; framedElementLength = framedLength(elementMaxLength); final int requiredBufferCapacity = requiredBufferCapacity(framedElementLength, capacity); final int bufferCapacity = allocatedBuffer.capacity(); if (bufferCapacity < requiredBufferCapacity) { final String errorMessage = String.format( "Not enough capacity in provided buffer. Has %d, required %d", bufferCapacity, requiredBufferCapacity); throw new IllegalArgumentException(errorMessage); } listBuffer = new UnsafeBuffer(0, 0); listBuffer.wrap(allocatedBuffer.getRawBuffer(), 0, requiredBufferCapacity); // write header listBuffer.putInt(sizeOffset(), 0); listBuffer.putInt(elementMaxLengthOffset(), elementMaxLength); listBuffer.putInt(capacityOffset(), capacity); iterator = new CompactListIterator(this); }
/** * Get the element from the list into a supplied {@link MutableDirectBuffer}. * * @param idx the element to supply. * @param dstBuffer into which the element will be copied. * @param offset of the supplied buffer to use. * @return the length of the supplied element. */ public int get(int idx, MutableDirectBuffer dstBuffer, int offset) { final int size = size(); boundsCheckIncludingSize(idx, size); final int elementOffset = elementOffset(framedElementLength, idx); final int length = listBuffer.getInt(elementLengthOffset(elementOffset)); dstBuffer.putBytes(offset, listBuffer, elementDataOffset(elementOffset), length); return length; }
protected void setValue(DirectBuffer buffer, int offset, int length, int idx, int elementOffset) { setMemory(elementOffset, framedElementLength, (byte) 0); listBuffer.putInt(elementLengthOffset(elementOffset), length); listBuffer.putBytes(elementDataOffset(elementOffset), buffer, offset, length); }
public CompactList(int elementMaxLength, int capacity, BufferAllocator bufferAllocator) { this( bufferAllocator.allocate(requiredBufferCapacity(framedLength(elementMaxLength), capacity)), elementMaxLength, capacity); }
/** * Returns the number of contained elements by the list. * * @return the number of contained elements. */ public int size() { return listBuffer.getInt(sizeOffset()); }
/** * Returns the maximal element data length. * * @return the maximal element data length. */ public int maxElementDataLength() { return listBuffer.getInt(elementMaxLengthOffset()); }
/** * Get the element from the list into a supplied {@link MutableDirectBuffer}. * * @param idx the element to supply. * @param dstBuffer into which the element will be copied. * @param offset of the supplied buffer to use. * @return the length of the supplied element. */ public int get(int idx, MutableDirectBuffer dstBuffer, int offset) { final int size = size(); boundsCheckIncludingSize(idx, size); final int elementOffset = elementOffset(framedElementLength, idx); final int length = listBuffer.getInt(elementLengthOffset(elementOffset)); dstBuffer.putBytes(offset, listBuffer, elementDataOffset(elementOffset), length); return length; }
protected void setValue(DirectBuffer buffer, int offset, int length, int idx) { final int elementOffset = elementOffset(framedElementLength, idx); setValue(buffer, offset, length, idx, elementOffset); }
public CompactList(final UnsafeBuffer listBuffer) { this.listBuffer = listBuffer; final int elementMaxLength = listBuffer.getInt(elementMaxLengthOffset()); framedElementLength = framedLength(elementMaxLength); iterator = new CompactListIterator(this); this.allocatedBuffer = null; }
protected void setSize(final int size) { listBuffer.putInt(sizeOffset(), size); }
/** * Returns this list's capacity. * * @return the capacity of the list. */ public int capacity() { return listBuffer.getInt(capacityOffset()); }