void PackageRepository::setAURData(const QList<PackageListData>*const listOfForeignPackages, const QSet<QString>& unrequiredPackages) { // std::cout << "received new foreign package list" << std::endl; std::for_each(m_dependingModels.begin(), m_dependingModels.end(), BeginResetModel()); // delete AUR items in list /*for (TListOfPackages::iterator it = m_listOfPackages.begin(); it != m_listOfPackages.end(); ++it) { if (*it != NULL && (*it)->managedByAUR) { delete *it; it = m_listOfPackages.erase(it); } }*/ m_listOfAURPackages.clear(); for (QList<PackageListData>::const_iterator it = listOfForeignPackages->begin(); it != listOfForeignPackages->end(); ++it) { //qDebug() << "Status: " << (*it).status; PackageData*const pkg = new PackageData(*it, unrequiredPackages.contains(it->name) == false); m_listOfPackages.push_back(pkg); m_listOfAURPackages.push_back(pkg); } qSort(m_listOfPackages.begin(), m_listOfPackages.end(), TSort()); qSort(m_listOfAURPackages.begin(), m_listOfAURPackages.end(), TSort()); std::for_each(m_dependingModels.begin(), m_dependingModels.end(), EndResetModel()); }
/* * Iterates over the package list to mark outdated foreign packages */ void PackageRepository::setAUROutdatedData(QList<PackageListData>*const listOfForeignPackages, const QStringList& outdatedAURPackages) { std::for_each(m_dependingModels.begin(), m_dependingModels.end(), BeginResetModel()); //delete AUR items in list for (TListOfPackages::iterator it = m_listOfPackages.begin(); it != m_listOfPackages.end(); ++it) { if (*it != NULL && ((*it)->status == ectn_FOREIGN || (*it)->status == ectn_FOREIGN_OUTDATED)) { delete *it; it = m_listOfPackages.erase(it); } } m_listOfAURPackages.clear(); for (QList<PackageListData>::iterator it = listOfForeignPackages->begin(); it != listOfForeignPackages->end(); ++it) { if (outdatedAURPackages.contains(it->name)) { it->status = ectn_FOREIGN_OUTDATED; } PackageData*const pkg = new PackageData(*it, true, true); m_listOfPackages.push_back(pkg); m_listOfAURPackages.push_back(pkg); } qSort(m_listOfPackages.begin(), m_listOfPackages.end(), TSort()); qSort(m_listOfAURPackages.begin(), m_listOfAURPackages.end(), TSort()); std::for_each(m_dependingModels.begin(), m_dependingModels.end(), EndResetModel()); }
MyStack<Tv>* Graph<Tv, Te>::tSort(int s){ //assert: 0 <= s < n reset(); int clock = 0; int v = s; MyStack<Tv> * S = new MyStack<Tv>; //用栈记录排序顶点 do{ if(UNDISCOVERED == status(v)) if( !TSort(v, clock, S) ){ //clock并非必需 while( !S->empty()) //任一连通域(亦即整图) 非DAG S->pop(); break; } }while(s != ( v = (++v) % n)); return S; //若输入为DAG,则s内各顶点自顶向低排序; 否则(不存在拓扑排序), S空 }
bool Graph<Tv, Te>::TSort(int v, int &clock, MyStack<Tv> *S){ //assert: 0 <= v < n dTime(v) = ++clock; status(v) = DISCOVERED; //发现顶点v for(int u = firstNbr(v); -1 < u; u = nextNbr(v, u)) //枚举v的所有邻居u switch(status(v)){ case UNDISCOVERED: parent(u) = v; type(v, u) = TREE; if( !TSort(u, clock, S)) //从顶点u处出发深入搜索 return false; //若u及其后代不能拓扑程序(则全图亦必如此), 故返回并报告 break; case DISCOVERED: type(v, u) = BACKWARD; //一旦发现后向边(非DAG), 则 return false; //不必深入,故返回并报告 default: //VISITED(digraphs only) type(v, u) = (dTime(v) < dTime(u) ) ? FORWARD : CROSS; break; } status(v) = VISITED; S->push(vertex(v) ); //顶点被标记为VISITED时, 随即入栈 return true; //v及其后代可以拓扑排序 }
void PackageRepository::setData(const QList<PackageListData>*const listOfPackages, const QSet<QString>& unrequiredPackages) { // std::cout << "received new package list" << std::endl; std::for_each(m_dependingModels.begin(), m_dependingModels.end(), BeginResetModel()); // delete items in groups list for (QList<Group*>::const_iterator it = m_listOfGroups.begin(); it != m_listOfGroups.end(); ++it) { if (*it != NULL) (*it)->invalidateList(); } // delete items in list for (TListOfPackages::const_iterator it = m_listOfPackages.begin(); it != m_listOfPackages.end(); ++it) { if (*it != NULL) delete *it; } m_listOfAURPackages.clear(); m_listOfPackages.clear(); for (QList<PackageListData>::const_iterator it = listOfPackages->begin(); it != listOfPackages->end(); ++it) { m_listOfPackages.push_back(new PackageData(*it, unrequiredPackages.contains(it->name) == false)); } qSort(m_listOfPackages.begin(), m_listOfPackages.end(), TSort()); std::for_each(m_dependingModels.begin(), m_dependingModels.end(), EndResetModel()); }