SNAP Library 2.0, Developer Reference  2013-05-13 16:33:57
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
TSimpleGraph Class Reference

Simple directed/undirected graph defined by its edges. More...

#include <ghash.h>

Collaboration diagram for TSimpleGraph:

List of all members.

Public Member Functions

 TSimpleGraph ()
 TSimpleGraph (const TIntPrV &GEdgeV)
bool operator== (const TSimpleGraph &Graph) const
bool operator< (const TSimpleGraph &Graph) const
int GetEdges () const
void AddEdge (const int &SrcNId, const int &DstNId)
bool Join (const TSimpleGraph &G1, const TSimpleGraph &G2)
TIntPrVGetEdgeV ()
TIntPrVoperator() ()
void Dump (const TStr &Desc=TStr()) const

Private Attributes

TIntPrV EdgeV

Detailed Description

Simple directed/undirected graph defined by its edges.

Definition at line 539 of file ghash.h.


Constructor & Destructor Documentation

Definition at line 543 of file ghash.h.

{ }
TSimpleGraph::TSimpleGraph ( const TIntPrV GEdgeV) [inline]

Definition at line 544 of file ghash.h.

: EdgeV(GEdgeV) { }

Member Function Documentation

void TSimpleGraph::AddEdge ( const int &  SrcNId,
const int &  DstNId 
) [inline]

Definition at line 549 of file ghash.h.

References TVec< TVal, TSizeTy >::Add(), and EdgeV.

Referenced by TSubGraphsEnum::RecurBfs().

{ EdgeV.Add(TIntPr(SrcNId, DstNId)); }

Here is the call graph for this function:

Here is the caller graph for this function:

void TSimpleGraph::Dump ( const TStr Desc = TStr()) const

Definition at line 274 of file ghash.cpp.

References TStr::CStr(), EdgeV, TStr::Empty(), and TVec< TVal, TSizeTy >::Len().

Referenced by TSubGraphsEnum::Gen2Graphs().

                                              {
  if (! Desc.Empty()) printf("%s. Edges: %d\n", Desc.CStr(), EdgeV.Len());
  else printf("Edges: %d\n", EdgeV.Len());
  for (int i = 0; i < EdgeV.Len(); i++) {
    printf("\t%d\t%d\n", EdgeV[i].Val1(), EdgeV[i].Val2());
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int TSimpleGraph::GetEdges ( ) const [inline]

Definition at line 548 of file ghash.h.

References EdgeV, and TVec< TVal, TSizeTy >::Len().

Referenced by Join().

{ return EdgeV.Len(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 551 of file ghash.h.

References EdgeV.

Referenced by TSubGraphsEnum::EnumSubGraphs(), and TSubGraphsEnum::Gen2Graphs().

{ return EdgeV; }

Here is the caller graph for this function:

bool TSimpleGraph::Join ( const TSimpleGraph G1,
const TSimpleGraph G2 
)

Definition at line 233 of file ghash.cpp.

References EdgeV, TVec< TVal, TSizeTy >::Gen(), GetEdges(), IAssert, and TVec< TVal, TSizeTy >::Last().

Referenced by TSubGraphsEnum::EnumSubGraphs().

                                                                      {
  const int Edges1 = G1.GetEdges();
  const int Edges2 = G2.GetEdges();
  const TIntPrV& EdgeV1 = G1.EdgeV;
  const TIntPrV& EdgeV2 = G2.EdgeV;
  const int MxEdges = Edges1+1;
  if (GetEdges() != MxEdges) EdgeV.Gen(MxEdges);
  IAssert(Edges1 == Edges2);

  int e=0, g1=0, g2=0;
  while (g1 < Edges1 && g2 < Edges2) {
    if (e == MxEdges) return false;
    if (abs(g1 - g2) > 1) return false;
    if (EdgeV1[g1] == EdgeV2[g2]) { e++;  g1++;  g2++; }
    else if (EdgeV1[g1] < EdgeV2[g2]) { e++;  g1++; }
    else { e++;  g2++; }
  }

  e=0; g1=0; g2=0;
  while (g1 < Edges1 && g2 < Edges2) {
    if (EdgeV1[g1] == EdgeV2[g2]) {
      EdgeV[e] = EdgeV1[g1];  e++;  g1++;  g2++; }
    else if (EdgeV1[g1] < EdgeV2[g2]) {
      EdgeV[e] = EdgeV1[g1];  e++;  g1++; }
    else {
      EdgeV[e] = EdgeV2[g2];  e++;  g2++; }
  }
  if (g1 == Edges1 && g2 == Edges2 && e == MxEdges) return true;
  if (e+1 == MxEdges) {
    if (g1+1 == Edges1 && g2 == Edges2) {
      EdgeV[e] = EdgeV1.Last();
      return true;
    }
    if (g1 == Edges1 && g2+1 == Edges2) {
      EdgeV[e] = EdgeV2.Last();
      return true;
    }
  }
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

TIntPrV& TSimpleGraph::operator() ( ) [inline]

Definition at line 552 of file ghash.h.

References EdgeV.

{ return EdgeV; }
bool TSimpleGraph::operator< ( const TSimpleGraph Graph) const [inline]

Definition at line 546 of file ghash.h.

References EdgeV.

{ return EdgeV < Graph.EdgeV; }
bool TSimpleGraph::operator== ( const TSimpleGraph Graph) const [inline]

Definition at line 545 of file ghash.h.

References EdgeV.

{ return EdgeV == Graph.EdgeV; }

Member Data Documentation

Definition at line 541 of file ghash.h.

Referenced by AddEdge(), Dump(), GetEdges(), GetEdgeV(), Join(), operator()(), operator<(), and operator==().


The documentation for this class was generated from the following files: