mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-22 18:48:52 +00:00
Improve LookupByKey , update docs
This commit is contained in:
@@ -130,24 +130,26 @@ public sealed class Monster : Table {
|
||||
}
|
||||
public static void FinishMonsterBuffer(FlatBufferBuilder builder, Offset<Monster> offset) { builder.Finish(offset.Value, "MONS"); }
|
||||
|
||||
public static VectorOffset CreateMySortedTableVector(FlatBufferBuilder builder, Offset<Monster>[] offsets) {
|
||||
public static VectorOffset CreateMySortedVectorOfTables(FlatBufferBuilder builder, Offset<Monster>[] offsets) {
|
||||
Array.Sort(offsets, (Offset<Monster> o1, Offset<Monster> o2) => CompareStrings(__offset(10, o1.Value, builder.DataBuffer), __offset(10, o2.Value, builder.DataBuffer), builder.DataBuffer));
|
||||
return builder.CreateVectorOfTables(offsets);
|
||||
}
|
||||
|
||||
public static Monster LookupByKey(Monster[] tables, string key) {
|
||||
int span = tables.Length, start = 0;
|
||||
public static Monster LookupByKey(VectorOffset vectorOffset, string key, ByteBuffer bb) {
|
||||
int vectorLocation = bb.Length - vectorOffset.Value;
|
||||
int span = bb.GetInt(vectorLocation), middle, start = 0, comp, tableOffset;
|
||||
vectorLocation += 4;
|
||||
while (span != 0) {
|
||||
int middle = span / 2;
|
||||
Monster table = tables[start + middle];
|
||||
int comp = table.Name.CompareTo(key);
|
||||
tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
|
||||
comp = CompareStrings(__offset(10, bb.Length - tableOffset, bb), key, bb);
|
||||
if (comp > 0) span = middle;
|
||||
else if (comp < 0) {
|
||||
middle++;
|
||||
start += middle;
|
||||
span -= middle;
|
||||
}
|
||||
else return table;
|
||||
else return new Monster().__init(tableOffset, bb);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user