jeudi 26 mai 2016

Using pointers to access row wise data inside map in C++

I have following data structure that stores result from database,

//       column name,    array of (row values)
std::map<std::string, std::vector<std::string>> dataset;

This will have values vector of string values for each column and I can quickly access each column values by

dataset["columnName"][rowIndex];

Sometimes, I also want to access all columns of complete row, this will require complex code like,

std::vector<std::string> getRow(unsigned int rowIndex)
{
    std::vector<std::string> row_data;
    for(auto& col : dataset)
        row_data.emplace(col[0]);
    return row_data;
}

Is this implementation to access row data efficient enough? Can I keep another map in row wise orientation with pointer to values in dataset? How to do it?

Something like,

         row Index,     array of (  pointer  to  string value in dataset)
std::map<unsigned long, std::vector<std::unique_ptr<std::string>>> point;

Aucun commentaire:

Enregistrer un commentaire