SNAP Library 3.0, Developer Reference
2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
Graph Hash Table. More...
#include <ghash.h>
Public Types | |
typedef THash< TGraphKey, TDat > ::TIter | TIter |
Public Member Functions | |
TGHash (const bool &HashTrees, const int &MaxIsoCheck=8, const int &MaxSvdGraph=500) | |
Default contructor. More... | |
TGHash (TSIn &SIn) | |
void | Save (TSOut &SOut) const |
const TDat & | operator[] (const int &KeyId) const |
Accesses the data at hash table position index KeyId. More... | |
TDat & | operator[] (const int &KeyId) |
Accesses the data at hash table position index KeyId. More... | |
const TDat & | operator() (const TGraphKey &Key) const |
Accesses the data of graph-key Key. More... | |
TDat & | operator() (const TGraphKey &Key) |
Accesses the data of graph-key Key. More... | |
TIter | BegI () const |
Returns iterator to the first element of the hash table. More... | |
TIter | EndI () const |
Returns iterator to one past the last element of the hash table. More... | |
TIter | GetI (const int &KeyId) const |
Returns iterator to a key at position index KeyId. More... | |
bool | HashTrees () const |
Returns whether the hash table only hashes trees and not arbitrary directed graphs. More... | |
void | Gen (const int &ExpectVals) |
Initializes the hash table for the expected number of keys ExpectVals. More... | |
void | Clr (const bool &DoDel=true, const int &NoDelLim=-1) |
Removes all the elements from the hash table. More... | |
bool | Empty () const |
Tests whether the hash table is empty. More... | |
int | Len () const |
Returns the number of keys in the hash table. More... | |
int | GetPorts () const |
Returns the number of ports in the hash table. More... | |
bool | IsAutoSize () const |
Tests whether the hash table automatically adjusts the number of ports based on the number of keys. More... | |
int | GetMxKeyIds () const |
Returns the maximum key Id of any element in the hash table. More... | |
bool | IsKeyIdEqKeyN () const |
Tests whether there are any unused slots in the hash table. More... | |
int | AddKey (const PNGraph &Graph) |
Adds a key Graph to the table and returns its KeyId. More... | |
TDat & | AddDat (const PNGraph &Graph) |
Adds a key Graph to the table and returns its data value. More... | |
TDat & | AddDat (const PNGraph &Graph, const TDat &Dat) |
Adds a key Graph to the table, sets its data value to value of Dat and returns Dat. More... | |
bool | IsKey (const PNGraph &Graph) const |
Test whether Graph is an existing key in the hash table. More... | |
int | GetKeyId (const PNGraph &Graph) const |
Returns the KeyId (position index) of key Graph. More... | |
const TDat & | GetDat (const PNGraph &Graph) const |
Returns the data associated with key Graph. More... | |
TDat & | GetDat (const PNGraph &Graph) |
Returns the data associated with key Graph. More... | |
const TGraphKey & | GetKey (const int &KeyId) const |
Returns the GraphKey with position index KeyId. More... | |
int | GetKeyId (const TGraphKey &Key) const |
Returns the KeyId for a given Key. More... | |
bool | IsKey (const TGraphKey &Key) const |
Tests whether a given Key exists in the hash table. More... | |
bool | IsKey (const TGraphKey &Key, int &KeyId) const |
Tests whether a given Key exists in the hash table. More... | |
bool | IsKeyId (const int &KeyId) const |
Tests whether there exists a key at given position index KeyId. More... | |
const TDat & | GetDat (const TGraphKey &Key) const |
Returns data with a given graph Key. More... | |
TDat & | GetDat (const TGraphKey &Key) |
Returns data with a given graph Key. More... | |
const TDat & | GetDatId (const int &KeyId) const |
Returns data at a given position index KeyId. More... | |
TDat & | GetDatId (const int &KeyId) |
Returns data at a given position index KeyId. More... | |
void | GetKeyDat (const int &KeyId, TGraphKey &Key, TDat &Dat) const |
Returns Key and Data at a given position index KeyId. More... | |
bool | IsKeyGetDat (const TGraphKey &Key, TDat &Dat) const |
Test whether Key exists and sets its data to Dat. More... | |
bool | GetNodeMap (const PNGraph &Graph, TIntPrV &NodeMapV) const |
Returns the mapping of node Ids of the Graph to those of the graph-key in the hash table. More... | |
bool | GetNodeMap (const PNGraph &Graph, TIntPrV &NodeMapV, int &KeyId) const |
Returns the mapping of node Ids of the Graph to those of the graph-key in the hash table and the Graph KeyId. More... | |
int | FFirstKeyId () const |
Finds first KeyId. More... | |
bool | FNextKeyId (int &KeyId) const |
Finds next KeyId. More... | |
void | GetKeyV (TVec< TGraphKey > &KeyV) const |
Returns a vector of keys stored in the hash table. More... | |
void | GetDatV (TVec< TDat > &DatV) const |
Returns a vector of data elements stored in the hash table. More... | |
void | GetKeyIdByDat (TIntV &KeyIdV, const bool &Asc=true) const |
Returns a vector of KeyIds of hash table elements sorted by their data value. More... | |
void | GetKeyIdByGSz (TIntV &KeyIdV, const bool &Asc=true) const |
Returns a vector of KeyIds of hash table elements sorted by their graph size. More... | |
void | GetKeyDatPrV (TVec< TPair< TGraphKey, TDat > > &KeyDatPrV) const |
Returns a vector of pairs (Key, Data) elements stored in the hash table. More... | |
void | GetDatKeyPrV (TVec< TPair< TDat, TGraphKey > > &DatKeyPrV) const |
Returns a vector of pairs (Data, Key) elements stored in the hash table. More... | |
void | Defrag () |
Removes unused slots from the hash table. More... | |
void | Pack () |
Frees the unused memory by the hash table. More... | |
void | DrawGViz (const int &KeyId, const TStr &OutFNmPref, const TStr &OutputType="gif", TStr Desc="") const |
Saves a given graph with key Id KeyId in DOT format and calls the GraphViz to draw it. More... | |
void | DrawGViz (const TIntV &KeyIdV, const TStr &OutFNmPref, const TStr &OutputType="gif") const |
Saves a set of graphs with key Ids KeyIdV in DOT format and calls the GraphViz to draw them. More... | |
void | SaveTxt (const TStr &OutFNm, const TStr &Desc, const TStr &DatColNm, const bool &SortByKeyVal=true) const |
Saves all graphs stored in the hash table into a text file. More... | |
void | SaveDetailTxt (const TStr &OutFNm, const TStr &Desc, const TStr &DatColNm) const |
Saves all graphs stored in the hash table into a text file and include additional information. More... | |
Private Member Functions | |
void | InitPermutations () |
int | IsGetKeyId (const PNGraph &Graph) const |
int | IsGetKeyId (const PNGraph &Graph, TGraphKey &GKey) const |
int | IsGetKeyId (const PNGraph &Graph, TGraphKey &GKey, TIntPrV &NodeMap) const |
Private Attributes | |
TInt | MxIsoCheck |
TInt | MxSvdGraph |
THash< TInt, TVec< TIntV > > | GSzToPermH |
TBool | HashOnlyTrees |
THash< TGraphKey, TDat > | GraphH |
Graph Hash Table.
Keys in this hash table are (little) directed graphs. The class is useful for counting frequencies of small subgraphs or information cascades. For small graphs with less than MxIsoCheck nodes the class performs exact isomorphism checking. For graphs with less than MxSvdGraph nodes the class performs approximate isomorphism checking by comparing a numeric SVD-based signatures of two graphs. For graphs with more than MxSvdGraph nodes the class performs approximate isorphism checking by comparing only the signature based on simple graph statistics. For hashing trees (tree is encoded as a directed graph where children point to the parent) the class always performs exact isomorphism testing.
TGHash< TDat >::TGHash | ( | const bool & | HashTrees, |
const int & | MaxIsoCheck = 8 , |
||
const int & | MaxSvdGraph = 500 |
||
) |
Default contructor.
For hashing trees and not general graphs, set HashTrees=true. A tree is a directed graph where children point to the parent. In this case exact isomorphism checking will be performed. For hashing general graphs, set HashTrees=false. MaxIsoCheck is the maximum number of nodes for which we perform brute force exact isomorphism check. For larger graph the isomorphism test is only approximate.
Definition at line 304 of file ghash.h.
References TGHash< TDat >::InitPermutations().
Definition at line 312 of file ghash.h.
References TGHash< TDat >::HashOnlyTrees, and TGHash< TDat >::InitPermutations().
Adds a key Graph to the table and returns its data value.
If the key already exists the function returns the data associated with that existing key.
Definition at line 177 of file ghash.h.
Referenced by TDGHashGraphCounter::operator()().
|
inline |
Adds a key Graph to the table, sets its data value to value of Dat and returns Dat.
If the key already exists the function sets the data value of that existing key.
Definition at line 181 of file ghash.h.
Adds a key Graph to the table and returns its KeyId.
KeyId is position index in the hash table. If the key already exists the function returns KeyId of that existing key.
Definition at line 327 of file ghash.h.
References Fail, TGraphKey::GetNodes(), TSnap::GetTreeSig(), IAssert, TGraphKey::IsIsomorph(), TSnap::IsTree(), TGraphKey::SetVariant(), TGraphKey::TakeGraph(), and TGraphKey::TakeSig().
Referenced by TGHash< TUInt64 >::AddDat().
|
inline |
Removes all the elements from the hash table.
If DoDel=true the data structure will free the memory, otherwise the object stays initialized (which makes subsequent insertion of keys much faster).
Definition at line 154 of file ghash.h.
|
inline |
void TGHash< TDat >::DrawGViz | ( | const int & | KeyId, |
const TStr & | OutFNmPref, | ||
const TStr & | OutputType = "gif" , |
||
TStr | Desc = "" |
||
) | const |
Saves a given graph with key Id KeyId in DOT format and calls the GraphViz to draw it.
Definition at line 480 of file ghash.h.
References TStr::CStr(), TStr::Fmt(), TGraphKey::GetEdges(), TGraphKey::GetNodes(), TSnap::TSnapDetail::GVizDoLayout(), gvlDot, IAssert, and TGraphKey::SaveGViz().
void TGHash< TDat >::DrawGViz | ( | const TIntV & | KeyIdV, |
const TStr & | OutFNmPref, | ||
const TStr & | OutputType = "gif" |
||
) | const |
Saves a set of graphs with key Ids KeyIdV in DOT format and calls the GraphViz to draw them.
Definition at line 489 of file ghash.h.
References TStr::CStr(), TStr::Fmt(), TGraphKey::GetEdges(), TGraphKey::GetNodes(), TExeTm::GetTmStr(), TSnap::TSnapDetail::GVizDoLayout(), gvlDot, IAssert, TVec< TVal, TSizeTy >::Len(), and TGraphKey::SaveGViz().
|
inline |
|
inline |
|
inline |
|
inline |
Returns the data associated with key Graph.
If the key does not exist the function aborts.
Definition at line 192 of file ghash.h.
Referenced by TDGHashGraphCounter::operator()().
Returns the data associated with key Graph.
If the key does not exist the function aborts.
Definition at line 196 of file ghash.h.
|
inline |
|
inline |
|
inline |
Returns a vector of pairs (Data, Key) elements stored in the hash table.
Definition at line 267 of file ghash.h.
|
inline |
|
inline |
Returns a vector of pairs (Key, Data) elements stored in the hash table.
Definition at line 265 of file ghash.h.
Returns the KeyId (position index) of key Graph.
If the key does not exist, the function returns -1.
Definition at line 188 of file ghash.h.
Referenced by TGHash< TUInt64 >::GetDat().
void TGHash< TDat >::GetKeyIdByDat | ( | TIntV & | KeyIdV, |
const bool & | Asc = true |
||
) | const |
Returns a vector of KeyIds of hash table elements sorted by their data value.
Asc=true: sort in ascending order, otherwise in descending order.
Definition at line 454 of file ghash.h.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Gen(), and TVec< TVal, TSizeTy >::Sort().
void TGHash< TDat >::GetKeyIdByGSz | ( | TIntV & | KeyIdV, |
const bool & | Asc = true |
||
) | const |
Returns a vector of KeyIds of hash table elements sorted by their graph size.
Asc=true: sort in ascending order, otherwise in descending order. Graph size is the number of nodes and edges.
Definition at line 467 of file ghash.h.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Gen(), and TVec< TVal, TSizeTy >::Sort().
|
inline |
bool TGHash< TDat >::GetNodeMap | ( | const PNGraph & | Graph, |
TIntPrV & | NodeMapV | ||
) | const |
Returns the mapping of node Ids of the Graph to those of the graph-key in the hash table.
The function assumes the Graph exists as a key in the table. Otherwise it returns false.
Definition at line 407 of file ghash.h.
bool TGHash< TDat >::GetNodeMap | ( | const PNGraph & | Graph, |
TIntPrV & | NodeMapV, | ||
int & | KeyId | ||
) | const |
Returns the mapping of node Ids of the Graph to those of the graph-key in the hash table and the Graph KeyId.
The function assumes the Graph exists as a key in the table. Otherwise it returns false.
Definition at line 413 of file ghash.h.
References TVec< TVal, TSizeTy >::Add(), TNGraph::BegNI(), TVec< TVal, TSizeTy >::Clr(), Fail, TVec< TVal, TSizeTy >::GetDat(), TNGraph::TNodeI::GetId(), TNGraph::GetNodes(), TSnap::GetTreeSig(), IAssert, TGraphKey::IsIsomorph(), TSnap::IsTree(), TVec< TVal, TSizeTy >::Len(), TGraphKey::SetVariant(), TGraphKey::TakeGraph(), and TGraphKey::TakeSig().
|
inline |
|
inline |
|
private |
Definition at line 287 of file ghash.h.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::NextPerm(), and TVec< TVal, TSizeTy >::Pack().
Referenced by TGHash< TDat >::TGHash().
|
inline |
Definition at line 370 of file ghash.h.
Referenced by TGHash< TUInt64 >::GetKeyId(), and TGHash< TUInt64 >::IsKey().
|
private |
Definition at line 376 of file ghash.h.
References Fail, TGraphKey::GetNodes(), TSnap::GetTreeSig(), IAssert, TGraphKey::IsIsomorph(), TSnap::IsTree(), TGraphKey::SetVariant(), TGraphKey::TakeGraph(), and TGraphKey::TakeSig().
|
private |
Test whether Graph is an existing key in the hash table.
Definition at line 184 of file ghash.h.
Referenced by TDGHashGraphCounter::operator()().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void TGHash< TDat >::SaveDetailTxt | ( | const TStr & | OutFNm, |
const TStr & | Desc, | ||
const TStr & | DatColNm | ||
) | const |
Saves all graphs stored in the hash table into a text file and include additional information.
Definition at line 523 of file ghash.h.
References TStr::CStr(), and TVec< TVal, TSizeTy >::Len().
void TGHash< TDat >::SaveTxt | ( | const TStr & | OutFNm, |
const TStr & | Desc, | ||
const TStr & | DatColNm, | ||
const bool & | SortByKeyVal = true |
||
) | const |
Saves all graphs stored in the hash table into a text file.
Definition at line 505 of file ghash.h.
References TStr::CStr(), TGraphKey::GetEdges(), TGraphKey::GetNodes(), and TVec< TVal, TSizeTy >::Len().
Definition at line 111 of file ghash.h.
Referenced by TGHash< TUInt64 >::AddDat(), TGHash< TUInt64 >::BegI(), TGHash< TUInt64 >::Clr(), TGHash< TUInt64 >::Defrag(), TGHash< TUInt64 >::Empty(), TGHash< TUInt64 >::EndI(), TGHash< TUInt64 >::FNextKeyId(), TGHash< TUInt64 >::Gen(), TGHash< TUInt64 >::GetDat(), TGHash< TUInt64 >::GetDatId(), TGHash< TUInt64 >::GetDatKeyPrV(), TGHash< TUInt64 >::GetDatV(), TGHash< TUInt64 >::GetI(), TGHash< TUInt64 >::GetKey(), TGHash< TUInt64 >::GetKeyDat(), TGHash< TUInt64 >::GetKeyDatPrV(), TGHash< TUInt64 >::GetKeyId(), TGHash< TUInt64 >::GetKeyV(), TGHash< TUInt64 >::GetMxKeyIds(), TGHash< TUInt64 >::GetPorts(), TGHash< TUInt64 >::IsAutoSize(), TGHash< TUInt64 >::IsKey(), TGHash< TUInt64 >::IsKeyGetDat(), TGHash< TUInt64 >::IsKeyId(), TGHash< TUInt64 >::IsKeyIdEqKeyN(), TGHash< TUInt64 >::Len(), TGHash< TUInt64 >::operator()(), TGHash< TUInt64 >::operator[](), and TGHash< TUInt64 >::Pack().
Definition at line 110 of file ghash.h.
Referenced by TGHash< TUInt64 >::HashTrees(), and TGHash< TDat >::TGHash().