Skip to content

Commit

Permalink
- performed cosmetic code edits
Browse files Browse the repository at this point in the history
  • Loading branch information
roks committed Jul 25, 2017
1 parent 54e96a0 commit e3a33ec
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 222 deletions.
1 change: 1 addition & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ clean:
$(MAKE) clean -C graphhash
$(MAKE) clean -C infopath
$(MAKE) clean -C kcores
$(MAKE) clean -C knnjaccardsim
$(MAKE) clean -C kronem
$(MAKE) clean -C krongen
$(MAKE) clean -C kronfit
Expand Down
14 changes: 7 additions & 7 deletions snap-core/Snap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include "timenet.cpp" // time evolving networks
#include "mmnet.cpp" // multimodal networks

// table data structures and algorithms
#include "table.cpp" // table
#include "conv.cpp"
#include "numpy.cpp" // numpy conversion

// algorithms
#include "subgraph.cpp" // subgraph manipulations
#include "anf.cpp" // approximate diameter calculation
Expand All @@ -32,7 +37,8 @@
#include "flow.cpp" // network flow algorithms
#include "coreper.cpp" // core-periphery algorithms
#include "triad.cpp" // clustering coefficient and triads
#include "casc.cpp" // cascade detection^M
#include "casc.cpp" // cascade graph construction from events^M
#include "sim.cpp" // K-nearest neighbors

// graph generators
#include "ggen.cpp" // graph generators (preferential attachment, small-world, ...)
Expand All @@ -42,9 +48,3 @@
#include "ghash.cpp"
#include "statplot.cpp"
#include "gio.cpp"

// table data structures and algorithms
#include "table.cpp" // table
#include "conv.cpp"
#include "numpy.cpp" // numpy conversion
#include "sim.cpp"
15 changes: 8 additions & 7 deletions snap-core/Snap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include "timenet.h" // time evolving networks
#include "mmnet.h" // multimodal networks

// table data structures and algorithms
#include "table.h" // table
#include "conv.h" // conversion functions - table to graph
#include "numpy.h" // numpy conversion

// algorithms
#include "subgraph.h" // subgraph manipulations
#include "anf.h" // approximate diameter calculation
Expand All @@ -38,6 +43,9 @@
#include "flow.h" // network flow algorithms
#include "coreper.h" // core-periphery algorithms
#include "randwalk.h" // Personalized PageRank
#include "casc.h" // cascade graph construction from events^M
#include "sim.h" // K-nearest neighbors


// graph generators
#include "ggen.h" // graph generators (preferential attachment, small-world, ...)
Expand All @@ -47,11 +55,4 @@
#include "gviz.h"
#include "ghash.h"
#include "statplot.h"

// table data structures and algorithms
#include "table.h" // table
#include "conv.h" // conversion functions - table to graph
#include "numpy.h" // numpy conversion
#include "casc.h" // cascade detection^M
#include "sim.h"
#endif // SNAP_H
40 changes: 40 additions & 0 deletions snap-core/doc/network.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Range of NodeN: 0 <= NodeN < GetOutDeg().
Range of NodeN: 0 <= NodeN < GetNbrDeg().
///

/// TNodeNet::LoadShM(TShMIn& ShMIn)
The object is read-only. It does not support operations that edit the edge
vectors of nodes or perform illegal operations on the NodeH, EdgeH
(deletion or swapping keys).
///

/// TNodeNet::AddNode (int NId = -1)
Returns the ID of the node being added.
If NId is -1, node ID is automatically assigned.
Expand Down Expand Up @@ -70,6 +76,12 @@ Range of NodeN: 0 <= NodeN < GetOutDeg().
Range of NodeN: 0 <= NodeN < GetNbrDeg().
///

/// TNodeEDatNet::LoadShM(TShMIn& ShMIn)
The object is read-only. It does not support operations that edit the edge
vectors of nodes or perform illegal operations on the NodeH, EdgeH
(deletion or swapping keys).
///

/// TNodeEDatNet::AddNode (int NId = -1)
Returns the ID of the node being added.
If NId is -1, node ID is automatically assigned.
Expand Down Expand Up @@ -142,6 +154,16 @@ Range of NodeN: 0 <= NodeN < GetOutDeg().
Range of NodeN: 0 <= NodeN < GetNbrDeg().
///

/// TNodeEdgeNet::New()
Call with: TPt <TNodeEdgeNet<TNodeData, TEdgeData> > Net = TNodeEdgeNet<TNodeData, TEdgeData>::New().
///

/// TNodeEdgeNet::LoadShM(TShMIn& ShMIn)
The object is read-only. It does not support operations that edit the edge
vectors of nodes or perform illegal operations on the NodeH, EdgeH
(deletion or swapping keys).
///

