当前位置: 首页>>代码示例>>C++>>正文


C++ THash::GetKeyId方法代码示例

本文整理汇总了C++中THash::GetKeyId方法的典型用法代码示例。如果您正苦于以下问题:C++ THash::GetKeyId方法的具体用法?C++ THash::GetKeyId怎么用?C++ THash::GetKeyId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在THash的用法示例。


在下文中一共展示了THash::GetKeyId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ComputeKCore

int ComputeKCore(const PUNGraph& G) {
  int cnt = 0;
  for(TUNGraph::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++)
    cnt = max(cnt, NI.GetOutDeg());
  THashSet <TInt> D[cnt+1];
  THash <TInt, TInt> deg;
  for(TUNGraph::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) { 
    TInt tmp = NI.GetOutDeg() - G->IsEdge(NI.GetId(), NI.GetId() );
    D[tmp.Val].AddKey(NI.GetId());
    deg.AddDat(NI.GetId()) = tmp;
  }
  int max_k = 0;
  for(int num_iters = 0;num_iters < G->GetNodes(); num_iters++)
    for(int i = 0; i < cnt; i++)
      if(D[i].Empty() == 0) {
        max_k = max(max_k, i);
        TInt a = *(D[i].BegI());
        D[i].DelKey(a);
        deg.AddDat(a.Val) = -1; // Hope overwriting works
        TUNGraph::TNodeI NI = G->GetNI(a.Val);
        for(int e = 0; e < NI.GetOutDeg(); e++) {
          TInt b = NI.GetOutNId(e);
          if(deg.GetDat(b) >= 0) {
            int Id = deg.GetKeyId(b); 
            D[deg[Id].Val].DelKey(b);
            deg[Id] = deg[Id] - 1;  //Hope the overwriting works
            D[deg[Id]].AddKey(b);
          }
        }
        break;
      }
  return max_k;
}
开发者ID:simp1eton,项目名称:snap-social,代码行数:33,代码来源:k-core.cpp

示例2: main

