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

AK: Added contains_in_range to Vector

Vector::contains_in_range() allows the search of an element in a given
range on a vector object.
Also added testcases for the new Vector method.
This commit is contained in:
r-paiva 2021-05-10 21:49:54 +01:00 committed by Andreas Kling
parent 68de9008e7
commit edcfbdf4bd
2 changed files with 53 additions and 0 deletions

View file

@ -150,6 +150,19 @@ public:
return false;
}
bool contains_in_range(const T& value, const size_t start, const size_t end) const
{
VERIFY(start <= end);
VERIFY(end < size());
for (size_t i = start; i <= end; ++i) {
if (Traits<T>::equals(at(i), value))
return true;
}
return false;
}
// NOTE: Vector::is_null() exists for the benefit of String::copy().
bool is_null() const { return false; }
bool is_empty() const { return size() == 0; }
ALWAYS_INLINE size_t size() const { return m_size; }
size_t capacity() const { return m_capacity; }