Untitled
unknown
plain_text
10 months ago
950 B
107
Indexable
#pragma once
#include<cstddef>
#include<cstdint>
#include <cmath>
#include <iostream>
typedef unsigned char uchar_t;
template<int bufferSize, size_t boolNum>
class BoolArray
{
private:
uchar_t m_buffer[bufferSize];
uint16_t sizeOfLastBuffer = 0;
void initializeBuffer()
{
for(uchar_t c : m_buffer)
c = 0;
}
public:
BoolArray(bool* boolArray)
{
initializeBuffer();
sizeOfLastBuffer = boolNum % 8;
// initialize all the bytes
for (size_t i = 0; i < boolNum; i++)
{
// calculate the desired buffer
int desiredBuffer = std::ceil(i / 8) - 1;
// Apply bit at desired location
m_buffer[desiredBuffer] |= boolArray[i] << i;
}
}
// debug functions
void print() {
for (uchar_t c : m_buffer) {
std::cout << (int)(c);
}
}
void printLastBufferSize () {
std::cout << sizeOfLastBuffer;
}
void printBoolNum() {
std::cout << boolNum;
}
};Editor is loading...
Leave a Comment