SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
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
Main namespace for all the Snap global entities.
Definition: alg.h:1
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
Definition: dt.h:1137
int GetOutDeg() const
Returns out-degree of the current node.
Definition: graph.h:406
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:383
int GetInDeg() const
Returns in-degree of the current node.
Definition: graph.h:404
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: graph.h:412
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:416