Fixed Java LookupByKey functionality for Java 1.6

Tested: on Linux.

Change-Id: Iea336f75a3b6e722743563813c3c9ed9db4d02fe
This commit is contained in:
Wouter van Oortmerssen
2016-08-26 13:57:40 -07:00
parent 49ee30a207
commit e1f8037cb5
4 changed files with 58 additions and 42 deletions

View File

@@ -140,21 +140,24 @@ public final class Monster extends Table {
protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(10, o1, _bb), __offset(10, o2, _bb), _bb); }
public static Monster lookupByKey(int vectorOffset, String key, ByteBuffer bb) {
byte[] byteKey = key.getBytes(StandardCharsets.UTF_8);
int vectorLocation = bb.array().length - vectorOffset.Value;
int span = bb.getInt(vectorLocation), middle, start = 0, comp, tableOffset;
byte[] byteKey = key.getBytes(Table.UTF8_CHARSET.get());
int vectorLocation = bb.array().length - vectorOffset;
int span = bb.getInt(vectorLocation);
int start = 0;
vectorLocation += 4;
while (span != 0) {
int middle = span / 2;
tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
comp = compareStrings(__offset(10, bb.array().length - tableOffset, bb), byteKey, bb);
if (comp > 0) span = middle;
else if (comp < 0) {
int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
int comp = compareStrings(__offset(10, bb.array().length - tableOffset, bb), byteKey, bb);
if (comp > 0) {
span = middle;
} else if (comp < 0) {
middle++;
start += middle;
span -= middle;
} else {
return new Monster().__init(tableOffset, bb);
}
else return new Monster().__init(tableOffset, bb);
}
return null;
}