int main(int argc, char* argv[])
{
	TExeTm ExeTm;
	PGconn *conn;
	PGresult *res;
	int id,start,rec_count,row,indx,end;
	unsigned int q;
	int total_number_tweets = 0;
	double tweet_date = 0;
	TStr TweetStr("");
	TStr TweetStrLc("");

	if(argc > 1)
	{
		start = atoi(argv[1]);
	}
	else
	{
		printf("YOU SHOULD SET THE INDICES...\n\n");
		return 1;
	}
	indx = start * LENGTH;
	end = indx + LENGTH;

	printf(":::::::: Find Cascades of Quotes In Twitter Separately ::::::::\n");
	const TStr StartDate = Env.GetIfArgPrefixStr("-sd:", "2008-08-01 00:00:00", "Starting date");
	const TStr EndDate = Env.GetIfArgPrefixStr("-ed:", "2009-10-01 00:00:00", "Ending date");

	Env = TEnv(argc, argv, TNotify::StdNotify);
	Env.PrepArgs(TStr::Fmt("\nFinding the cascades of the desired quotes. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
	try
	{
		while(indx < end)
		{
			TStr qContentFname = TStr::Fmt("QuotesData/Q%d.rar",indx);
			TStr resultFname = TStr::Fmt("QuotesCascResult/R%d.rar",indx++);

			if(fileExists(resultFname))
			{
				if(fileExists(qContentFname))
				{
					// removing the quotes' content file
					system(TStr::Fmt("rm %s",qContentFname.CStr()).CStr());
				}
			}
			else
			{
				if(fileExists(qContentFname))
				{
					THash<TStr,TInt> quotesContent;
					THash<TInt,TSecTmV> CascadesOnTwitter;

					TZipIn ZquotesIn(qContentFname);
					quotesContent.Load(ZquotesIn);
					printf("Q%d loading done, it contains %d quotes.\n",indx-1,quotesContent.Len());

					conn = PQconnectdb("dbname=twitter host=postgresql01.mpi-sws.org user=twitter [email protected]");

					if (PQstatus(conn) == CONNECTION_BAD)
					{
						printf("We were unable to connect to the database");
						return 1;
					}

					// we use cursors/fetch to speed up the process; batch of 10000 tweets
					PQexec(conn, "begin work");
					PQexec(conn,TStr::Fmt("declare mycursor cursor for select tweettext, extract(epoch from tweettime) from tweets where tweettime >= timestamp '%s' and tweettime < timestamp '%s'", StartDate.CStr(), EndDate.CStr()).CStr());

					do
					{
						res = PQexec(conn, "FETCH 1000000 IN mycursor");    // all of them are: 1675401026
						if (PQresultStatus(res) == PGRES_TUPLES_OK)
						{
							rec_count = PQntuples(res);
							total_number_tweets += rec_count;
							printf("Adding %d tweets... (total: %d)\n", rec_count, total_number_tweets);

							for (row=0; row<rec_count; row++)
							{
								TweetStr = PQgetvalue(res, row, 0);
								tweet_date = TStr(PQgetvalue(res, row, 1)).GetFlt();
								TweetStrLc = TweetStr.ToLc();
								for(q=0;q<quotesContent.Len();q++)
								{
									if (TweetStrLc.SearchStr(quotesContent.GetKey(q)) > -1)
									{
										TSecTm td(tweet_date);
										id = CascadesOnTwitter.GetKeyId(quotesContent[q]);
										if(id == -1)
										{
											CascadesOnTwitter.AddDat(quotesContent[q]).Add(td);
										}
										else
										{
											CascadesOnTwitter.GetDat(quotesContent[q]).AddSorted(td);
										}
									}
								}
							}

//.........这里部分代码省略.........
开发者ID:omid55,项目名称:memestwrepo,代码行数:101,代码来源:find_cascades_of_quotes_separately.cpp

示例3: main


//.........这里部分代码省略.........
		twitterContent2.close();


		// URLS Cascades Over Memes and Twitter
		ofstream quotesContent3("MEMES_TWITTER_URL_QuotesContent.csv",ios::out|ios::app);
		ofstream memeWebs3("MEMES_TWITTER_URL_MemesCascadesWebs.csv",ios::out|ios::app);
		ofstream memeTimes3("MEMES_TWITTER_URL_MemesCascadesTimes.csv",ios::out|ios::app);
		ofstream externalLinks3("MEMES_TWITTER_URL_MemesExternalLinks.csv",ios::out|ios::app);
		ofstream twitter3("MEMES_TWITTER_URL_TwitterUrlCascades.csv",ios::out|ios::app);
		for(i=0;i<cascadesOnTwitterUrls.Len();i++)
		{
			quoteIndex = cascadesOnTwitterUrls.GetKey(i);
			quotesContent3 << quotes.GetKey(quoteIndex).CStr() << "\r\n";

			for(j=0;j<quotes[quoteIndex].Len();j++)
			{
				for(k=0;k<quotes[quoteIndex][j].explicit_links.Len();k++)
				{
					externalLinks3 << quotes[quoteIndex][j].explicit_links[k].Val << "," << quotes[quoteIndex][j].post.Val<<"\r\n";   // << CHECK HERE >> CHANGE -> TO SPACE
				}
				memeTimes3 << quotes[quoteIndex][j].time.GetAbsSecs() << ",";
				memeWebs3 << quotes[quoteIndex][j].post.Val << ",";
			}
			memeTimes3 << "\r\n";
			memeWebs3 << "\r\n";
			externalLinks3 << "-1\r\n";  // this means that the external links for this quote is finished

			for(j=0;j<cascadesOnTwitterUrls.GetDat(quoteIndex).Len();j++)
			{
				twitter3 << cascadesOnTwitterUrls.GetDat(quoteIndex)[j] << ",";
			}
			twitter3 << "\r\n";
		}
		quotesContent3.close();
		memeWebs3.close();
		memeTimes3.close();
		externalLinks3.close();
		twitter3.close();


		// INTERSECT OF URLS OF TEXTS Cascades Over Memes and Twitter
		ofstream quotesContent4("TRIPLE_QuotesContent.csv",ios::out|ios::app);
		ofstream memeWebs4("TRIPLE_MemesCascadesWebs.csv",ios::out|ios::app);
		ofstream memeTimes4("TRIPLE_MemesCascadesTimes.csv",ios::out|ios::app);
		ofstream externalLinks4("TRIPLE_MemesExternalLinks.csv",ios::out|ios::app);
		ofstream twitter4("TRIPLE_TwitterUrlCascades.csv",ios::out|ios::app);
		ofstream twitterContent4("TRIPLE_TwitterTextCascades.csv",ios::out|ios::app);
		for(i=0;i<cascadesOnTwitterUrls.Len();i++)
		{
			quoteIndex = cascadesOnTwitterUrls.GetKey(i);
			if(cascadesOnTwitterContents.GetKeyId(quoteIndex) == -1)
			{
				continue;
			}
			quotesContent4 << quotes.GetKey(quoteIndex).CStr() << "\r\n";

			for(j=0;j<quotes[quoteIndex].Len();j++)
			{
				for(k=0;k<quotes[quoteIndex][j].explicit_links.Len();k++)
				{
					externalLinks4 << quotes[quoteIndex][j].explicit_links[k].Val << "," << quotes[quoteIndex][j].post.Val<<"\r\n";   // << CHECK HERE >> CHANGE -> TO SPACE
				}
				memeTimes4 << quotes[quoteIndex][j].time.GetAbsSecs() << ",";
				memeWebs4 << quotes[quoteIndex][j].post.Val << ",";
			}
			memeTimes4 << "\r\n";
			memeWebs4 << "\r\n";
			externalLinks4 << "-1\r\n";  // this means that the external links for this quote is finished

			for(j=0;j<cascadesOnTwitterContents.GetDat(quoteIndex).Len();j++)
			{
				twitterContent4 << cascadesOnTwitterContents.GetDat(quoteIndex)[j] << ",";
			}

			for(j=0;j<cascadesOnTwitterUrls.GetDat(quoteIndex).Len();j++)
			{
				twitter4 << cascadesOnTwitterUrls.GetDat(quoteIndex)[j] << ",";
			}
			twitter4 << "\r\n";
			twitterContent4 << "\r\n";
		}
		quotesContent4.close();
		memeWebs4.close();
		memeTimes4.close();
		externalLinks4.close();
		twitter4.close();
		twitterContent4.close();
	}
	catch(exception& ex)
	{
		printf("\nError1 happened, it was: %s\n\n",ex.what());
	}
	catch(TPt<TExcept>& ex)
	{
		printf("\nError2 happened: %s\n\n",ex[0].GetStr().CStr());
	}

	printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
	return 0;
}
开发者ID:omid55,项目名称:memestwrepo,代码行数:101,代码来源:save_cascades_for_matlab.cpp

示例4: main


//.........这里部分代码省略.........
//	printf("CascadesRawUrlsOnTwitterData loading done, it contains %d items.\n",cascadesInUrlsOnTwitter.Len());
//	long long l1 = 0;
//	for(int i=0;i<cascadesInUrlsOnTwitter.Len();i++)
//	{
//		l1+=cascadesInUrlsOnTwitter[i].Len();
//	}
//	cascadesInUrlsOnTwitter.Clr();
//
//	TZipIn z2("CascadesFullUrlsOnTwitterData.rar");
//	cascadesInUrlsOnTwitter.Load(z2);
//	printf("CascadesFullUrlsOnTwitterData loading done, it contains %d items.\n",cascadesInUrlsOnTwitter.Len());
//	long long l2 = 0;
//	for(int i=0;i<cascadesInUrlsOnTwitter.Len();i++)
//	{
//		l2+=cascadesInUrlsOnTwitter[i].Len();
//	}
//
//	cout << "\n\n\nRaw All Items: " << l1 << "\n" << "Full All Items: " << l2 << endl;
//	return 0;


//	TZipIn resIn("CascadesUrlsOnTwitterData.rar");
//	cascadesInUrlsOnTwitter.Load(resIn);
//	printf("The size of CascadesUrlsOnTwitter was: %d\n",cascadesInUrlsOnTwitter.Len());
//	for(int l=0;l<5;l++)
//	{
//		printf("\n\n\nQ%d:\n\n",l);
//		for(int o=0;o<cascadesInUrlsOnTwitter[l].Len();o++)
//		{
//			printf("%d. %s\n",o,cascadesInUrlsOnTwitter[l][o].GetYmdTmStr().CStr());
//		}
//	}
//	return 0;


	TExeTm ExeTm;
	unsigned int q,p;
	int id,i;
	TSecTmV* cascade;
	TSecTmV* res;
	Env = TEnv(argc, argv, TNotify::StdNotify);
	Env.PrepArgs(TStr::Fmt("\n***(((Finding the cascades of the desired quotes in their urls)))***. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
	try
	{
		TZipIn ZquotesIn("/NS/twitter-5/work/oaskaris/QuotesPreprocessedData_NIFTY.rar");
		preprocessedQuotes.Load(ZquotesIn);
		printf("QuotesPreprocessed loading done, it contains %d quotes.\n",preprocessedQuotes.Len());

		TZipIn ZpostsPropIn("PostsPropagatedOverTwitterFullUrls.rar");
		postsPropagatedOverTw.Load(ZpostsPropIn);
		printf("PostsPropagatedOverTwitterFullUrls loading done, it contains %d items.\n",postsPropagatedOverTw.Len());


		for(q=0;q<preprocessedQuotes.Len();q++)
		{
			for(p=0;p<preprocessedQuotes[q].Len();p++)
			{
				TUInt postId = preprocessedQuotes[q][p].post;
				if(postsPropagatedOverTw.GetKeyId(postId) != -1)
				{
					cascade = &postsPropagatedOverTw.GetDat(postId);
					id = cascadesInUrlsOnTwitter.GetKeyId(q);
					if(id == -1)
					{
						res = &cascadesInUrlsOnTwitter.AddDat(q);
						for(i=0;i<cascade->Len();i++)
						{
							res->AddSorted((*cascade)[i]);
						}
					}
					else
					{
						res = &cascadesInUrlsOnTwitter.GetDat(q);
						for(i=0;i<cascade->Len();i++)
						{
							res->AddSorted((*cascade)[i]);
						}
					}
				}
			}
		}

		printf("\n\nFINDING THE CASCADES OF QUOTES WITH URLS OVER TWITTER IS DONE\n\n");

		SaveAll();
	}
	catch(exception& ex)
	{
		SaveAll();
		printf("\nError1 happened, it was: %s\n\n",ex.what());
	}
	catch(TPt<TExcept>& ex)
	{
		SaveAll();
		printf("\nError2 happened: %s\n\n",ex[0].GetStr().CStr());
	}

	printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
	return 0;
}
开发者ID:omid55,项目名称:memestwrepo,代码行数:101,代码来源:find_cascades_of_quotes_in_urls.cpp


注:本文中的THash::GetKeyId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。