Ejemplo n.º 1
0
int main(int argc, char* argv[])
{
  size_t NumRows = pow(2, MyRow::NumCol);

  if (argc > 1) {
    NumRows = atoi(argv[1]);
  }

  std::mt19937 seedGen(getpid());
  std::uniform_int_distribution<uint32_t> numGen(0, MaxRangeForEachCol);

  typedef std::vector<MyRow> Table;

  Table table;

  // Enumerate all the combinations of possible columns
  for (uint32_t idx = 0; idx < NumRows; idx ++)
  {
    std::vector<uint32_t> arr;
    //std::generate_n(std::back_inserter(arr), MyRow::NumCol, [&] () -> uint32_t {return numGen(seedGen);});
    //
    //std::cout <<  "idx=" << idx << "{";
    for (uint32_t col = 0; col < MyRow::NumCol; col ++)
    {
      // if the bit-rep of i-th row has j-th bit set
      // set the j-th col for i-th row 
      auto bit = (((0x1 << col) & idx) >> col);
      //std::cout << bit << ",";
      arr.push_back(bit);
    }
    //std::cout << "}" << std::endl;

    MyRow a(arr);
    table.push_back(a);
  }

  // Sort table based on Morton code
  std::sort(table.begin(), table.end());

  // Print the rows sorted by Morton code
  for (auto& row : table) {
    std::cout << row << std::endl;
  }
}
Ejemplo n.º 2
0
void populate(std::vector<int>& vec) {
    std::minstd_rand numGen(std::chrono::system_clock::now().time_since_epoch().count());
    for (auto&& entry : vec) {
        entry = numGen() % 100;
    }
}