本文整理汇总了C++中THash::GetDat方法的典型用法代码示例。如果您正苦于以下问题:C++ THash::GetDat方法的具体用法?C++ THash::GetDat怎么用?C++ THash::GetDat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类THash
的用法示例。
在下文中一共展示了THash::GetDat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Count
void TTable::Count(TStr CountColName, TStr Col){
if(!ColTypeMap.IsKey(Col)){TExcept::Throw("no such column " + Col);}
TIntV CntCol(NumRows);
switch(GetColType(Col)){
case INT:{
THash<TInt,TIntV> T; // can't really estimate the size of T for constructor hinting
TIntV& Column = IntCols[GetColIdx(Col)];
GroupByIntCol(Col, T, TIntV(0), true);
for(TRowIterator it = BegRI(); it < EndRI(); it++){
CntCol[it.GetRowIdx()] = T.GetDat(Column[it.GetRowIdx()]).Len();
}
break;
}
case FLT:{
THash<TFlt,TIntV> T;
TFltV& Column = FltCols[GetColIdx(Col)];
GroupByFltCol(Col, T, TIntV(0), true);
for(TRowIterator it = BegRI(); it < EndRI(); it++){
CntCol[it.GetRowIdx()] = T.GetDat(Column[it.GetRowIdx()]).Len();
}
break;
}
case STR:{
THash<TStr,TIntV> T;
GroupByStrCol(Col, T, TIntV(0), true);
for(TRowIterator it = BegRI(); it < EndRI(); it++){
CntCol[it.GetRowIdx()] = T.GetDat(GetStrVal(Col, it.GetRowIdx())).Len();
}
}
}
// add count column
IntCols.Add(CntCol);
AddSchemaCol(CountColName, INT);
ColTypeMap.AddDat(CountColName, TPair<TYPE,TInt>(INT, IntCols.Len()-1));
}
示例2: 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");
}
示例3: SaveBipartiteGephi
/// save bipartite community affiliation into gexf file
void TAGMUtil::SaveBipartiteGephi(const TStr& OutFNm, const TIntV& NIDV, const TVec<TIntV>& CmtyVV, const double MaxSz, const double MinSz, const TIntStrH& NIDNameH, const THash<TInt, TIntTr>& NIDColorH, const THash<TInt, TIntTr>& CIDColorH ) {
/// Plot bipartite graph
if (CmtyVV.Len() == 0) {
return;
}
double NXMin = 0.1, YMin = 0.1, NXMax = 250.00, YMax = 30.0;
double CXMin = 0.3 * NXMax, CXMax = 0.7 * NXMax;
double CStep = (CXMax - CXMin) / (double) CmtyVV.Len(), NStep = (NXMax - NXMin) / (double) NIDV.Len();
THash<TInt,TIntV> NIDComVH;
TAGMUtil::GetNodeMembership(NIDComVH, CmtyVV);
FILE* F = fopen(OutFNm.CStr(), "wt");
fprintf(F, "<?xml version='1.0' encoding='UTF-8'?>\n");
fprintf(F, "<gexf xmlns='http://www.gexf.net/1.2draft' xmlns:viz='http://www.gexf.net/1.1draft/viz' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd' version='1.2'>\n");
fprintf(F, "\t<graph mode='static' defaultedgetype='directed'>\n");
fprintf(F, "\t\t<nodes>\n");
for (int c = 0; c < CmtyVV.Len(); c++) {
int CID = c;
double XPos = c * CStep + CXMin;
TIntTr Color = CIDColorH.IsKey(CID)? CIDColorH.GetDat(CID) : TIntTr(120, 120, 120);
fprintf(F, "\t\t\t<node id='C%d' label='C%d'>\n", CID, CID);
fprintf(F, "\t\t\t\t<viz:color r='%d' g='%d' b='%d'/>\n", Color.Val1.Val, Color.Val2.Val, Color.Val3.Val);
fprintf(F, "\t\t\t\t<viz:size value='%.3f'/>\n", MaxSz);
fprintf(F, "\t\t\t\t<viz:shape value='square'/>\n");
fprintf(F, "\t\t\t\t<viz:position x='%f' y='%f' z='0.0'/>\n", XPos, YMax);
fprintf(F, "\t\t\t</node>\n");
}
for (int u = 0; u < NIDV.Len(); u++) {
int NID = NIDV[u];
TStr Label = NIDNameH.IsKey(NID)? NIDNameH.GetDat(NID): "";
double Size = MinSz;
double XPos = NXMin + u * NStep;
TIntTr Color = NIDColorH.IsKey(NID)? NIDColorH.GetDat(NID) : TIntTr(120, 120, 120);
double Alpha = 1.0;
fprintf(F, "\t\t\t<node id='%d' label='%s'>\n", NID, Label.CStr());
fprintf(F, "\t\t\t\t<viz:color r='%d' g='%d' b='%d' a='%.1f'/>\n", Color.Val1.Val, Color.Val2.Val, Color.Val3.Val, Alpha);
fprintf(F, "\t\t\t\t<viz:size value='%.3f'/>\n", Size);
fprintf(F, "\t\t\t\t<viz:shape value='square'/>\n");
fprintf(F, "\t\t\t\t<viz:position x='%f' y='%f' z='0.0'/>\n", XPos, YMin);
fprintf(F, "\t\t\t</node>\n");
}
fprintf(F, "\t\t</nodes>\n");
fprintf(F, "\t\t<edges>\n");
int EID = 0;
for (int u = 0; u < NIDV.Len(); u++) {
int NID = NIDV[u];
if (NIDComVH.IsKey(NID)) {
for (int c = 0; c < NIDComVH.GetDat(NID).Len(); c++) {
int CID = NIDComVH.GetDat(NID)[c];
fprintf(F, "\t\t\t<edge id='%d' source='C%d' target='%d'/>\n", EID++, CID, NID);
}
}
}
fprintf(F, "\t\t</edges>\n");
fprintf(F, "\t</graph>\n");
fprintf(F, "</gexf>\n");
}
示例4: FindMxQEdge
TFltIntIntTr FindMxQEdge() {
while (true) {
if (MxQHeap.Empty()) { break; }
const TFltIntIntTr TopQ = MxQHeap.PopHeap();
if (! CmtyQH.IsKey(TopQ.Val2) || ! CmtyQH.IsKey(TopQ.Val3)) { continue; }
if (TopQ.Val1!=CmtyQH.GetDat(TopQ.Val2).GetMxQ() && TopQ.Val1!=CmtyQH.GetDat(TopQ.Val3).GetMxQ()) { continue; }
return TopQ;
}
return TFltIntIntTr(-1, -1, -1);
}
示例5: MinHash
// YES I COPIED AND PASTED CODE my section leader would be so ashamed :D
void LSH::MinHash(THash<TMd5Sig, TIntSet>& ShingleToQuoteIds,
TVec<THash<TIntV, TIntSet> >& SignatureBandBuckets) {
TRnd RandomGenerator; // TODO: make this "more random" by incorporating time
for (int i = 0; i < NumBands; ++i) {
THash < TInt, TIntV > Inverted; // (QuoteID, QuoteSignatureForBand)
THash < TIntV, TIntSet > BandBuckets; // (BandSignature, QuoteIDs)
for (int j = 0; j < BandSize; ++j) {
// Create new signature
TVec < TMd5Sig > Signature;
ShingleToQuoteIds.GetKeyV(Signature);
Signature.Shuffle(RandomGenerator);
// Place in bucket - not very efficient
int SigLen = Signature.Len();
for (int k = 0; k < SigLen; ++k) {
TIntSet CurSet = ShingleToQuoteIds.GetDat(Signature[k]);
for (TIntSet::TIter l = CurSet.BegI(); l < CurSet.EndI(); l++) {
TInt Key = l.GetKey();
if (Inverted.IsKey(Key)) {
TIntV CurSignature = Inverted.GetDat(Key);
if (CurSignature.Len() <= j) {
CurSignature.Add(k);
Inverted.AddDat(Key, CurSignature);
}
} else {
TIntV NewSignature;
NewSignature.Add(k);
Inverted.AddDat(Key, NewSignature);
}
}
}
}
TIntV InvertedKeys;
Inverted.GetKeyV(InvertedKeys);
TInt InvertedLen = InvertedKeys.Len();
for (int k = 0; k < InvertedLen; ++k) {
TIntSet Bucket;
TIntV Signature = Inverted.GetDat(InvertedKeys[k]);
if (BandBuckets.IsKey(Signature)) {
Bucket = BandBuckets.GetDat(Signature);
}
Bucket.AddKey(InvertedKeys[k]);
BandBuckets.AddDat(Signature, Bucket);
}
SignatureBandBuckets.Add(BandBuckets);
Err("%d out of %d band signatures computed\n", i + 1, NumBands);
}
Err("Minhash step complete!\n");
}
示例6: main
int main(int argc, char *argv[]) {
TStr BaseString = "/lfs/1/tmp/curis/week/QBDB.bin";
TFIn BaseFile(BaseString);
TQuoteBase *QB = new TQuoteBase;
TDocBase *DB = new TDocBase;
QB->Load(BaseFile);
DB->Load(BaseFile);
TIntV QuoteIds;
QB->GetAllQuoteIds(QuoteIds);
int NumQuotes = QuoteIds.Len();
THash<TInt, TStrSet> PeakCounts;
for (int i = 0; i < NumQuotes; i++) {
TQuote CurQuote;
if (QB->GetQuote(QuoteIds[i], CurQuote)) {
TVec<TSecTm> Peaks;
CurQuote.GetPeaks(DB, Peaks);
TStr QuoteString;
CurQuote.GetParsedContentString(QuoteString);
TStrSet StringSet;
if (PeakCounts.IsKey(Peaks.Len())) {
StringSet = PeakCounts.GetDat(Peaks.Len());
}
StringSet.AddKey(QuoteString);
PeakCounts.AddDat(Peaks.Len(), StringSet);
}
}
TIntV PeakCountKeys;
PeakCounts.GetKeyV(PeakCountKeys);
PeakCountKeys.Sort(true);
for (int i = 0; i < PeakCountKeys.Len(); i++) {
TStrSet CurSet = PeakCounts.GetDat(PeakCountKeys[i]);
if (CurSet.Len() > 0) {
printf("QUOTES WITH %d PEAKS\n", PeakCountKeys[i].Val);
printf("#########################################\n");
THashSet<TStr> StringSet = PeakCounts.GetDat(PeakCountKeys[i]);
for (THashSet<TStr>::TIter l = StringSet.BegI(); l < StringSet.EndI(); l++) {
printf("%s\n", l.GetKey().CStr());
}
printf("\n");
}
}
delete QB;
delete DB;
return 0;
}
示例7: 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");
}
示例8: HashShinglesOfClusters
/// 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");
}
示例9: Connect
void TSockSys::Connect(const uint64& SockId, const PSockHost& SockHost, const int& PortN) {
// make sure it's a valid socket
IAssert(IsSock(SockId));
uv_tcp_t* SockHnd = SockIdToHndH.GetDat(SockId);
// make sure we got a valid socket host
IAssert(SockHost->IsOk());
// get connection handle
uv_connect_t* ConnectHnd = (uv_connect_t*)malloc(sizeof(uv_connect_t));
// special handling for v4 and v6
int ResCd = 0;
if (SockHost->IsIpv4()) {
// get address
struct sockaddr_in Addr = uv_ip4_addr(SockHost->GetIpNum().CStr(), PortN);
// establish connection
ResCd = uv_tcp_connect(ConnectHnd, SockHnd, Addr, TSockSys::OnConnect);
} else if (SockHost->IsIpv6()) {
// get address
struct sockaddr_in6 Addr = uv_ip6_addr(SockHost->GetIpNum().CStr(), PortN);
// establish connection
ResCd = uv_tcp_connect6(ConnectHnd, SockHnd, Addr, TSockSys::OnConnect);
}
// check for errors
if (ResCd != 0) {
// cleanup first
free(SockHnd);
// and throw exception
throw TExcept::New("SockSys.Connect: Error establishing socket connection: " + SockSys.GetLastErr());
}
}
示例10: 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;
}
示例11: BuildGraphTopology
// wrong reading of string attributes
void TTable::BuildGraphTopology(PNEAGraph& Graph, THash<TFlt, TInt>& FSrNodeMap, THash<TFlt, TInt>& FDsNodeMap) {
TYPE SrCT = GetColType(SrcCol);
TInt SrIdx = GetColIdx(SrcCol);
TYPE DsCT = GetColType(DstCol);
TInt DsIdx = GetColIdx(DstCol);
TInt SrcCnt = 0;
TInt DstCnt = 0;
for(TRowIterator RowI = BegRI(); RowI < EndRI(); RowI++) {
if (SrCT == INT && DsCT == INT) {
Graph->AddNode(IntCols[SrIdx][RowI.GetRowIdx()]);
Graph->AddNode(IntCols[DsIdx][RowI.GetRowIdx()]);
Graph->AddEdge(IntCols[SrIdx][RowI.GetRowIdx()], IntCols[DsIdx][RowI.GetRowIdx()], RowI.GetRowIdx());
} else if (SrCT == INT && DsCT == FLT) {
Graph->AddNode(IntCols[SrIdx][RowI.GetRowIdx()]);
TFlt val = FltCols[DsIdx][RowI.GetRowIdx()];
if (!FDsNodeMap.IsKey(val)) {
FDsNodeMap.AddDat(val, DstCnt++);
}
Graph->AddNode(FDsNodeMap.GetDat(val));
Graph->AddEdge(IntCols[SrIdx][RowI.GetRowIdx()], FDsNodeMap.GetDat(val));
} else if (SrCT == INT && DsCT == STR) {
Graph->AddNode(IntCols[SrIdx][RowI.GetRowIdx()]);
Graph->AddNode(StrColMaps[DsIdx][RowI.GetRowIdx()]);
Graph->AddEdge(IntCols[SrIdx][RowI.GetRowIdx()], StrColMaps[DsIdx][RowI.GetRowIdx()], RowI.GetRowIdx());
} else if (SrCT == FLT && DsCT == INT) {
Graph->AddNode(IntCols[DsIdx][RowI.GetRowIdx()]);
TFlt val = FltCols[SrIdx][RowI.GetRowIdx()];
if (!FSrNodeMap.IsKey(val)) {
FSrNodeMap.AddDat(val, SrcCnt++);
}
Graph->AddNode(FSrNodeMap.GetDat(val));
Graph->AddEdge(FSrNodeMap.GetDat(val), IntCols[SrIdx][RowI.GetRowIdx()], RowI.GetRowIdx());
} else if (SrCT == FLT && DsCT == STR) {
Graph->AddNode(StrColMaps[DsIdx][RowI.GetRowIdx()]);
TFlt val = FltCols[SrIdx][RowI.GetRowIdx()];
if (!FSrNodeMap.IsKey(val)) {
FSrNodeMap.AddDat(val, SrcCnt++);
}
Graph->AddNode(FSrNodeMap.GetDat(val));
Graph->AddEdge(FSrNodeMap.GetDat(val), IntCols[SrIdx][RowI.GetRowIdx()], RowI.GetRowIdx());
} else if (SrCT == FLT && DsCT == FLT) {
TFlt val = FltCols[SrIdx][RowI.GetRowIdx()];
if (!FSrNodeMap.IsKey(val)) {
FSrNodeMap.AddDat(val, SrcCnt++);
}
Graph->AddNode(FSrNodeMap.GetDat(val));
val = FltCols[DsIdx][RowI.GetRowIdx()];
if (!FDsNodeMap.IsKey(val)) {
FDsNodeMap.AddDat(val, DstCnt++);
}
Graph->AddNode(FDsNodeMap.GetDat(val));
Graph->AddEdge(FSrNodeMap.GetDat(val), FDsNodeMap.GetDat(val), RowI.GetRowIdx());
}
}
}
示例12: GetNId
TInt TTable::GetNId(TStr Col, TInt RowIdx, THash<TFlt, TInt>& FSrNodeMap, THash<TFlt, TInt>& FDsNodeMap) {
TYPE CT = GetColType(Col);
TInt Idx = GetColIdx(Col);
if (CT == INT) {
return IntCols[RowIdx][Idx];
} else if (CT == FLT) {
if (Col == SrcCol) {
return FSrNodeMap.GetDat(FltCols[Idx][RowIdx]);
} else if (Col == DstCol) {
return FDsNodeMap.GetDat(FltCols[Idx][RowIdx]);
} else {
TExcept::Throw("Column " + Col + " is not source node or destination column");
}
} else {
return StrColMaps[RowIdx][Idx]();
}
return 0;
}
示例13: DelSock
void TSockSys::DelSock(const uint64& SockId) {
if (Active) {
uv_tcp_t* SockHnd = SockIdToHndH.GetDat(SockId);
// close the handle
uv_close((uv_handle_t*)SockHnd, TSockSys::OnClose);
// mark it's under closing so we don't handle it again in the destructor
ClosedSockIdSet.AddKey(SockId);
}
}
示例14: DelIfSockTimer
void TSockSys::DelIfSockTimer(const uint64& SockId) {
if (SockIdToTimerHndH.IsKey(SockId)) {
// get timer handle
uv_timer_t* TimerHnd = SockIdToTimerHndH.GetDat(SockId);
// stop the timer
uv_timer_stop(TimerHnd);
// remove shortcuts
SockIdToTimerHndH.DelKey(SockId);
TimerHndToSockIdH.DelKey((uint64)TimerHnd);
// remove shortcuts
}
}
示例15: GetFlagStr
TStr GetFlagStr(const TGraphFlag& GraphFlag) {
static THash<TInt, TStr> GraphFlagToStrH;
if (GraphFlagToStrH.Empty()) {
GraphFlagToStrH.AddDat((int) gfUndef, "Undef");
GraphFlagToStrH.AddDat((int) gfDirected, "Directed");
GraphFlagToStrH.AddDat((int) gfMultiGraph, "MultiGraph");
GraphFlagToStrH.AddDat((int) gfNodeDat, "NodeDat");
GraphFlagToStrH.AddDat((int) gfEdgeDat, "EdgeDat");
GraphFlagToStrH.AddDat((int) gfSources, "Sources");
}
return GraphFlagToStrH.GetDat((int) GraphFlag);
}