1 #ifndef Snap_SubGraphEnum_h 
    2 #define Snap_SubGraphEnum_h 
   14 template<
class TGraphCounter>
 
   24                         m_nodes = (
bool *)malloc(capacity); memset(m_nodes, 0, capacity);
 
   25                         m_capacity = capacity; m_size = 0; }
 
   31                 inline void Add(
int i) { 
if(!m_nodes[i]) m_size++; m_nodes[i]=
true; }
 
   32                 inline void Remove(
int i) { m_nodes[i]=
false; m_size--; }
 
   33                 inline bool IsKey(
int i)
 const { 
return m_nodes[i]; }
 
   36                 inline bool operator[](
int i)
 const { 
return m_nodes[i]; }
 
   46                         m_v.
Gen(capacity); m_arr = (
int *) m_v.
BegI();
 
   47       for(
int i=0; i<capacity; i++) { m_arr[i]=-1; }
 
   48                         m_capacity = capacity; m_size = 0; }
 
   51                         for(
int i=0; i<
m_size; i++) { 
if(m_arr[i]==nodeId) 
return true; } 
return false; }
 
   53                 inline void Push(
int nodeId) { m_arr[
m_size]=nodeId; m_size++; }
 
   80 template <
class TGraphCounter>
 
   82         if(sg.
Size() == m_subGraphSz) { (*m_functor)(m_graph, sg.
getVec()); 
return; }
 
   84         for(
int i=0; i<ext.
Capacity(); i++) {
 
   85                 while(ext[i] == 
false) {
 
   97                 TSSet newSgNbrs = sgNbrs;
 
   98                 for(
int j=0; j<wDeg; j++) {
 
  100                         if(nbrId > vId && !sgNbrs.
IsKey(nbrId) && !sg.
Contains(nbrId)) {
 
  102                                 newSgNbrs.
Add(nbrId);
 
  106                 GetSubGraphs_recursive(sg, newSgNbrs, newExt, vId);
 
  111 template <
class TGraphCounter>
 
  115         m_subGraphSz = SubGraphSz;
 
  116         m_functor = &Functor;
 
  120                 int vId = it.GetId();
 
  121                 int vDeg = it.GetDeg();
 
  123                 TSVec sg(SubGraphSz);
 
  127                 for(
int i=0; i<vDeg; i++) {
 
  128                         int nbrId = it.GetNbrNId(i);
 
  134                 GetSubGraphs_recursive(sg, sgNbrs, ext, vId);
 
  139 template <
class TGraphCounter>
 
  141         if(sg.
Size() == m_subGraphSz) { (*m_functor)(m_graph, sg.
getVec()); 
return; }
 
  143         for(
int i=0; i<ext.
Capacity(); i++) {
 
  144                 while(ext[i] == 
false) {
 
  156                 TSSet newSgNbrs = sgNbrs;
 
  157                 for(
int j=0; j<wDeg; j++) {
 
  161                                 newSgNbrs.
Add(nbrId);
 
  165                 GetSubGraphs_recursive(sg, newSgNbrs, newExt);
 
  170 template <
class TGraphCounter>
 
  174         m_subGraphSz = SubGraphSz;
 
  175         m_functor = &Functor;
 
  181         TSVec sg(SubGraphSz);
 
  185         for(
int i=0; i<vDeg; i++) {
 
  193         GetSubGraphs_recursive(sg, sgNbrs, ext);
 
  194         printf(
"secs: %llf\n", extime.
GetSecs());
 
int GetNbrNId(const int &NodeN) const 
Returns ID of NodeN-th neighboring node. 
 
int operator[](int i) const 
 
int GetNodes() const 
Returns the number of nodes in the graph. 
 
TGraphCounter * m_functor
 
const TIntV & getVec() const 
 
void GetSubGraphs(PNGraph &Graph, int SubGraphSz, TGraphCounter &Counter)
 
bool operator[](int i) const 
 
int GetDeg() const 
Returns degree of the current node, the sum of in-degree and out-degree. 
 
void GetSubGraphs_recursive(TSVec &sg, const TSSet &sgNbrs, TSSet &ext, int vId)
 
TIter BegI() const 
Returns an iterator pointing to the first element in the vector. 
 
Node iterator. Only forward iteration (operator++) is supported. 
 
bool Contains(int nodeId) const 
 
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.