protected VecBufferSequence(VecBufferSequence that, int beginIndex, int endIndex) { super(that, beginIndex, endIndex); this.vecCount = that.vecCount; this.buffer = that.buffer; }
protected VecBufferSequence(VecBufferSequence that, int[] indices, int offset, int length) { super(that, indices, offset, length); this.vecCount = that.vecCount; this.buffer = that.buffer; }
/** * Returns an empty VecBufferSequence. The returned VecBufferSequence has a size of zero and contains no * sub-buffers. * * @param coordsPerVec the number of coordinates per logical vector. * * @return the empty VecBufferSequence. */ public static VecBufferSequence emptyVecBufferSequence(int coordsPerVec) { if (coordsPerVec < 1) { String message = Logging.getMessage("generic.ArgumentOutOfRange", coordsPerVec); Logging.logger().severe(message); throw new ArgumentException(message); } return(new VecBufferSequence(VecBuffer.emptyVecBuffer(coordsPerVec))); }
/** * Constructs a PackedCompoundVecBuffer with the specified backing VecBuffer and the specified initial capacity. * * @param buffer the backing VecBuffer. * @param capacity the PackedCompoundVecBuffer's initial capacity, in number of sub-buffers. * * @throws ArgumentException if the buffer is null, or if the capacity is less than 1. */ public VecBufferSequence(VecBuffer buffer, int capacity) { super(capacity); if (buffer == null) { String message = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } this.buffer = buffer; }
/** * Sets a subsequence of this buffer with the contents of the specified buffer. The subsequence to set starts with * the vector at the specified position, and has size equal to the specified size. The specified buffer must have * the same logical vector size as this buffer (coordsPerVec must be equivalent). * * @param position the starting vector position to set. * @param buffer the input buffer. * @param offset the vector position to start copying values from the specified buffer. * @param size the number of vectors to read copy form the specified buffer. * * @throws ArgumentException if the position is out of range, if the buffer is null or incompatible, if this * buffer has insufficient length to store the sub-buffer at the specified * position, or if the specified offset and size define a range outside of the * specified buffer. */ public void putSubBuffer(int position, VecBuffer buffer, int offset, int size) { if (position < 0 || position >= this.getSize()) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "position < 0 or position >= size"); Logging.logger().severe(message); throw new ArgumentException(message); } if (buffer == null) { String message = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } // Not enough room in buffer. if (buffer.getSize() < (offset + size)) { String message = Logging.getMessage("generic.BufferOverflow", buffer.getSize(), size); Logging.logger().severe(message); throw new ArgumentException(message); } // Buffer is incompatible. if (this.coordsPerVec != buffer.coordsPerVec) { String message = Logging.getMessage("generic.BufferIncompatible", buffer); Logging.logger().severe(message); throw new ArgumentException(message); } // Buffer is too large. int sizeNeeded = position + size; if (this.getSize() < sizeNeeded) { String message = Logging.getMessage("generic.BufferOverflow", this.getSize(), sizeNeeded); Logging.logger().severe(message); throw new ArgumentException(message); } int index = this.indexFromVectorPosition(position); int off = this.indexFromVectorPosition(offset); int length = this.indexFromVectorPosition(size); this.buffer.putSubBuffer(index, buffer.getBufferWrapper(), off, length); }
protected void expandBufferCapacity(int minCapacity) { int newCapacity = 2 * this.buffer.getSize(); // If the new capacity overflows the range of 32-bit integers, then use the largest 32-bit integer. if (newCapacity < 0) { newCapacity = Integer.MAX_VALUE; } // If the new capacity is still not large enough for the minimum capacity specified, then just use the minimum // capacity specified. else if (newCapacity < minCapacity) { newCapacity = minCapacity; } this.buffer = this.buffer.copyOf(newCapacity); }
/** * Sets a subsequence of this buffer with the contents of the specified buffer. The subsequence to set starts with * the vector at the specified position, and has size equal to the specified buffer's size. The specified buffer * must have the same logical vector size as this buffer (coordsPerVec must be equivalent). * * @param position the starting vector position to set. * @param buffer the input buffer. * * @throws ArgumentException if the position is out of range, if the buffer is null or incompatible, or if * this buffer has insufficient length to store the sub-buffer at the specified * position. */ public void putSubBuffer(int position, VecBuffer buffer) { if (position < 0 || position >= this.getSize()) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "position < 0 or position >= size"); Logging.logger().severe(message); throw new ArgumentException(message); } if (buffer == null) { String message = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } this.putSubBuffer(position, buffer, 0, buffer.getSize()); }
/** * Returns the sub-buffer at the specified index as a {@link SharpEarth.util.VecBuffer}. * * @param index the index of the VecBuffer to return. * * @return the VecBuffer at the specified index. * * @throws ArgumentException if the index is out of range. */ public VecBuffer subBuffer(int index) { if (index < 0 || index >= this.count) { String message = Logging.getMessage("generic.indexOutOfRange", index); Logging.logger().severe(message); throw new ArgumentException(message); } int off = this.offsets.get(index); int len = this.lengths.get(index); if (len > 0) { return(this.createSubBuffer(off, len)); } else { return(VecBuffer.emptyVecBuffer(this.getCoordsPerVec())); } }
/** * Appends the contents of the specified sub-buffer to the end of this PackedCompoundVecBuffer, incrementing the * number of sub-buffers by one. The backing buffer grows to accomodate the sub-buffer if it does not already have * enough capacity to hold it. * * @param buffer the sub-buffer to append. * * @return the sub-buffer's index. * * @throws ArgumentException if the subBuffer is null. */ public int append(VecBuffer buffer) { if (buffer == null) { String message = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } int minVecCount = buffer.getSize() + this.vecCount; if (minVecCount > this.buffer.getSize()) { this.expandBufferCapacity(minVecCount); } int newBufferPos = this.vecCount; this.buffer.putSubBuffer(newBufferPos, buffer); this.vecCount += buffer.getSize(); return(this.addSubBuffer(newBufferPos, buffer.getSize())); }
/** * Constructs a PackedCompoundVecBuffer with the specified backing VecBuffer and the default initial capacity. * * @param buffer the backing VecBuffer. * * @throws ArgumentException if the buffer is null. */ public VecBufferSequence(VecBuffer buffer) { this(buffer, DEFAULT_INITIAL_CAPACITY); }