本文整理汇总了C++中THash类的典型用法代码示例。如果您正苦于以下问题:C++ THash类的具体用法?C++ THash怎么用?C++ THash使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了THash类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HashFile
int HashFile(char **Return, char *Type, char *Path, int Encoding)
{
THash *Hash;
STREAM *S;
char *Tempstr=NULL;
int result;
S=STREAMOpenFile(Path,O_RDONLY);
if (! S) return(FALSE);
Hash=HashInit(Type);
if (! Hash)
{
STREAMClose(S);
return(FALSE);
}
Tempstr=SetStrLen(Tempstr,4096);
result=STREAMReadBytes(S,Tempstr,4096);
while (result !=EOF)
{
Hash->Update(Hash, Tempstr, result);
result=STREAMReadBytes(S,Tempstr,4096);
}
DestroyString(Tempstr);
STREAMClose(S);
result=Hash->Finish(Hash, Encoding, Return);
HashDestroy(Hash);
return(result);
}
示例2: GetNodeMembership
void TAGM::GetNodeMembership(THash<TInt,TIntV >& NIDComVH, const TVec<TIntV>& CmtyVV) {
THash<TInt,TIntV> CmtyVH;
for(int i=0;i<CmtyVV.Len();i++) {
CmtyVH.AddDat(i,CmtyVV[i]);
}
GetNodeMembership(NIDComVH,CmtyVH);
}
示例3: Err
/// Shingles by words
void LSH::HashShinglesOfClusters(TQuoteBase *QuoteBase,
TClusterBase *ClusterBase, TIntV& ClusterIds, TInt ShingleLen,
THash<TMd5Sig, TIntV>& ShingleToClusterIds) {
Err("Hashing shingles of clusters...\n");
for (int i = 0; i < ClusterIds.Len(); i++) {
if (i % 1000 == 0) {
fprintf(stderr, "%d out of %d completed\n", i, ClusterIds.Len());
}
TCluster C;
ClusterBase->GetCluster(ClusterIds[i], C);
//fprintf(stderr, "%d vs. %d\n", ClusterIds[i].Val, C.GetId().Val);
// Put x-word shingles into hash table; x is specified by ShingleLen parameter
THashSet < TMd5Sig > CHashedShingles;
GetHashedShinglesOfCluster(QuoteBase, C, ShingleLen, CHashedShingles);
for (THashSet<TMd5Sig>::TIter Hash = CHashedShingles.BegI();
Hash < CHashedShingles.EndI(); Hash++) {
TIntV ShingleClusterIds;
if (ShingleToClusterIds.IsKey(*Hash)) {
ShingleClusterIds = ShingleToClusterIds.GetDat(*Hash);
}
ShingleClusterIds.Add(ClusterIds[i]);
ShingleToClusterIds.AddDat(*Hash, ShingleClusterIds);
}
}
Err("Done hashing!\n");
}
示例4: ReinforceEdges
// IN-OUT edges are swapped (so that the prog runs faster)
// Send message via IN edge proportional to the OUT edge weight
void TWgtNet::ReinforceEdges(const int& NIters) {
THash<TInt, TFlt> OutWgtSumH;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
double wgt = 0;
for (int e = 0; e < NI.GetOutDeg(); e++) {
wgt += NI.GetOutEDat(e); }
OutWgtSumH.AddDat(NI.GetId(), wgt);
}
printf("Reinforcing edges for %d iterations\n", NIters);
// iterate
TExeTm ExeTm;
for (int iter = 0; iter < NIters; iter++) {
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
const double X = TInt::Rnd.GetUniDev() * OutWgtSumH.GetDat(NI.GetId());
double x = 0; int e = 0;
for ( ; x + NI.GetOutEDat(e) < X; e++) {
x += NI.GetOutEDat(e); }
IAssert(IsEdge(NI.GetOutNId(e), NI.GetId()));
GetEDat(NI.GetOutNId(e), NI.GetId()) += 1; // reinforce the edge
OutWgtSumH.GetDat(NI.GetOutNId(e)) += 1;
}
if (iter % (NIters/100) == 0) {
printf("\r%d [%s]", iter, ExeTm.GetStr());
}
}
printf(" done.\n");
}
示例5: choose_seeds
THash<TInt, TInt> * choose_seeds (const PUNGraph g, const int num, const int * infection_state, const int infect) {
THash<TInt, TInt> choices;
THash<TInt, TUNGraph::TNode> nodes;
THash<TInt, TInt> * output = new THash<TInt, TInt> ();
TInt weight = 0;
TInt num_total = 0;
for (TUNGraph::TNodeI n = g->BegNI(); n != g->EndNI(); n++) {
//cout << "nodeID: " << n.GetId() << ",\tStatus: " << infection_state[n.GetId () - 1] << endl;
if (infection_state[n.GetId () - 1] != infect) {
weight += n.GetDeg ();
choices.AddDat (num_total, weight);
nodes.AddDat (num_total, n.GetId());
num_total++;
}
}
// TRnd random ((int) time(NULL));
// TRnd random (0);
TInt num_chosen = 0;
while (num_chosen < num) {
TInt choice = my_random.GetUniDevInt (weight);
TUNGraph::TNode node_choice = nodes[find (choice, choices, 0, num_total-1)];
if (!output->IsKey(node_choice.GetId())) {
num_chosen++;
// cout << node_choice.GetId () << "\n";
output->AddDat(node_choice.GetId (), 1);
}
}
return output;
}
示例6: InitListViewContorol
void InitListViewContorol(HWND hWnd)
{
HWND hWndLV = GetDlgItem(hWnd, IDC_LIST_MAILBOX);
LV_COLUMN lc;
LV_ITEM li;
HIMAGELIST hImgList;
RECT rect;
GetClientRect(hWndLV, &rect);
// イメージリストの作成
hImgList = ImageList_Create(16, 16, ILC_COLOR | ILC_MASK, 1 , 1);
ImageList_AddIcon(hImgList, LoadIcon(g_hInstance, "IDI_MAILBOX"));
ListView_SetImageList(hWndLV, hImgList, LVSIL_SMALL);
ListView_SetExtendedListViewStyle(hWndLV, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
// ヘッダを追加 (表示しない)
lc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
lc.fmt = LVCFMT_LEFT;
lc.pszText = "メールボックス";
lc.cx = rect.right;
lc.iSubItem = 0;
lc.cchTextMax = strlen(lc.pszText);
ListView_InsertColumn(hWndLV, 0, &lc);
lc.pszText = "フォルダ名";
lc.cx = 0;
lc.iSubItem = 1;
lc.cchTextMax = strlen(lc.pszText);
ListView_InsertColumn(hWndLV, 1, &lc);
// メールボックスを列挙
THash MailBoxes;
EnumMailBox(MailBoxes);
// メールボックスを追加
int i = 0;
for (THash::iterator itr = MailBoxes.begin(); itr != MailBoxes.end(); ++itr) {
li.mask = LVIF_TEXT | LVIF_IMAGE;
li.iItem = i;
li.iImage = 0;
// 表示名
li.pszText = (char *)((*itr).second).c_str();
li.iSubItem = 0;
ListView_InsertItem(hWndLV, &li);
// メールボックスのディレクトリ名
li.pszText = (char *)((*itr).first).c_str();
li.iSubItem = 1;
ListView_SetItem(hWndLV, &li);
// 設定されているメールボックスにチェックをつける
if (g_temporary_mailbox.count((*itr).first) == 1) {
ListView_SetCheckState(hWndLV, i, 1);
}
i++;
}
}
示例7: 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;
}
示例8: ElCheapoHashing
void LSH::ElCheapoHashing(TQuoteBase *QuoteBase, TInt ShingleLen,
THash<TMd5Sig, TIntSet>& ShingleToQuoteIds) {
fprintf(stderr, "Hashing shingles the el cheapo way...\n");
TIntV QuoteIds;
QuoteBase->GetAllQuoteIds(QuoteIds);
for (int qt = 0; qt < QuoteIds.Len(); qt++) {
if (qt % 1000 == 0) {
fprintf(stderr, "%d out of %d completed\n", qt, QuoteIds.Len());
}
TQuote Q;
QuoteBase->GetQuote(QuoteIds[qt], Q);
// Put x-character (or x-word) shingles into hash table; x is specified by ShingleLen parameter
TStr QContentStr;
Q.GetParsedContentString(QContentStr);
TChA QContentChA = TChA(QContentStr);
for (int i = 0; i < QContentChA.Len() - ShingleLen + 1; i++) {
TChA ShingleChA = TChA();
for (int j = 0; j < ShingleLen; j++) {
ShingleChA.AddCh(QContentChA.GetCh(i + j));
}
TStr Shingle = TStr(ShingleChA);
const TMd5Sig ShingleMd5(Shingle);
TIntSet ShingleQuoteIds;
if (ShingleToQuoteIds.IsKey(ShingleMd5)) {
ShingleQuoteIds = ShingleToQuoteIds.GetDat(ShingleMd5);
}
ShingleQuoteIds.AddKey(QuoteIds[qt]);
ShingleToQuoteIds.AddDat(ShingleMd5, ShingleQuoteIds);
}
}
Err("Done with el cheapo hashing!\n");
}
示例9: HMACUpdate
void HMACUpdate(THash *HMAC, char *Data, int Len)
{
THash *Hash;
Hash=(THash *) HMAC->Ctx;
Hash->Update(Hash,Data,Len);
}
示例10: CompareUsingShingles
void QuoteGraph::CompareUsingShingles(THash<TMd5Sig, TIntSet>& Shingles) {
int Count = 0;
int RealCount = 0;
TVec<TMd5Sig> ShingleKeys;
Shingles.GetKeyV(ShingleKeys);
THashSet<TIntPr> EdgeCache;
for (int i = 0; i < ShingleKeys.Len(); i++) {
if (i % 100 == 0) {
Err("Processed %d out of %d shingles, count = %d\n", i, ShingleKeys.Len(), Count);
}
TIntSet Bucket;
Shingles.IsKeyGetDat(ShingleKeys[i], Bucket);
for (TIntSet::TIter Quote1 = Bucket.BegI(); Quote1 < Bucket.EndI(); Quote1++) {
TIntSet::TIter Quote1Copy = Quote1;
Quote1Copy++;
for (TIntSet::TIter Quote2 = Quote1Copy; Quote2 < Bucket.EndI(); Quote2++) {
if (!EdgeCache.IsKey(TIntPr(Quote1.GetKey(), Quote2.GetKey())) && !EdgeCache.IsKey(TIntPr(Quote2.GetKey(), Quote1.GetKey()))) {
EdgeCache.AddKey(TIntPr(Quote1.GetKey(), Quote2.GetKey()));
EdgeCache.AddKey(TIntPr(Quote2.GetKey(), Quote1.GetKey()));
RealCount++;
AddEdgeIfSimilar(Quote1.GetKey(), Quote2.GetKey());
}
}
}
int Len = Bucket.Len() * (Bucket.Len() - 1) / 2;
Count += Len;
}
fprintf(stderr, "NUMBER OF COMPARES: %d\n", Count);
fprintf(stderr, "NUMBER OF REAL COMPARES: %d\n", RealCount);
}
示例11: Err
void LogOutput::PrintClusterInformation(TDocBase *DB, TQuoteBase *QB, TClusterBase *CB, PNGraph& QGraph, TIntV& ClusterIds, TSecTm PresentTime, TIntV &OldTopClusters) {
if (!ShouldLog) return;
TStr CurDateString = PresentTime.GetDtYmdStr();
Err("Writing cluster information...\n");
// PREVIOUS RANKING SETUP
THash<TInt, TInt> OldRankings;
if (OldTopClusters.Len() > 0) {
for (int i = 0; i < OldTopClusters.Len(); i++) {
OldRankings.AddDat(OldTopClusters[i], i + 1);
}
}
TStrV RankStr;
TStr ClusterJSONDirectory = Directory + "/web/json/clusters/";
for (int i = 0; i < ClusterIds.Len(); i++) {
TStr OldRankStr;
ComputeOldRankString(OldRankings, ClusterIds[i], i+1, OldRankStr);
RankStr.Add(OldRankStr);
// JSON file for each cluster!
TPrintJson::PrintClusterJSON(QB, DB, CB, QGraph, ClusterJSONDirectory, ClusterIds[i], PresentTime);
}
Err("JSON Files for individual written!\n");
TStr JSONTableFileName = Directory + "/web/json/daily/" + CurDateString + ".json";
TPrintJson::PrintClusterTableJSON(QB, DB, CB, JSONTableFileName, ClusterIds, RankStr);
Err("JSON Files for the cluster table written!\n");
}
示例12: RewireCmtyVV
/// rewire bipartite community affiliation graphs
void TAGMUtil::RewireCmtyVV(const TVec<TIntV>& CmtyVVIn, TVec<TIntV>& CmtyVVOut, TRnd& Rnd) {
THash<TInt,TIntV> CmtyVH;
for (int i = 0; i < CmtyVVIn.Len(); i++) {
CmtyVH.AddDat(i, CmtyVVIn[i]);
}
TAGMUtil::RewireCmtyNID(CmtyVH, Rnd);
CmtyVH.GetDatV(CmtyVVOut);
}
示例13: HashBytes
int HashBytes(char **Return, char *Type, char *text, int len, int Encoding)
{
THash *Hash;
Hash=HashInit(Type);
Hash->Update(Hash, text, len);
return(Hash->Finish(Hash, Encoding, Return));
}
示例14:
void TTop2FriendNet::GetAvgSDevV(const THash<TFlt, TMom>& MomH, TFltTrV& ValAvgSDevV) {
ValAvgSDevV.Clr(false);
for (int i = 0; i < MomH.Len(); i++) {
TMom Mom=MomH[i];
Mom.Def();
ValAvgSDevV.Add(TFltTr(MomH.GetKey(i), Mom.GetMean(), Mom.GetSDev()));
}
ValAvgSDevV.Sort();
}
示例15: GetNodeMembership
void TAGMUtil::GetNodeMembership(THash<TInt,TIntSet >& NIDComVH, const THash<TInt,TIntV>& CmtyVH) {
for (THash<TInt,TIntV>::TIter HI = CmtyVH.BegI(); HI < CmtyVH.EndI(); HI++) {
int CID = HI.GetKey();
for (int j = 0; j < HI.GetDat().Len(); j++) {
int NID = HI.GetDat()[j];
NIDComVH.AddDat(NID).AddKey(CID);
}
}
}