Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class BoolHashMap2d{
  2. private:
  3. unsigned int w, h;
  4. bool* map;
  5. unsigned int convert2dTo1dIndex(unsigned int x, unsigned int y){
  6. return ((y * w) + x);
  7. }
  8. public:
  9. void init(bool value) {
  10. for(unsigned int index; index < (w*h); index++){
  11. this->map[index] = value;
  12. }
  13. }
  14. BoolHashMap2d(unsigned int width, unsigned int height) {
  15. this->w = width;
  16. this->map = new bool[width * height];
  17. this->init(false);
  18. }
  19. ~BoolHashMap2d(){
  20. delete [this->w * this->h]map;
  21. }
  22. bool getBool(unsigned int x, unsigned int y){
  23. return this->map[this->convert2dTo1dIndex(x,y)];
  24. }
  25. void setBool(unsigned int x, unsigned int y, bool value){
  26. this->map[this->convert2dTo1dIndex(x,y)]=value;
  27. }
  28. unsigned int getWidth() const {
  29. return this->w;
  30. }
  31. unsigned int getHeight() const {
  32. return this->h;
  33. }
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement