AK: Add Bitmap::set_range()
Add set_range() which sets a range of bits to requested value. Fix code style.
This commit is contained in:
parent
6e7713a5f4
commit
73901c9b2b
Notes:
sideshowbarker
2024-07-19 07:52:35 +09:00
Author: https://github.com/nimelehin 🔰 Commit: https://github.com/SerenityOS/serenity/commit/73901c9b2bd
1 changed files with 8 additions and 4 deletions
12
AK/Bitmap.h
12
AK/Bitmap.h
|
@ -94,6 +94,12 @@ public:
|
||||||
else
|
else
|
||||||
m_data[index / 8] &= static_cast<u8>(~(1u << (index % 8)));
|
m_data[index / 8] &= static_cast<u8>(~(1u << (index % 8)));
|
||||||
}
|
}
|
||||||
|
void set_range(size_t start, size_t len, bool value)
|
||||||
|
{
|
||||||
|
for (size_t index = start; index < start + len; ++index) {
|
||||||
|
set(index, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
u8* data() { return m_data; }
|
u8* data() { return m_data; }
|
||||||
const u8* data() const { return m_data; }
|
const u8* data() const { return m_data; }
|
||||||
|
@ -136,8 +142,7 @@ public:
|
||||||
while (i < m_size / 8 && m_data[i] == 0x00)
|
while (i < m_size / 8 && m_data[i] == 0x00)
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
size_t j = 0;
|
for (size_t j = i * 8; j < m_size; j++) {
|
||||||
for (j = i * 8; j < m_size; j++) {
|
|
||||||
if (get(j))
|
if (get(j))
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
@ -151,8 +156,7 @@ public:
|
||||||
while (i < m_size / 8 && m_data[i] == 0xff)
|
while (i < m_size / 8 && m_data[i] == 0xff)
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
size_t j = 0;
|
for (size_t j = i * 8; j < m_size; j++)
|
||||||
for (j = i * 8; j < m_size; j++)
|
|
||||||
if (!get(j))
|
if (!get(j))
|
||||||
return j;
|
return j;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue