리팩토링
nxn 매트릭스 분석 one depth 분석 필터 구현 git-svn-id: svn://192.168.0.12/source@168 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
194
MorphereAnalyzer/yalgorithm.cpp
Normal file
194
MorphereAnalyzer/yalgorithm.cpp
Normal file
@@ -0,0 +1,194 @@
|
||||
#include "yalgorithm.h"
|
||||
#include "ychildrenthread.h"
|
||||
#include <QDebug>
|
||||
/*
|
||||
*class YASingleton
|
||||
*
|
||||
*/
|
||||
YAlgorithm* YASingleton::algorithm = NULL;
|
||||
YAlgorithm* YASingleton::getInstance()
|
||||
{
|
||||
if(algorithm == NULL)
|
||||
algorithm = new YAlgorithm();
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
YASingleton::YASingleton()
|
||||
{
|
||||
}
|
||||
|
||||
YASingleton::~YASingleton()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
*class YAlgorithm
|
||||
*
|
||||
*/
|
||||
|
||||
YAlgorithm::YAlgorithm()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
YAlgorithm::~YAlgorithm()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
QMap <QString, int> YAlgorithm::getResult()
|
||||
{
|
||||
return m_mapTotalResult;
|
||||
}
|
||||
|
||||
void YAlgorithm::setParam(QMap <QString, QString> mapParam)
|
||||
{
|
||||
m_mapParam = mapParam;
|
||||
}
|
||||
|
||||
|
||||
QMutex* YAlgorithm::getMutex()
|
||||
{
|
||||
return &mutex;
|
||||
}
|
||||
|
||||
void YAlgorithm::setDataAlgorithmInterface(DataAlgorithmInterface* pDAInterface)
|
||||
{
|
||||
m_pDAInterface = pDAInterface;
|
||||
}
|
||||
|
||||
void YAlgorithm::clearParam()
|
||||
{
|
||||
m_mapParam.clear();
|
||||
}
|
||||
|
||||
void YAlgorithm::clearResult()
|
||||
{
|
||||
m_mapTotalResult.clear();
|
||||
}
|
||||
|
||||
void YAlgorithm::init()
|
||||
{
|
||||
clearParam();
|
||||
clearResult();
|
||||
m_nThread = 1;
|
||||
m_pYMThread = NULL;
|
||||
}
|
||||
|
||||
|
||||
QMap <QString, int> YAlgorithm::KeywordFilter(QMap <QString, int> mapResult)
|
||||
{
|
||||
QMap <QString, int> Result;
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
QMap <QString, int> YAlgorithm::RankFilter(QMap <QString, int> mapResult)
|
||||
{
|
||||
QMap <QString, int> Result;
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void YAlgorithm::EmergeThreadResult()
|
||||
{
|
||||
for(int i = 0;i < getThreadNumber(); i++)
|
||||
{
|
||||
for(QMap<QString, int>::iterator iterPos = m_mapThreadResult[i]->begin(); iterPos != m_mapThreadResult[i]->end();iterPos++)
|
||||
{
|
||||
if(m_mapTotalResult.contains(iterPos.key()))
|
||||
{
|
||||
m_mapTotalResult[iterPos.key()] += iterPos.value();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mapTotalResult.insert(iterPos.key(), iterPos.value());
|
||||
}
|
||||
}
|
||||
m_mapThreadResult[i]->clear();
|
||||
}
|
||||
|
||||
for(int i = 0;i < getThreadNumber(); i++)
|
||||
{
|
||||
delete m_mapThreadResult[i];
|
||||
}
|
||||
delete[] m_mapThreadResult;
|
||||
}
|
||||
|
||||
void YAlgorithm::setThreadNumber(int nThread)
|
||||
{
|
||||
m_nThread = nThread;
|
||||
}
|
||||
|
||||
int YAlgorithm::getThreadNumber()
|
||||
{
|
||||
return m_nThread;
|
||||
}
|
||||
|
||||
void YAlgorithm::Start()
|
||||
{
|
||||
if(m_mapParam.isEmpty())
|
||||
return;
|
||||
|
||||
bool okThread = false;
|
||||
int nThread = m_mapParam.value("Thread").trimmed().toInt(&okThread);
|
||||
|
||||
if(!okThread)
|
||||
setThreadNumber(1);
|
||||
else
|
||||
setThreadNumber(nThread);
|
||||
|
||||
m_pYMThread = new YMorphereThread*[getThreadNumber()];
|
||||
for(int i = 0; i < getThreadNumber(); i++)
|
||||
{
|
||||
m_pYMThread[i] = ThreadFactory::getThread(m_mapParam);
|
||||
m_pYMThread[i]->setDataAlgorithmInterface(m_pDAInterface);
|
||||
m_pYMThread[i]->setMutex(&mutex);
|
||||
m_pYMThread[i]->setParam(m_mapParam);
|
||||
}
|
||||
for(int i = 0;i < getThreadNumber(); i++)
|
||||
{
|
||||
m_pYMThread[i]->start();
|
||||
}
|
||||
for(int i = 0;i < getThreadNumber(); i++)
|
||||
{
|
||||
m_pYMThread[i]->wait();
|
||||
}
|
||||
|
||||
m_mapThreadResult = new QMap<QString, int>*[getThreadNumber()];
|
||||
for(int i = 0; i < getThreadNumber(); i++)
|
||||
{
|
||||
m_mapThreadResult[i] = new QMap<QString, int>();
|
||||
}
|
||||
for(int i = 0; i < getThreadNumber(); i++)
|
||||
{
|
||||
*m_mapThreadResult[i] = m_pYMThread[i]->getResult();
|
||||
m_pYMThread[i]->clearResult();
|
||||
}
|
||||
|
||||
for(int i = 0;i < getThreadNumber(); i++)
|
||||
{
|
||||
delete m_pYMThread[i];
|
||||
}
|
||||
delete[] m_pYMThread;
|
||||
|
||||
EmergeThreadResult();
|
||||
/*
|
||||
if(!m_mapParam.value("KeywordFilter").isEmpty())
|
||||
{
|
||||
m_mapTotalResult = KeywordFilter(m_mapTotalResult);
|
||||
}
|
||||
if(!m_mapParam.value("RankFilter").isEmpty())
|
||||
{
|
||||
m_mapTotalResult = RankFilter(m_mapTotalResult);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user