public IndexShortBuffer(ShortBuffer buffer) { buf = buffer; buf.rewind(); }
/** * Create a copy of the content of this container as a short array. This creates a copy. * * @return copy of the content as a short array */ public short[] toShortArray() { short[] answer = new short[cardinality]; content.rewind(); content.get(answer); return answer; }
/** * Create a copy of the content of this container as a short array. This creates a copy. * * @return copy of the content as a short array */ public short[] toShortArray() { short[] answer = new short[2 * nbrruns]; valueslength.rewind(); valueslength.get(answer); return answer; }
private MappeableArrayContainer(int newCard, ShortBuffer newContent) { this.cardinality = newCard; ShortBuffer tmp = newContent.duplicate();// for thread-safety this.content = ShortBuffer.allocate(Math.max(newCard, tmp.limit())); tmp.rewind(); this.content.put(tmp); }
private MappeableRunContainer(int nbrruns, final ShortBuffer valueslength) { this.nbrruns = nbrruns; ShortBuffer tmp = valueslength.duplicate();// for thread safety this.valueslength = ShortBuffer.allocate(Math.max(2 * nbrruns, tmp.limit())); tmp.rewind(); this.valueslength.put(tmp); // may copy more than it needs to?? }
/** * Create a new ShortBuffer of an appropriate size to hold the specified * number of shorts only if the given buffer if not already the right size. * * @param buf * the buffer to first check and rewind * @param size * number of shorts that need to be held by the newly created * buffer * @return the requested new ShortBuffer */ public static ShortBuffer createShortBuffer(ShortBuffer buf, int size) { if (buf != null && buf.limit() == size) { buf.rewind(); return buf; } buf = createShortBuffer(size); return buf; }
protected ShortBuffer readShortBuffer(byte[] content) throws IOException { int length = readInt(content); if (length == BinaryOutputCapsule.NULL_OBJECT) return null; if (BinaryImporter.canUseFastBuffers()){ ByteBuffer value = BufferUtils.createByteBuffer(length * 2); value.put(content, index, length * 2).rewind(); index += length * 2; return value.asShortBuffer(); }else{ ShortBuffer value = BufferUtils.createShortBuffer(length); for (int x = 0; x < length; x++) { value.put(readShortForBuffer(content)); } value.rewind(); return value; } }
protected void ensureCapacity(int minNbRuns) { final int minCapacity = 2 * minNbRuns; if (valueslength.capacity() < minCapacity) { 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; } final ShortBuffer nv = ShortBuffer.allocate(newCapacity); valueslength.rewind(); nv.put(valueslength); valueslength = nv; } }
private void increaseCapacity(boolean allowIllegalSize) { int len = this.content.limit(); int newCapacity = (len == 0) ? DEFAULT_INIT_SIZE : len < 64 ? len * 2 : this.content.limit() < 1067 ? len * 3 / 2 : len * 5 / 4; // do not allocate more than we will ever need if (newCapacity > MappeableArrayContainer.DEFAULT_MAX_SIZE && !allowIllegalSize) { newCapacity = MappeableArrayContainer.DEFAULT_MAX_SIZE; } // if we are within 1/16th of the max., go to max right away to avoid further reallocations if (newCapacity > MappeableArrayContainer.DEFAULT_MAX_SIZE - MappeableArrayContainer.DEFAULT_MAX_SIZE / 16 && !allowIllegalSize) { newCapacity = MappeableArrayContainer.DEFAULT_MAX_SIZE; } final ShortBuffer newContent = ShortBuffer.allocate(newCapacity); this.content.rewind(); newContent.put(this.content); this.content = newContent; }
StringBuilder buf = new StringBuilder(); int pos = value.position(); value.rewind(); int ctr = 0; while (value.hasRemaining()) {
/** * Creates a new ShortBuffer with the same contents as the given * ShortBuffer. The new ShortBuffer is separate from the old one and changes * are not reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). * * @param buf * the ShortBuffer to copy * @return the copy */ public static ShortBuffer clone(ShortBuffer buf) { if (buf == null) { return null; } buf.rewind(); ShortBuffer copy; if (isDirect(buf)) { copy = createShortBuffer(buf.limit()); } else { copy = ShortBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
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; }
content.rewind(); co.put(content); content = co;
jointIndex.rewind(); c.setMaxNumWeights(1); FloatBuffer jointWeight = (FloatBuffer) VertexBuffer.createBuffer(VertexBuffer.Format.Float, 4, c.getVertexCount());
jointIndex.rewind(); c.setMaxNumWeights(1); FloatBuffer jointWeight = (FloatBuffer) VertexBuffer.createBuffer(VertexBuffer.Format.Float, 4, c.getVertexCount());
/** * Create a copy of the content of this container as a short array. This creates a copy. * * @return copy of the content as a short array */ public short[] toShortArray() { short[] answer = new short[cardinality]; content.rewind(); content.get(answer); return answer; }