/// TNodeEdgeNet::AddNode (int NId = -1)
Returns the ID of the node being added.
If NId is -1, node ID is automatically assigned.
Expand Down Expand Up @@ -228,6 +250,12 @@ Range of NodeN: 0 <= NodeN < GetNbrDeg().
/// TNEANet::New
Call: PNEANet Net = TNEANet::New(Nodes, Edges).
///

/// TNEANet::LoadShM(TShMIn& ShMIn)
The object is read-only. It does not support operations that edit the edge
vectors of nodes or perform illegal operations on the NodeH, EdgeH
(deletion or swapping keys).
///

/// TNEANet::AddNode (int NId = -1)
Returns the ID of the node being added.
Expand Down Expand Up @@ -340,6 +368,12 @@ GetInNId(), GetOutNId() and GetNbrNId() all give the same output.
Call: PUndirNet Net = TUndirNet::New(Nodes, Edges).
///

/// TUndirNet::LoadShM(TShMIn& ShMIn)
The object is read-only. It does not support operations that edit the edge
vectors of nodes or perform illegal operations on the NodeH, EdgeH
(deletion or swapping keys).
///

/// TUndirNet::AddNode (int NId = -1)
Returns the ID of the node being added.
If NId is -1, node ID is automatically assigned.
Expand Down Expand Up @@ -458,6 +492,12 @@ Range of NodeN: 0 <= NodeN < GetNbrDeg().
Call: PDirNet Net = TDirNet::New(Nodes, Edges).
///

/// TDirNet::LoadShM(TShMIn& ShMIn)
The object is read-only. It does not support operations that edit the edge
vectors of nodes or perform illegal operations on the NodeH, EdgeH
(deletion or swapping keys).
///

