mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:07:46 +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:
parent
68de9008e7
commit
edcfbdf4bd
2 changed files with 53 additions and 0 deletions
13
AK/Vector.h
13
AK/Vector.h
|
@ -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; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue