SNAP Library, User Reference  2012-10-02 12:56:23
SNAP, a general purpose network analysis and graph mining library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
graphcounter.h
Go to the documentation of this file.
00001 #ifndef Snap_GraphCounter
00002 #define Snap_GraphCounter
00003 
00004 #include "Snap.h"
00005 
00007 // Directed 3 or 4 graph counter
00008 class TD34GraphCounter {
00009 public:
00010   TD34GraphCounter(int GraphSz); // IAssert(GraphSz==3 || GraphSz==4);
00011 public:
00012   void operator()(const PNGraph &G, const TIntV &sg);
00013   //THash<TInt,TUInt64> &GraphCounters() { return m_graphCounters; }
00014   int Len() const  { return m_graphCounters.Len(); }
00015   int GetId(const int& i) const { return m_graphCounters.GetKey(i); }
00016   uint64 GetCnt(const  int& GraphId) const { return m_graphCounters.GetDat(GraphId); }
00017   PNGraph GetGraph(const int& GraphId) const;
00018 private:
00019   THash<TInt,TInt> m_graphMaps;
00020   THash<TInt,TUInt64> m_graphCounters;
00021   int m_subGraphSize;
00022 };
00023 
00025 // Directed graph counter
00026 class TDGraphCounter{
00027 public:
00028   void operator()(const PNGraph &G, const TIntV &sg);
00029   THash<TUInt64,TUInt64> &GraphCounters() { return m_graphCounters; }
00030 private:
00031   THash<TUInt64,TUInt64> m_graphMaps;
00032   THash<TUInt64,TUInt64> m_graphCounters;
00033 };
00034 
00036 // Directed ghash graph counter
00037 class TDGHashGraphCounter{
00038 public:
00039   TDGHashGraphCounter() : m_graphs(false) {}
00040 public:
00041   void operator()(const PNGraph &G, const TIntV &sg);
00042   TGHash<TUInt64> &Graphs() { return m_graphs; }
00043 private:
00044   TGHash<TUInt64> m_graphs;
00045 };
00046 
00048 // Directed 3 graph
00049 class TD3Graph {
00050 public:
00051   static inline int getId(const PNGraph &G, const TIntV &sg);
00052 public:
00053   static int m_numOfGraphs;
00054   static int m_graphIds[];
00055 };
00056 
00058 // Directed 4 graph
00059 class TD4Graph {
00060 public:
00061   static inline int getId(const PNGraph &G, const TIntV &sg);
00062 public:
00063   static int m_numOfGraphs;
00064   static int m_graphIds[];
00065 };
00066 
00068 // TSNodeTest
00069 class TSNodeTest{
00070 public:
00071   void operator()(const PNGraph &G, const TIntV &sg) {
00072     for(int i=0; i<sg.Len(); i++) printf("%d, ", sg[i].Val);
00073     printf("\n");
00074   }
00075 };
00076 
00078 // TGraphEnumUtils
00079 class TGraphEnumUtils{
00080 private:
00081   static void GetNormalizedMap(const PNGraph &G, THash<TInt,TInt> &map);
00082   static void GetPermutations(TIntV &v, int start, TVec<TIntV> &perms);
00083 public:
00084   static inline bool IsEdge(const PNGraph &G, int SrcNId, int DstNId) {
00085     // JURE return G->GetNodeC(SrcNId).IsOutNId(DstNId);
00086     return G->IsEdge(SrcNId, DstNId, true);
00087     }
00088   static void GetEdges(uint64 graphId, int nodes, TVec<TPair<int,int> > &edges);
00089 public:
00090   static void GetNormalizedGraph(const PNGraph &G, PNGraph &nG);
00091   static void GetIndGraph(const PNGraph &G, const TIntV &sg, PNGraph &indG);
00092   static void GetGraph(uint64 graphId, int nodes, PNGraph &G);
00093 public:
00094   static void GetIsoGraphs(uint64 graphId, int nodes, TVec<PNGraph> &isoG);
00095   static void GetIsoGraphs(const PNGraph &G, TVec<PNGraph> &isoG);
00096 public:
00097   static uint64 GraphId(const PNGraph &G);
00098   static uint64 GraphId(const PNGraph &G, const TIntV &sg);
00099   static uint64 GetMinAndGraphIds(const TVec<PNGraph> &isoG, TVec<uint64> &graphIds);
00100 };
00101 
00102 #endif