SNAP Library , Developer Reference  2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
gio.cpp
Go to the documentation of this file.
00001 namespace TSnap {
00002 
00004 PNGraph LoadDyNet(const TStr& FNm) {
00005   TXmlLx XmlLx(TZipIn::IsZipFNm(FNm)?TZipIn::New(FNm):TFIn::New(FNm), xspTruncate);
00006   THashSet<TStr> NIdStr;
00007   while (XmlLx.GetSym()!=xsyEof) {
00008     if (XmlLx.Sym==xsySTag && XmlLx.TagNm=="network") {
00009       PNGraph G = TNGraph::New();
00010       XmlLx.GetSym();
00011       while (XmlLx.TagNm=="link") {
00012         TStr Str1, Val1, Str2, Val2;
00013         XmlLx.GetArg(0, Str1, Val1);  XmlLx.GetArg(1, Str2, Val2);
00014         IAssert(Str1=="source" && Str2=="target");
00015         NIdStr.AddKey(Val1); NIdStr.AddKey(Val2);
00016         const int src=NIdStr.GetKeyId(Val1);
00017         const int dst=NIdStr.GetKeyId(Val2);
00018         if (! G->IsNode(src)) { G->AddNode(src); }
00019         if (! G->IsNode(dst)) { G->AddNode(dst); }
00020         G->AddEdge(src, dst);
00021         XmlLx.GetSym();
00022       }
00023       return G;
00024     }
00025   }
00026   return PNGraph();
00027 }
00028 
00030 TVec<PNGraph> LoadDyNetGraphV(const TStr& FNm) {
00031   TXmlLx XmlLx(TZipIn::IsZipFNm(FNm)?TZipIn::New(FNm):TFIn::New(FNm), xspTruncate);
00032   TVec<PNGraph> GraphV;
00033   THashSet<TStr> NIdStr;
00034   while (XmlLx.GetSym()!=xsyEof) {
00035     if (XmlLx.Sym==xsySTag && XmlLx.TagNm=="network") {
00036       PNGraph G = TNGraph::New();
00037       GraphV.Add(G);
00038       XmlLx.GetSym();
00039       while (XmlLx.TagNm=="link") {
00040         TStr Str1, Val1, Str2, Val2;
00041         XmlLx.GetArg(0, Str1, Val1);  XmlLx.GetArg(1, Str2, Val2);
00042         IAssert(Str1=="source" && Str2=="target");
00043         NIdStr.AddKey(Val1); NIdStr.AddKey(Val2);
00044         const int src=NIdStr.GetKeyId(Val1);
00045         const int dst=NIdStr.GetKeyId(Val2);
00046         if (! G->IsNode(src)) { G->AddNode(src); }
00047         if (! G->IsNode(dst)) { G->AddNode(dst); }
00048         G->AddEdge(src, dst);
00049         XmlLx.GetSym();
00050       }
00051     }
00052   }
00053   return GraphV;
00054 }
00055 
00056 }; // namespace TSnap