Commit Graph

3 Commits

Author SHA1 Message Date
Abtin Keshavarzian ef9c8de3cd [bit-utils] un-inline CountBitsInMask helper method (#13286)
This commit replaces the template function `CountBitsInMask<UintType>`
with a non-template function `CountBitsInMask(uint32_t)` in `bit_utils.hpp`
and moves its implementation to `bit_utils.cpp`.

Un-inlining this helper function avoids template instantiation overhead
and reduces binary size across translation units. Small integer arguments
(`uint8_t`, `uint16_t`) automatically promote to `uint32_t`, preserving
existing functionality.
2026-07-03 21:00:06 -07:00
Abtin Keshavarzian 1d4900609d [bit-utils] add DetermineMinBitSizeFor helper method (#13287)
This commit adds `DetermineMinBitSizeFor(uint32_t)` to calculate and
return the minimum number of bits required to represent a given
32-bit unsigned integer value.

It also adds unit tests for this in `test_bit_utils.cpp`.
2026-07-03 13:13:42 -07:00
Abtin Keshavarzian d952ad9085 [bit-utils] add CountMatchingBits utility function (#11893)
This change introduces a new utility function `CountMatchingBits()` to
calculate the number of matching leading bits between two byte
arrays.

This new fn replaces the now-removed `Ip6::Prefix::MatchLength()`.
The previous implementation was specific to the `Ip6::Prefix`
class. The new generic function is placed in `common/bit_utils` and
is used to update `Ip6::Prefix`, `Ip6::Address`, `Ip4::Cidr`, and
`PrefixTlv`.

A new unit test `test_bit_utils` is added with comprehensive tests for
the new function. The existing tests for `CountBitsInMask` are also
moved into this new test file.
2025-09-03 22:29:15 -07:00