1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:37:44 +00:00

AK: Add Span<T>::matching_prefix_length

This commit is contained in:
Tim Schumacher 2023-06-02 00:31:40 +02:00 committed by Linus Groh
parent 2109f61b0d
commit 3526d67694

View file

@ -227,6 +227,18 @@ public:
return TypedTransfer<T>::compare(data(), other.data(), other.size()); return TypedTransfer<T>::compare(data(), other.data(), other.size());
} }
[[nodiscard]] size_t constexpr matching_prefix_length(ReadonlySpan<T> other) const
{
auto maximum_length = min(size(), other.size());
for (size_t i = 0; i < maximum_length; i++) {
if (data()[i] != other.data()[i])
return i;
}
return maximum_length;
}
[[nodiscard]] ALWAYS_INLINE constexpr T const& at(size_t index) const [[nodiscard]] ALWAYS_INLINE constexpr T const& at(size_t index) const
{ {
VERIFY(index < this->m_size); VERIFY(index < this->m_size);