mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[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:
committed by
GitHub
parent
91d444c2c5
commit
a4cba16c39
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user