allow the List(Primitive) -> List(Struct) upgrade path, for now

This commit is contained in:
David Renshaw 2014-10-11 12:46:47 -04:00
parent c941f5960f
commit be23d22a89
2 changed files with 26 additions and 24 deletions

View file

@ -51,65 +51,66 @@ public class ListBuilder {
}
protected boolean _getBooleanElement(int index) {
byte b = this.segment.buffer.get(this.ptr + index / 8);
return (b & (1 << (index % 8))) != 0;
long bindex = index * this.step;
byte b = this.segment.buffer.get(this.ptr + (int)(bindex / Constants.BITS_PER_BYTE));
return (b & (1 << (bindex % 8))) != 0;
}
protected byte _getByteElement(int index) {
return this.segment.buffer.get(this.ptr + index);
return this.segment.buffer.get(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected short _getShortElement(int index) {
return this.segment.buffer.getShort(this.ptr + index * 2);
return this.segment.buffer.getShort(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected int _getIntElement(int index) {
return this.segment.buffer.getInt(this.ptr + index * 4);
return this.segment.buffer.getInt(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected long _getLongElement(int index) {
return this.segment.buffer.getLong(this.ptr + index * 8);
return this.segment.buffer.getLong(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected float _getFloatElement(int index) {
return this.segment.buffer.getFloat(this.ptr + index * 4);
return this.segment.buffer.getFloat(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected double _getDoubleElement(int index) {
return this.segment.buffer.getDouble(this.ptr + index * 8);
return this.segment.buffer.getDouble(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected void _setBooleanElement(int index, boolean value) {
int bitOffset = index;
long bitOffset = index * this.step;
byte bitnum = (byte)(bitOffset % 8);
int position = this.ptr + (bitOffset / 8);
int position = (int)(this.ptr + (bitOffset / 8));
byte oldValue = this.segment.buffer.get(position);
this.segment.buffer.put(position,
(byte)((oldValue & (~(1 << bitnum))) | (( value ? 1 : 0) << bitnum)));
}
protected void _setByteElement(int index, byte value) {
this.segment.buffer.put(this.ptr + index, value);
this.segment.buffer.put(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value);
}
protected void _setShortElement(int index, short value) {
this.segment.buffer.putShort(this.ptr + index * 2, value);
this.segment.buffer.putShort(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value);
}
protected void _setIntElement(int index, int value) {
this.segment.buffer.putInt(this.ptr + index * 4, value);
this.segment.buffer.putInt(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value);
}
protected void _setLongElement(int index, long value) {
this.segment.buffer.putLong(this.ptr + index * 8, value);
this.segment.buffer.putLong(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value);
}
protected void _setFloatElement(int index, float value) {
this.segment.buffer.putFloat(this.ptr + index * 4, value);
this.segment.buffer.putFloat(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value);
}
protected void _setDoubleElement(int index, double value) {
this.segment.buffer.putDouble(this.ptr + index * 8, value);
this.segment.buffer.putDouble(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value);
}
protected final <T> T _getStructElement(StructBuilder.Factory<T> factory, int index) {

View file

@ -67,32 +67,33 @@ public class ListReader {
}
protected boolean _getBooleanElement(int index) {
byte b = this.segment.buffer.get(this.ptr + index / 8);
return (b & (1 << (index % 8))) != 0;
long bindex = index * this.step;
byte b = this.segment.buffer.get(this.ptr + (int)(bindex / Constants.BITS_PER_BYTE));
return (b & (1 << (bindex % 8))) != 0;
}
protected byte _getByteElement(int index) {
return this.segment.buffer.get(this.ptr + index);
return this.segment.buffer.get(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected short _getShortElement(int index) {
return this.segment.buffer.getShort(this.ptr + index * 2);
return this.segment.buffer.getShort(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected int _getIntElement(int index) {
return this.segment.buffer.getInt(this.ptr + index * 4);
return this.segment.buffer.getInt(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected long _getLongElement(int index) {
return this.segment.buffer.getLong(this.ptr + index * 8);
return this.segment.buffer.getLong(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected float _getFloatElement(int index) {
return this.segment.buffer.getFloat(this.ptr + index * 4);
return this.segment.buffer.getFloat(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected double _getDoubleElement(int index) {
return this.segment.buffer.getDouble(this.ptr + index * 8);
return this.segment.buffer.getDouble(this.ptr + index * this.step / Constants.BITS_PER_BYTE);
}
protected <T> T _getStructElement(StructReader.Factory<T> factory, int index) {