SNAP Library 3.0, User Reference  2016-07-20 17:56:49
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 void GetMergeSortedV(TIntV& NeighbourV, TNGraph::TNodeI NI) {
4  int j = 0;
5  int k = 0;
6  int prev = -1;
7  int indeg = NI.GetInDeg();
8  int outdeg = NI.GetOutDeg();
9  if (indeg > 0 && outdeg > 0) {
10  int v1 = NI.GetInNId(j);
11  int v2 = NI.GetOutNId(k);
12  while (1) {
13  if (v1 <= v2) {
14  if (prev != v1) {
15  NeighbourV.Add(v1);
16  prev = v1;
17  }
18  j += 1;
19  if (j >= indeg) {
20  break;
21  }
22  v1 = NI.GetInNId(j);
23  } else {
24  if (prev != v2) {
25  NeighbourV.Add(v2);
26  prev = v2;
27  }
28  k += 1;
29  if (k >= outdeg) {
30  break;
31  }
32  v2 = NI.GetOutNId(k);
33  }
34  }
35  }
36  while (j < indeg) {
37  int v = NI.GetInNId(j);
38  if (prev != v) {
39  NeighbourV.Add(v);
40  prev = v;
41  }
42  j += 1;
43  }
44  while (k < outdeg) {
45  int v = NI.GetOutNId(k);
46  if (prev != v) {
47  NeighbourV.Add(v);
48  prev = v;
49  }
50  k += 1;
51  }
52 }
53 
54 int GetCommon(TIntV& A, TIntV& B) {
55  int i, j;
56  int ret = 0;
57  int alen, blen;
58  int d;
59  TInt ai;
60 
61  alen = A.Len();
62  blen = B.Len();
63  i = 0;
64  j = 0;
65  if (i >= alen || j >= blen) {
66  return ret;
67  }
68 
69  while (1) {
70  d = A[i] - B[j];
71  if (d < 0) {
72  i++;
73  if (i >= alen) {
74  break;
75  }
76  } else if (d > 0) {
77  j++;
78  if (j >= blen) {
79  break;
80  }
81  } else {
82  ret++;
83  i++;
84  if (i >= alen) {
85  break;
86  }
87  j++;
88  if (j >= blen) {
89  break;
90  }
91  }
92  }
93  return ret;
94 }
95 
96 } // namespace TSnap
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void GetMergeSortedV(TIntV &NeighbourV, TNGraph::TNodeI NI)
Definition: triad.cpp:3
Definition: dt.h:1044
int GetOutDeg() const
Returns out-degree of the current node.
Definition: graph.h:362
int GetCommon(TIntV &A, TIntV &B)
Returns the number of common elements in two sorted TInt vectors.
Definition: triad.cpp:54
Node iterator. Only forward iteration (operator++) is supported.
Definition: graph.h:339
int GetInDeg() const
Returns in-degree of the current node.
Definition: graph.h:360
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: graph.h:368
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: graph.h:372