本文整理汇总了C++中TIntPrV::Empty方法的典型用法代码示例。如果您正苦于以下问题:C++ TIntPrV::Empty方法的具体用法?C++ TIntPrV::Empty怎么用?C++ TIntPrV::Empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TIntPrV
的用法示例。
在下文中一共展示了TIntPrV::Empty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetLangCntryByMajority
// set Language and Country for movies that do not have the value set
// for every movie find the mojority language/country in 1-hop neighborhood and set it
void TImdbNet::SetLangCntryByMajority() {
// set language
while (true) {
TIntPrV NIdToVal;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
if (NI().GetLang() != 0) { continue; }
int Nbhs=0; TIntH LangCntH;
for (int e = 0; e < NI.GetOutDeg(); e++) {
LangCntH.AddDat(NI.GetOutNDat(e).GetLang()) += 1; Nbhs++; }
for (int e = 0; e < NI.GetInDeg(); e++) {
LangCntH.AddDat(NI.GetInNDat(e).GetLang()) += 1; Nbhs++; }
if (LangCntH.IsKey(0)) { Nbhs-=LangCntH.GetDat(0); LangCntH.GetDat(0)=0; }
LangCntH.SortByDat(false);
if (LangCntH.GetKey(0) == 0) { continue; }
if (LangCntH[0]*2 >= Nbhs) {
NIdToVal.Add(TIntPr(NI.GetId(), LangCntH.GetKey(0))); }
}
if (NIdToVal.Empty()) { break; } // done
for (int i = 0; i < NIdToVal.Len(); i++) {
GetNDat(NIdToVal[i].Val1).Lang = NIdToVal[i].Val2; }
printf(" language set: %d\n", NIdToVal.Len());
}
int cnt=0;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { if (NI().GetLang()==0) cnt++; }
printf(" NO language: %d\n\n", cnt);
// set country
while (true) {
TIntPrV NIdToVal;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
if (NI().GetCntry() != 0) { continue; }
int Nbhs=0; TIntH CntryCntH;
for (int e = 0; e < NI.GetOutDeg(); e++) {
CntryCntH.AddDat(NI.GetOutNDat(e).GetCntry()) += 1; Nbhs++; }
for (int e = 0; e < NI.GetInDeg(); e++) {
CntryCntH.AddDat(NI.GetInNDat(e).GetCntry()) += 1; Nbhs++; }
if (CntryCntH.IsKey(0)) { Nbhs-=CntryCntH.GetDat(0); CntryCntH.GetDat(0)=0; }
CntryCntH.SortByDat(false);
if (CntryCntH.GetKey(0) == 0) { continue; }
if (CntryCntH[0]*2 >= Nbhs) {
NIdToVal.Add(TIntPr(NI.GetId(), CntryCntH.GetKey(0))); }
}
if (NIdToVal.Empty()) { break; } // done
for (int i = 0; i < NIdToVal.Len(); i++) {
GetNDat(NIdToVal[i].Val1).Cntry = NIdToVal[i].Val2; }
printf(" country set: %d\n", NIdToVal.Len());
}
cnt=0;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { if (NI().GetCntry()==0) cnt++; }
printf(" NO country: %d\n\n", cnt);
}
示例2: Get1CnCom
// get the node ids in 1-connected components
void Get1CnCom(const PUNGraph& Graph, TCnComV& Cn1ComV) {
//TCnCom::GetWccCnt(Graph, SzCntV); IAssertR(SzCntV.Len() == 1, "Graph is not connected.");
TIntPrV EdgeV;
GetEdgeBridges(Graph, EdgeV);
if (EdgeV.Empty()) { Cn1ComV.Clr(false); return; }
PUNGraph TmpG = TUNGraph::New();
*TmpG = *Graph;
for (int e = 0; e < EdgeV.Len(); e++) {
TmpG->DelEdge(EdgeV[e].Val1, EdgeV[e].Val2); }
TCnComV CnComV; GetWccs(TmpG, CnComV);
IAssert(CnComV.Len() >= 2);
const TIntV& MxWcc = CnComV[0].NIdV;
TIntSet MxCcSet(MxWcc.Len());
for (int i = 0; i < MxWcc.Len(); i++) {
MxCcSet.AddKey(MxWcc[i]); }
// create new graph: bridges not touching MxCc of G with no bridges
for (int e = 0; e < EdgeV.Len(); e++) {
if (! MxCcSet.IsKey(EdgeV[e].Val1) && ! MxCcSet.IsKey(EdgeV[e].Val2)) {
TmpG->AddEdge(EdgeV[e].Val1, EdgeV[e].Val2); }
}
GetWccs(TmpG, Cn1ComV);
// remove the largest component of G
for (int c = 0; c < Cn1ComV.Len(); c++) {
if (MxCcSet.IsKey(Cn1ComV[c].NIdV[0])) {
Cn1ComV.Del(c); break; }
}
}