[common] add BinarySearch module and Stringfy (#7294)

This commit adds set of generic binary search related functions in
OpenThread core under `BinarySearch` module. The binary search module
replaces and enhances the existing `Lookup` table module (which was
limited to search based on strings and mainly used by CLI to map from
command string to a handler function).

This commit also adds a new class `Stringfy` in `string.hpp` to help
convert from a set of `uint16_t` values (e.g., a non-sequential
`enum`) to strings using binary search in a table. The new methods are
used for converting `Coap::Code` and `IpProto` enumerations to
corresponding strings.
This commit is contained in:
Abtin Keshavarzian
2022-01-10 13:19:34 -08:00
committed by GitHub
parent 91d444c2c5
commit a4cba16c39
39 changed files with 409 additions and 517 deletions
+1 -1
View File
@@ -129,7 +129,7 @@ otError Dataset::Process(Arg aArgs[])
ExitNow(error = Print(sDataset));
}
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
command = BinarySearch::Find(aArgs[0].GetCString(), sCommands);
VerifyOrExit(command != nullptr);
error = (this->*command->mHandler)(aArgs + 1);