samedi 28 mars 2015

How can I speed up my c++ natural join row comparison?


This function is the bottleneck of my program and I'm not sure how to optimize it further.


The intent of the function is to simply tell me whether or not two vectors contain the same values that have the same column names. At this point of my algorithm I'm just checking the whether or not I should add the concatenated Row and RowRT by checking those locations where the column names are the same to assure that the corresponding values in the rows in fact all the same. To be clear, I'm passing in the map Duplicates which is simply all of the Columns that had a duplicate and the corresponding indices.


Is there a better way to do this? Am I overcomplicating this?


What I think could be optomized: It seems to me that I should be able to check those Rows without needing to merge the two together, but I'm not sure what other optimizations I need to make could be. Suggestions would be very much appreciated.



bool Database::NaturalJoinAddRowQuery(std::vector<Token> Row, std::vector<Token>& RowRT,
std::map<Token, std::vector<int>>& Duplicates)
{

typedef std::map<Token, std::vector<int>>::iterator it_type;
Row.insert(Row.end(), RowRT.begin(), RowRT.end());

for (it_type it = Duplicates.begin(); it != Duplicates.end(); it++) {

if (it->second.size() != 1)
for (int k = 0; k < it->second.size(); k++)
{
for (int i = 0; i < Row.size(); i++)
{
if (std::find(it->second.begin(), it->second.end(), i) != it->second.end())
{
if (Row[i].Content() != Row[it->second[k]].Content())
return false;

}
}


}
}



Aucun commentaire:

Enregistrer un commentaire