我試圖找到字符串在那裏我有〜250萬串的向量的重複的實例的大載體複製〜檢查字符串中
目前我使用類似:
std::vector<string> concatVec; // Holds all of the concatenated strings containing columns C,D,E,J and U.
std::vector<string> dupecheckVec; // Holds all of the unique instances of concatenated columns
std::vector<unsigned int> linenoVec; // Holds the line numbers of the unique instances only
// Copy first element across, it cannot be a duplicate yet
dupecheckVec.push_back(concatVec[0]);
linenoVec.push_back(0);
// Copy across and do the dupecheck
for (unsigned int i = 1; i < concatVec.size(); i++)
{
bool exists = false;
for (unsigned int x = 0; x < dupecheckVec.size(); x++)
{
if (concatVec[i] == dupecheckVec[x])
{
exists = true;
}
}
if (exists == false)
{
dupecheckVec.push_back(concatVec[i]);
linenoVec.push_back(i);
}
else
{
exists = false;
}
}
這很好的小文件,但很明顯,最終以一個非常長的時間,文件大小的增長,由於嵌套的for循環和越來越多的包含在dupecheckVec字符串。
什麼可能是在一個大的文件要做到這一點不那麼可怕呢?
您是否想過使用'unique'算法和'erase'? – lrm29 2011-03-30 13:50:27
@ lrm29:獨特的要求矢量有序,這可能是或不是一個問題在這裏。 – 2011-03-30 14:10:49
這就是爲什麼我沒有發佈它作爲答案。使用算法可能沒有發生OP。 – lrm29 2011-03-30 14:12:22