All checks were successful
continuous-integration/drone/push Build is passing
This method looks for the first bit with a value, optionally from a starting index, and returns its index. This should be (haven't benchmarked) way faster than the manual way, AKA what MM and KernelVM were doing. This is due to this method using bit and byte manipulation tricks instead of just calling get() until getting the desired result :)
52 lines
1.0 KiB
C++
52 lines
1.0 KiB
C++
#pragma once
|
|
#include <luna/Option.h>
|
|
#include <luna/Types.h>
|
|
|
|
class Bitmap
|
|
{
|
|
public:
|
|
Bitmap();
|
|
Bitmap(void* location, usize size_in_bytes);
|
|
|
|
void initialize(void* location, usize size_in_bytes);
|
|
void* move(void* new_location, usize new_location_size_in_bytes);
|
|
|
|
void set(usize index, bool value);
|
|
bool get(usize index) const;
|
|
|
|
// size() returns size in bits! If you want the size in bytes, call size_in_bytes().
|
|
usize size() const
|
|
{
|
|
return m_size_in_bytes * 8;
|
|
}
|
|
|
|
usize size_in_bytes() const
|
|
{
|
|
return m_size_in_bytes;
|
|
}
|
|
|
|
void* location() const
|
|
{
|
|
return (void*)m_location;
|
|
}
|
|
|
|
bool initialized() const
|
|
{
|
|
return m_location;
|
|
}
|
|
|
|
Option<usize> find(bool value, usize begin = 0) const;
|
|
|
|
void clear(bool value);
|
|
void clear_region(usize start, usize bits, bool value);
|
|
|
|
private:
|
|
u8 value_byte(bool b) const
|
|
{
|
|
return b ? 0xff : 0;
|
|
}
|
|
|
|
u8* m_location = nullptr;
|
|
usize m_size_in_bytes = 0;
|
|
};
|