本文整理汇总了C++中SearchData::getNbMatches方法的典型用法代码示例。如果您正苦于以下问题:C++ SearchData::getNbMatches方法的具体用法?C++ SearchData::getNbMatches怎么用?C++ SearchData::getNbMatches使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SearchData
的用法示例。
在下文中一共展示了SearchData::getNbMatches方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doSearch
void SearchOperation::doSearch( SearchData& searchData, qint64 initialLine )
{
const qint64 nbSourceLines = sourceLogData_->getNbLine();
int maxLength = 0;
int nbMatches = searchData.getNbMatches();
SearchResultArray currentList = SearchResultArray();
// Ensure no re-alloc will be done
currentList.reserve( nbLinesInChunk );
LOG(logDEBUG) << "Searching from line " << initialLine << " to " << nbSourceLines;
if (initialLine < startLine_) {
initialLine = startLine_;
}
const qint64 endLine = qMin(nbSourceLines, endLine_);
for ( qint64 i = initialLine; i < endLine; i += nbLinesInChunk ) {
if ( *interruptRequested_ )
break;
const int percentage = ( i - initialLine ) * 100 / ( endLine - initialLine );
emit searchProgressed( nbMatches, percentage );
const QStringList lines = sourceLogData_->getLines( i,
qMin( nbLinesInChunk, (int) ( endLine - i ) ) );
LOG(logDEBUG) << "Chunk starting at " << i <<
", " << lines.size() << " lines read.";
int j = 0;
for ( ; j < lines.size(); j++ ) {
if ( regexp_.match( lines[j] ).hasMatch() ) {
// FIXME: increase perf by removing temporary
const int length = sourceLogData_->getExpandedLineString(i+j).length();
if ( length > maxLength )
maxLength = length;
currentList.push_back( MatchingLine( i+j ) );
nbMatches++;
}
}
// After each block, copy the data to shared data
// and update the client
searchData.addAll( maxLength, currentList, i+j );
currentList.clear();
}
emit searchProgressed( nbMatches, 100 );
}
示例2: doSearch
void SearchOperation::doSearch( SearchData& searchData, LineNumber initialLine )
{
const auto& config = Persistable::get<Configuration>();
const auto nbSourceLines = sourceLogData_->getNbLine();
LineLength maxLength = 0_length;
LinesCount nbMatches = searchData.getNbMatches();
const auto nbLinesInChunk = LinesCount( config.searchReadBufferSizeLines() );
LOG( logDEBUG ) << "Searching from line " << initialLine << " to " << nbSourceLines;
if ( initialLine < startLine_ ) {
initialLine = startLine_;
}
const auto endLine = qMin( LineNumber( nbSourceLines.get() ), endLine_ );
using namespace std::chrono;
high_resolution_clock::time_point t1 = high_resolution_clock::now();
QSemaphore searchCompleted;
QSemaphore blocksDone;
using SearchBlockQueue = moodycamel::BlockingConcurrentQueue<SearchBlockData>;
using ProcessMatchQueue = moodycamel::BlockingConcurrentQueue<PartialSearchResults>;
SearchBlockQueue searchBlockQueue;
ProcessMatchQueue processMatchQueue;
std::vector<QFuture<void>> matchers;
const auto matchingThreadsCount = [&config]()
{
if ( !config.useParallelSearch() ) {
return 1;
}
return qMax( 1, config.searchThreadPoolSize() == 0
? QThread::idealThreadCount() - 1
: static_cast<int>( config.searchThreadPoolSize() ) );
}();
LOG( logINFO ) << "Using " << matchingThreadsCount << " matching threads";
auto localThreadPool = std::make_unique<QThreadPool>();
localThreadPool->setMaxThreadCount( matchingThreadsCount + 2 );
const auto makeMatcher = [this, &searchBlockQueue, &processMatchQueue,
pool = localThreadPool.get()]( size_t index ) {
// copy and optimize regex for each thread
auto regexp = QRegularExpression{ regexp_.pattern(), regexp_.patternOptions() };
regexp.optimize();
return QtConcurrent::run( pool, [regexp, index, &searchBlockQueue, &processMatchQueue]() {
auto cToken = moodycamel::ConsumerToken{ searchBlockQueue };
auto pToken = moodycamel::ProducerToken{ processMatchQueue };
for ( ;; ) {
SearchBlockData blockData;
searchBlockQueue.wait_dequeue( cToken, blockData );
LOG( logDEBUG ) << "Searcher " << index << " " << blockData.chunkStart;
const auto lastBlock = blockData.lines.empty();
if ( !lastBlock ) {
blockData.results
= filterLines( regexp, blockData.lines, blockData.chunkStart );
}
LOG( logDEBUG ) << "Searcher " << index << " sending matches "
<< blockData.results.matchingLines.size();
processMatchQueue.enqueue( pToken, std::move( blockData.results ) );
if ( lastBlock ) {
LOG( logDEBUG ) << "Searcher " << index << " last block";
return;
}
}
} );
};
for ( int i = 0; i < matchingThreadsCount; ++i ) {
matchers.emplace_back( makeMatcher( i ) );
}
auto processMatches = QtConcurrent::run( localThreadPool.get(), [&]() {
auto cToken = moodycamel::ConsumerToken{ processMatchQueue };
size_t matchersDone = 0;
int reportedPercentage = 0;
auto reportedMatches = nbMatches;
LinesCount totalProcessedLines = 0_lcount;
const auto totalLines = endLine - initialLine;
for ( ;; ) {
PartialSearchResults matchResults;
//.........这里部分代码省略.........