Created
August 24, 2017 07:03
-
-
Save luyao795/746bb9d4efdc4809af93f7eb509eb0c9 to your computer and use it in GitHub Desktop.
Header file for Bit Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef BITARRAY_H | |
#define BITARRAY_H | |
#include <stdint.h> | |
#include "BlockAllocator.h" | |
namespace Engine | |
{ | |
#ifdef _WIN64 | |
#define u_integer uint64_t | |
#define integer int64_t | |
#define MAX_DT UINT64_MAX | |
#define MAX_BYTE UINT8_MAX | |
#define ScanBit(index, mask) _BitScanForward64(index, mask) | |
#else | |
#define u_integer uint32_t | |
#define integer int32_t | |
#define MAX_DT UINT32_MAX | |
#define MAX_BYTE UINT8_MAX | |
#define ScanBit(index, mask) _BitScanForward(index, mask) | |
#endif // _WIN64 | |
class BitArray | |
{ | |
public: | |
BitArray(size_t numBits, bool startClear, BlockAllocator* allocator); | |
void create(size_t numBits, bool startClear, BlockAllocator* allocator); | |
void clearAll(); | |
void setAll(); | |
void destroy(); | |
bool areAllClear() const; | |
bool areAllSet() const; | |
bool isBitSet(size_t bitIndex) const; | |
bool isBitClear(size_t bitIndex) const; | |
void setBit(size_t bitIndex); | |
void clearBit(size_t bitIndex); | |
bool getFirstClearBit(size_t &outBitIndex) const; | |
bool getFirstSetBit(size_t &outBitIndex) const; | |
u_integer* getBitArray() const; | |
u_integer operator[](size_t bitIndex) const; | |
private: | |
~BitArray(); | |
static BlockAllocator* inst; | |
u_integer shiftOne = 1; | |
u_integer shiftZero = 0; | |
size_t wholeBytes; | |
size_t extraBits; | |
u_integer* bits; | |
size_t arraySize; | |
size_t numBit; | |
const size_t byteSize = 8; | |
}; | |
} | |
#endif // !BITARRAY_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment