mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 04:21:13 +00:00
Sorted Vector & binary search functionality.
Bug: 16659276 Tested: on Linux & Windows. Change-Id: Ie7a73810345fad4cf0a3ad03dfaa5464e3ed5ac8
This commit is contained in:
@@ -245,6 +245,24 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
|
||||
code += "_nested_root() { return flatbuffers::GetRoot<";
|
||||
code += nested_root->name + ">(" + field.name + "()->Data()); }\n";
|
||||
}
|
||||
// Generate a comparison function for this field if it is a key.
|
||||
if (field.key) {
|
||||
code += " bool KeyCompareLessThan(const " + struct_def.name;
|
||||
code += " *o) const { return ";
|
||||
if (field.value.type.base_type == BASE_TYPE_STRING) code += "*";
|
||||
code += field.name + "() < ";
|
||||
if (field.value.type.base_type == BASE_TYPE_STRING) code += "*";
|
||||
code += "o->" + field.name + "(); }\n";
|
||||
code += " int KeyCompareWithValue(";
|
||||
if (field.value.type.base_type == BASE_TYPE_STRING) {
|
||||
code += "const char *val) const { return strcmp(" + field.name;
|
||||
code += "()->c_str(), val); }\n";
|
||||
} else {
|
||||
code += GenTypeBasic(parser, field.value.type, false);
|
||||
code += " val) const { return " + field.name + "() < val ? -1 : ";
|
||||
code += field.name + "() > val; }\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Generate a verifier function that can check a buffer from an untrusted
|
||||
|
||||
Reference in New Issue
Block a user