WordCount countWords(const QString &file)
{
QFile f(file);
f.open(QIODevice::ReadOnly);
QTextStream textStream(&f);
WordCount wordCount;
while (textStream.atEnd() == false)
foreach (QString word, textStream.readLine().split(" "))
wordCount[word] += 1;
return wordCount;
}
...
QStringList files = findFiles("../../", QStringList() << "*.cpp" << "*.h");
...
int mapReduceTime = 0;
{
QTime time;
time.start();
WordCount total = mappedReduced(files, countWords, reduce);
mapReduceTime = time.elapsed();
qDebug() << "MapReduce" << mapReduceTime;
}
說我想跟蹤我正在處理哪個文件,我可以創建一個全局靜態變量,並在每次啓動運行時遞增它,在countWord函數內部知道我正在做一些處理在檔案號碼1?或者是不可能知道哪些文件將被首先處理?我問,因爲mapreduce允許並行處理,但我不知道操作系統將如何安排線程。Qt庫中的mapreduce是否保留了輸入文件的序列?
您確實需要發佈完整的代碼,以表明您正在嘗試做什麼,並說明如何實現您的目標。 –