/// TDirNet::AddNode (int NId = -1)
Returns the ID of the node being added.
If NId is -1, node ID is automatically assigned.
Expand Down
6 changes: 3 additions & 3 deletions snap-core/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ class TNGraph {
TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
void LoadGraphShM(TShMIn& ShMIn) {
MxNId = TInt(ShMIn);
TLoadTNodeInitializer Fn;
NodeH.LoadShM(ShMIn, Fn);
MxNId = TInt(ShMIn);
TLoadTNodeInitializer Fn;
NodeH.LoadShM(ShMIn, Fn);
}

public:
Expand Down
37 changes: 18 additions & 19 deletions snap-core/mmnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,23 +647,23 @@ int TCrossNet::DelAttrE(const TStr& attr) {
}

void TMMNet::LoadNetworkShM(TShMIn& ShMIn) {
MxModeId = TInt(ShMIn);
MxCrossNetId = TInt(ShMIn);
TModeNetInit Fm;
TModeNetH.LoadShM(ShMIn, Fm);
TCrossNetInit Fc;
TCrossNetH.LoadShM(ShMIn, Fc);
ModeIdToNameH.LoadShM(ShMIn);
ModeNameToIdH.LoadShM(ShMIn);
CrossIdToNameH.LoadShM(ShMIn);
CrossNameToIdH.LoadShM(ShMIn);
for (THash<TInt, TModeNet>::TIter it = TModeNetH.BegI(); it < TModeNetH.EndI(); it++) {
it.GetDat().SetParentPointer(this);
}
for (THash<TInt, TCrossNet>::TIter it = TCrossNetH.BegI(); it < TCrossNetH.EndI(); it++) {
it.GetDat().SetParentPointer(this);
}
MxModeId = TInt(ShMIn);
MxCrossNetId = TInt(ShMIn);
TModeNetInit Fm;
TModeNetH.LoadShM(ShMIn, Fm);
TCrossNetInit Fc;
TCrossNetH.LoadShM(ShMIn, Fc);
ModeIdToNameH.LoadShM(ShMIn);
ModeNameToIdH.LoadShM(ShMIn);
CrossIdToNameH.LoadShM(ShMIn);
CrossNameToIdH.LoadShM(ShMIn);
for (THash<TInt, TModeNet>::TIter it = TModeNetH.BegI(); it < TModeNetH.EndI(); it++) {
it.GetDat().SetParentPointer(this);
}
for (THash<TInt, TCrossNet>::TIter it = TCrossNetH.BegI(); it < TCrossNetH.EndI(); it++) {
it.GetDat().SetParentPointer(this);
}
}

int TMMNet::AddModeNet(const TStr& ModeName) {
if (ModeNameToIdH.IsKey(ModeName)) {
Expand Down Expand Up @@ -1113,10 +1113,9 @@ PNEANet TMMNet::ToNetwork2(TIntV& CrossNetTypes, TIntStrPrVH& NodeAttrMap, THash
}

void TMMNet::GetPartitionRanges(TIntPrV& Partitions, const TInt& NumPartitions, const TInt& MxLen) const {
if (MxLen <= NumPartitions){
if (MxLen <= NumPartitions) {
Partitions.Add(TIntPr(0,MxLen));
}
else{
} else {
TInt PartitionSize = MxLen/NumPartitions;
TInt CurrStart = 0;
bool done = false;
Expand Down
6 changes: 3 additions & 3 deletions snap-core/mmnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TModeNet : public TNEANet {
/// Saves the graph to a (binary) stream SOut.
void Save(TSOut& SOut) const {
TNEANet::Save(SOut); ModeId.Save(SOut); NeighborTypes.Save(SOut); }
/// Load graph from shared memory
/// Loads graph from shared memory.
void LoadShM(TShMIn & ShMIn) {
TNEANet::LoadNetworkShM(ShMIn);
ModeId = TInt(ShMIn);
Expand Down Expand Up @@ -337,7 +337,7 @@ class TCrossNet {
void Save(TSOut& SOut) const { CrossH.Save(SOut); MxEId.Save(SOut); Mode1.Save(SOut); Mode2.Save(SOut); IsDirect.Save(SOut); CrossNetId.Save(SOut);
KeyToIndexTypeE.Save(SOut); IntDefaultsE.Save(SOut); StrDefaultsE.Save(SOut); FltDefaultsE.Save(SOut); VecOfIntVecsE.Save(SOut);
VecOfStrVecsE.Save(SOut); VecOfFltVecsE.Save(SOut); }
/// Load network from shared memory stream
/// Loads network from shared memory stream.
void LoadShM(TShMIn& ShMIn) {
CrossH.LoadShM(ShMIn);
MxEId = TInt(ShMIn);
Expand Down Expand Up @@ -606,7 +606,7 @@ class TMMNet {
CrossNameToIdH.Save(SOut); }
/// Loads the TMMNet from binary stream.
static PMMNet Load(TSIn& SIn) { return PMMNet(new TMMNet(SIn)); }
/// Load network from mmapped shared memory.
/// Loads network from mmapped shared memory.
static PMMNet LoadShM(TShMIn& ShMIn) {
TMMNet* Network = new TMMNet();
Network->LoadNetworkShM(ShMIn);
Expand Down
116 changes: 58 additions & 58 deletions snap-core/network.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
/////////////////////////////////////////////////
void TNEANet::LoadNetworkShM(TShMIn& ShMIn) {
MxNId = TInt(ShMIn);
MxEId = TInt(ShMIn);
MxNId = TInt(ShMIn);
MxEId = TInt(ShMIn);

LoadTNodeFunctor NodeFn;
NodeH.LoadShM(ShMIn, NodeFn);
LoadTNodeFunctor NodeFn;
NodeH.LoadShM(ShMIn, NodeFn);

EdgeH.LoadShM(ShMIn);
KeyToIndexTypeN.LoadShM(ShMIn);
KeyToIndexTypeE.LoadShM(ShMIn);
EdgeH.LoadShM(ShMIn);
KeyToIndexTypeN.LoadShM(ShMIn);
KeyToIndexTypeE.LoadShM(ShMIn);

KeyToDenseN.LoadShM(ShMIn);
KeyToDenseE.LoadShM(ShMIn);

IntDefaultsN.LoadShM(ShMIn);
IntDefaultsE.LoadShM(ShMIn);
StrDefaultsN.LoadShM(ShMIn);
StrDefaultsE.LoadShM(ShMIn);
FltDefaultsE.LoadShM(ShMIn);
FltDefaultsE.LoadShM(ShMIn);

LoadVecFunctor vec_fn;
VecOfIntVecsN.LoadShM(ShMIn, vec_fn);
VecOfIntVecsE.LoadShM(ShMIn, vec_fn);
/* Strings and floats are complicated, so don't optimize on these */
VecOfStrVecsN.Load(ShMIn);
VecOfStrVecsE.Load(ShMIn);
VecOfFltVecsN.Load(ShMIn);
VecOfFltVecsE.Load(ShMIn);

LoadVecOfVecFunctor vec_of_vec_fn;
VecOfIntVecVecsN.LoadShM(ShMIn, vec_of_vec_fn);
VecOfIntVecVecsE.LoadShM(ShMIn, vec_of_vec_fn);

LoadHashOfVecFunctor hash_of_vec_fn;
VecOfIntHashVecsN.LoadShM(ShMIn, hash_of_vec_fn);
VecOfIntHashVecsE.LoadShM(ShMIn, hash_of_vec_fn);

/* Attributes are complicated so load these straight */
SAttrN.Load(ShMIn);
SAttrE.Load(ShMIn);
}
KeyToDenseN.LoadShM(ShMIn);
KeyToDenseE.LoadShM(ShMIn);

IntDefaultsN.LoadShM(ShMIn);
IntDefaultsE.LoadShM(ShMIn);
StrDefaultsN.LoadShM(ShMIn);
StrDefaultsE.LoadShM(ShMIn);
FltDefaultsE.LoadShM(ShMIn);
FltDefaultsE.LoadShM(ShMIn);

LoadVecFunctor vec_fn;
VecOfIntVecsN.LoadShM(ShMIn, vec_fn);
VecOfIntVecsE.LoadShM(ShMIn, vec_fn);
/* Strings and floats are complicated, so don't optimize on these */
VecOfStrVecsN.Load(ShMIn);
VecOfStrVecsE.Load(ShMIn);
VecOfFltVecsN.Load(ShMIn);
VecOfFltVecsE.Load(ShMIn);

LoadVecOfVecFunctor vec_of_vec_fn;
VecOfIntVecVecsN.LoadShM(ShMIn, vec_of_vec_fn);
VecOfIntVecVecsE.LoadShM(ShMIn, vec_of_vec_fn);

LoadHashOfVecFunctor hash_of_vec_fn;
VecOfIntHashVecsN.LoadShM(ShMIn, hash_of_vec_fn);
VecOfIntHashVecsE.LoadShM(ShMIn, hash_of_vec_fn);

/* Attributes are complicated so load these straight */
SAttrN.Load(ShMIn);
SAttrE.Load(ShMIn);
}

// Attribute Node Edge Network
bool TNEANet::HasFlag(const TGraphFlag& Flag) const {
Expand Down Expand Up @@ -1285,17 +1285,17 @@ int TNEANet::AddIntAttrN(const TStr& attr, TInt defaultValue){
int TNEANet::AddIntVAttrN(const TStr& attr, TBool UseDense){
TInt CurrLen;
if (UseDense) {
CurrLen = VecOfIntVecVecsN.Len();
KeyToIndexTypeN.AddDat(attr, TIntPr(IntVType, CurrLen));
KeyToDenseN.AddDat(attr, true);
TVec<TIntV> NewVec = TVec<TIntV>(MxNId);
VecOfIntVecVecsN.Add(NewVec);
CurrLen = VecOfIntVecVecsN.Len();
KeyToIndexTypeN.AddDat(attr, TIntPr(IntVType, CurrLen));
KeyToDenseN.AddDat(attr, true);
TVec<TIntV> NewVec = TVec<TIntV>(MxNId);
VecOfIntVecVecsN.Add(NewVec);
} else {
CurrLen = VecOfIntHashVecsN.Len();
KeyToIndexTypeN.AddDat(attr, TIntPr(IntVType, CurrLen));
KeyToDenseN.AddDat(attr, false);
THash<TInt, TIntV> NewHash;
VecOfIntHashVecsN.Add(NewHash);
CurrLen = VecOfIntHashVecsN.Len();
KeyToIndexTypeN.AddDat(attr, TIntPr(IntVType, CurrLen));
KeyToDenseN.AddDat(attr, false);
THash<TInt, TIntV> NewHash;
VecOfIntHashVecsN.Add(NewHash);
}
return 0;
}
Expand Down Expand Up @@ -1362,17 +1362,17 @@ int TNEANet::AddIntAttrE(const TStr& attr, TInt defaultValue){
int TNEANet::AddIntVAttrE(const TStr& attr, TBool UseDense){
TInt CurrLen;
if (UseDense) {
CurrLen = VecOfIntVecVecsE.Len();
KeyToIndexTypeE.AddDat(attr, TIntPr(IntVType, CurrLen));
KeyToDenseE.AddDat(attr, true);
TVec<TIntV> NewVec = TVec<TIntV>(MxEId);
VecOfIntVecVecsE.Add(NewVec);
CurrLen = VecOfIntVecVecsE.Len();
KeyToIndexTypeE.AddDat(attr, TIntPr(IntVType, CurrLen));
KeyToDenseE.AddDat(attr, true);
TVec<TIntV> NewVec = TVec<TIntV>(MxEId);
VecOfIntVecVecsE.Add(NewVec);
} else {
CurrLen = VecOfIntHashVecsE.Len();
KeyToIndexTypeE.AddDat(attr, TIntPr(IntVType, CurrLen));
KeyToDenseE.AddDat(attr, false);
THash<TInt, TIntV> NewHash;
VecOfIntHashVecsE.Add(NewHash);
CurrLen = VecOfIntHashVecsE.Len();
KeyToIndexTypeE.AddDat(attr, TIntPr(IntVType, CurrLen));
KeyToDenseE.AddDat(attr, false);
THash<TInt, TIntV> NewHash;
VecOfIntHashVecsE.Add(NewHash);
}
return 0;
}
Expand Down
Loading

0 comments on commit e3a33ec

Please sign in to comment.