Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BoolHashMap2d{
- private:
- unsigned int w, h;
- bool* map;
- unsigned int convert2dTo1dIndex(unsigned int x, unsigned int y){
- return ((y * w) + x);
- }
- public:
- void init(bool value) {
- for(unsigned int index; index < (w*h); index++){
- this->map[index] = value;
- }
- }
- BoolHashMap2d(unsigned int width, unsigned int height) {
- this->w = width;
- this->map = new bool[width * height];
- this->init(false);
- }
- ~BoolHashMap2d(){
- delete [this->w * this->h]map;
- }
- bool getBool(unsigned int x, unsigned int y){
- return this->map[this->convert2dTo1dIndex(x,y)];
- }
- void setBool(unsigned int x, unsigned int y, bool value){
- this->map[this->convert2dTo1dIndex(x,y)]=value;
- }
- unsigned int getWidth() const {
- return this->w;
- }
- unsigned int getHeight() const {
- return this->h;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement