Table tile(const Cordinate width, const Cordinate height) { Table table(height, TRow(width)); // Start with simple vertical tiling TraceID alpha =0; for(unsigned int y=0; y<height-1; y+=2) { for(unsigned int x = 0; x<width; ++x) { table[y][x] = alpha; table[y+1][x] = alpha; alpha++; } } // Add padding in case of odd height if (height%2 == 1) { for(unsigned int x = 0; x<width-1; x+=2) { table[height-1][x] = alpha; table[height-1][x+1] = alpha; alpha++; } // In case of odd width, add a single in the corner. // We will merge it into a real flow after shuffeling if (width%2 == 1) { table[height-1][width-1] = alpha; } } shuffle(table); return table; }
bkp::MaskedVector<const TRow> LoadRows(std::string filename) { // If the csv file doesn't exist, we may as well just stop now. // Nothing in our program will be able to run if our data doesn't // load. AssertFileExists(filename); // set up the csv_parser... csv_parser file_parser; file_parser.set_skip_lines(1); file_parser.set_enclosed_char('"', ENCLOSURE_OPTIONAL); file_parser.set_field_term_char(','); file_parser.set_line_term_char('\n'); file_parser.init(filename.c_str()); // Use a deque for initial load - we (theoretically) don't // know how much data we'll be loading and this grows more easily // than a vector (no big copy operations when we go over capacity). // We'll copy to a vector later, which has better read operations. std::deque<TRow> insert_deque; while (file_parser.has_more_rows()) { csv_row row = file_parser.get_row(); insert_deque.push_back(TRow(row)); } // Create a vector that will serve as the backing store for our // MaskedVector. We could do this manually and try to use move // operations to save ourselves from copying all the data, but since // our rows are nearly POD objects, move semantics wouldn't really // be able to save us anything. std::vector<const TRow> allData(insert_deque.begin(), insert_deque.end()); // Move the vector into a MaskedVector and return. return bkp::MaskedVector<const TRow>(std::move(allData)); }