2121
2222import org .jetbrains .annotations .Nullable ;
2323import org .neo4j .gds .api .AdjacencyCursor ;
24+ import org .neo4j .gds .api .AdjacencyCursorUtils ;
2425import org .neo4j .gds .api .IntersectionConsumer ;
2526import org .neo4j .gds .api .RelationshipIntersect ;
2627
@@ -67,7 +68,7 @@ private void triangles(
6768 CURSOR neighborsOfa ,
6869 IntersectionConsumer consumer
6970 ) {
70- long b = next (neighborsOfa );
71+ long b = AdjacencyCursorUtils . next (neighborsOfa );
7172 while (b != NOT_FOUND && b < a ) {
7273 var degreeOfb = degree (b );
7374 if (degreeFilter .test (degreeOfb )) {
@@ -88,23 +89,23 @@ private void triangles(
8889 ); //find all triangles involving the edge (a-b)
8990 }
9091
91- b = next (neighborsOfa );
92+ b = AdjacencyCursorUtils . next (neighborsOfa );
9293 }
9394
9495 }
9596
9697 private void triangles (long a , long b , CURSOR neighborsOfa , CURSOR neighborsOfb , IntersectionConsumer consumer ) {
97- long c = next (neighborsOfb );
98- long currentOfa = next (neighborsOfa );
98+ long c = AdjacencyCursorUtils . next (neighborsOfb );
99+ long currentOfa = AdjacencyCursorUtils . next (neighborsOfa );
99100 while (c != NOT_FOUND && currentOfa != NOT_FOUND && c < b ) {
100101 var degreeOfc = degree (c );
101102 if (degreeFilter .test (degreeOfc )) {
102- currentOfa = advance (neighborsOfa , currentOfa , c );
103+ currentOfa = AdjacencyCursorUtils . advance (neighborsOfa , currentOfa , c );
103104 //now print all triangles a-b-c (taking into consideration the parallel edges of c)
104105 checkForAndEmitTriangle (consumer , a , b , currentOfa , c );
105106
106107 }
107- c = next (neighborsOfb );
108+ c = AdjacencyCursorUtils . next (neighborsOfb );
108109 }
109110 }
110111
@@ -123,35 +124,6 @@ private void checkForAndEmitTriangle(
123124 }
124125 }
125126
126- private long advance (CURSOR adjacencyList , long start , long target ) {
127- long current = start ;
128- while (current != NOT_FOUND && current < target ) {
129- current = next (adjacencyList );
130- }
131- return current ;
132- }
133- private long next (CURSOR adjacencyList ) {
134-
135- if (!adjacencyList .hasNextVLong ()) {
136- return NOT_FOUND ;
137- }
138- var value = adjacencyList .nextVLong ();
139-
140- while (peek (adjacencyList ) == value ) {
141- adjacencyList .nextVLong ();
142- }
143-
144- return value ;
145- }
146-
147- private long peek (CURSOR adjacencyList ) {
148-
149- if (!adjacencyList .hasNextVLong ()) {
150- return NOT_FOUND ;
151- }
152-
153- return adjacencyList .peekVLong ();
154- }
155127
156128 protected abstract CURSOR cursorForNode (@ Nullable CURSOR reuse , long node , int degree );
157129
0 commit comments