Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
random-bit-length.cc
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <time.h>
3 #include <stdio.h>
4 
5 int main(int argc, char** argv) {
6  int counts[64];
7  for (int i=0; i < 64; ++i) {
8  counts[i] = 0;
9  }
10 
11  srand(time(NULL));
12  for (int i = 0;i < 10; ++i) {
13  unsigned long rvalue = rand();
14  rvalue = (rvalue << 32) ^ rand();
15  rvalue = rvalue >> 32; //(rand() % 64);
16  rvalue = rand();
17  printf("Rvalue: %ld\n", rvalue);
18  printf("Sizeof: %lu\n", sizeof(rvalue));
19  for (unsigned long j = 63; j >= 0; --j) {
20  unsigned long mask = 1 << j;
21  printf("1 << %d: %lu\n", j, mask);
22  if ((rvalue & mask) != 0) {
23  counts[j]++;
24  break;
25  }
26  }
27  }
28 
29  for (int i=0; i< 64; ++i) {
30  printf("Bucket[%d]: %d\n", i, counts[i]);
31  }
32 }
int main(int argc, char **argv)