Skip to content

Instantly share code, notes, and snippets.

@luyao795
Created August 24, 2017 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luyao795/746bb9d4efdc4809af93f7eb509eb0c9 to your computer and use it in GitHub Desktop.
Save luyao795/746bb9d4efdc4809af93f7eb509eb0c9 to your computer and use it in GitHub Desktop.
Header file for Bit Array
#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