Guest User

vkumar

a guest
Feb 7th, 2010
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. struct qtree {
  2.     uint8_t height;
  3.     union {
  4.         #define ALIVE   node.alive
  5.         bool alive;
  6.         #define QUADS   node.quads  /* 0: tl    1: tr */
  7.         struct qtree** quads;           /* 2: bl    3: br */
  8.     } node;
  9. } __attribute__((__packed__));
  10.  
  11. static qtree* init_qtree(int height, bool init_quads = true) {
  12.     qtree* qt = new qtree;
  13.     qt->height = (uint8_t) height;
  14.  
  15.     if (init_quads) {
  16.         qt->QUADS = new qtree*[4];
  17.     } else {
  18.         qt->ALIVE = false;
  19.     }
  20. }
  21.  
  22. qtree* new_qt(int height) {
  23.     if (height == 0) {
  24.         return init_qtree(0, false);
  25.     } else {
  26.         qtree* qt = init_qtree(height);
  27.  
  28.         for (int i = 0; i < 4; ++i) {
  29.             qt->QUADS[i] = new_qt(height - 1);
  30.         }
  31.  
  32.         return qt;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment