SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
triad.cpp
Go to the documentation of this file.
1 namespace TSnap {
2 
3 #if 0
4 // OP RS 2016/09/12 commented out, fails to compile for Snap.py on Windows.
5 // This function is obsolete, since it is TNGraph specific.
6 // Use MergeNbrs() instead.
7 void GetMergeSortedV(TIntV& NeighbourV, TNGraph::TNodeI NI) {
8  int j = 0;
9  int k = 0;
10  int prev = -1;
11  int indeg = NI.GetInDeg();
12  int outdeg = NI.GetOutDeg();
13  if (indeg > 0 && outdeg > 0) {
14  int v1 = NI.GetInNId(j);
15  int v2 = NI.GetOutNId(k);
16  while (1) {
17  if (v1 <= v2) {
18  if (prev != v1) {
19  NeighbourV.Add(v1);
20  prev = v1;
21  }
22  j += 1;
23  if (j >= indeg) {
24  break;
25  }
26  v1 = NI.GetInNId(j);
27  } else {
28  if (prev != v2) {
29  NeighbourV.Add(v2);
30  prev = v2;
31  }
32  k += 1;
33  if (k >= outdeg) {
34  break;
35  }
36  v2 = NI.GetOutNId(k);
37  }
38  }
39  }
40  while (j < indeg) {
41  int v = NI.GetInNId(j);
42  if (prev != v) {
43  NeighbourV.Add(v);
44  prev = v;
45  }
46  j += 1;
47  }
48  while (k < outdeg) {
49  int v = NI.GetOutNId(k);
50  if (prev != v) {
51  NeighbourV.Add(v);
52  prev = v;
53  }
54  k += 1;
55  }
56 }
57 #endif
58 
59 int GetCommon(TIntV& A, TIntV& B) {
60  int i, j;
61  int ret = 0;
62  int alen, blen;
63  int d;
64  TInt ai;
65 
66  alen = A.Len();
67  blen = B.Len();
68  i = 0;
69  j = 0;
70  if (i >= alen || j >= blen) {
71  return ret;
72  }
73 
74  while (1) {
75  d = A[i] - B[j];
76  if (d < 0) {
77  i++;
78  if (i >= alen) {
79  break;
80  }
81  } else if (d > 0) {
82  j++;
83  if (j >= blen) {
84  break;
85  }
86  } else {
87  ret++;
88  i++;
89  if (i >= alen) {
90  break;
91  }
92  j++;
93  if (j >= blen) {
94  break;
95  }
96  }
97  }
98  return ret;
99 }
100 
101 } // namespace TSnap
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
Definition: dt.h:1134
int GetOutDeg() const
Returns out-degree of the current node.
Definition: graph.h:402
int GetCommon(TIntV &A, TIntV &B)
Returns the number of common elements in two sorted TInt vectors.
Definition: triad.cpp:59
Node iterator. Only forward iteration (operator++) is supported.
Definition: graph.h:379
int GetInDeg() const
Returns in-degree of the current node.
Definition: graph.h:400
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: graph.h:408
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: graph.h:412