Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstdint>
- using std::size_t;
- template <typename Block>
- class BitMap {
- static const size_t BitsPerBlock = sizeof(Block) * 8;
- public:
- BitMap(size_t height, size_t width)
- : m_width(width)
- , m_height(height)
- , m_blocks((width * height) / BitsPerBlock + 1, 0)
- {}
- bool get(size_t x, size_t y) const {
- const size_t index = x * m_width + y;
- const size_t nbit = index % BitsPerBlock;
- const size_t nblock = index / BitsPerBlock;
- return m_blocks[nblock] & (1 << nbit);
- }
- void set(size_t x, size_t y) {
- const size_t index = x * m_width + y;
- const size_t nbit = index % BitsPerBlock;
- const size_t nblock = index / BitsPerBlock;
- m_blocks[nblock] |= (1 << nbit);
- }
- size_t width() const {
- return m_width;
- }
- size_t height() const {
- return m_height;
- }
- private:
- size_t m_width;
- size_t m_height;
- std::vector<Block> m_blocks;
- };
- int main() {
- // your code goes here
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement