class BinarySearch

Defined at line 43 of file ../../third_party/openthread/src/core/common/binary_search.hpp

Public Methods

template <typename Key, typename Entry, uint16_t kLength>
const Entry * Find (const Key & aKey, const Entry (&)[kLength] aTable)

Performs binary search in a given sorted table array to find an entry matching a given key.

The `Entry` class MUST provide the following method to compare the entry against a given key.

int Entry::Compare(const Key

&aKey

) const;

The return value indicates the comparison result between

and the entry (similar to `strcmp()`), i.e.,

zero means perfect match, positive (> 0) indicates

is larger than entry, and negative indicates

is smaller than entry.

Parameters

aKey [in] The key to search for within the table.
aTable [in] A reference to an array of `kLength` entries of type `Entry`

Template Parameters

Key The type of `Key` to search for.
Entry The table `Entry` type.
kLength The array length (number of entries in the array).

Defined at line 72 of file ../../third_party/openthread/src/core/common/binary_search.hpp

template <typename Entry, uint16_t kLength>
bool IsSorted (const Entry (&)[kLength] aTable)

Indicates whether a given table array is sorted based or not.

Is `constexpr` and is intended for use in `static_assert`s to verify that a `constexpr` lookup table

array is sorted. It is not recommended for use in other situations.

The `Entry` class MUST provide the following `static` and `constexpr` method to compare two entries.

constexpr static bool Entry::AreInOrder(const Entry

&aFirst

, const Entry

&aSecond

);

The return value MUST be TRUE if the entries are in order, i.e. `aFirst

<

aSecond` and FALSE otherwise.

Parameters

aTable [in] A reference to an array of `kLength` entries on type `Entry`

Template Parameters

Entry The table entry type.
kLength The array length (number of entries in the array).

Defined at line 98 of file ../../third_party/openthread/src/core/common/binary_search.hpp