Skip to content

Commit 4523993

Browse files
Correct priority list of cursors
1 parent ef73f80 commit 4523993

File tree

4 files changed

+117
-3
lines changed

4 files changed

+117
-3
lines changed

algo/src/main/java/org/neo4j/gds/triangle/intersect/GraphIntersect.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ public void intersectAll(long nodeA, IntersectionConsumer consumer) {
8686
// check the second node's degree
8787
int degreeB = degree(nodeB);
8888
if (degreeFilter.test(degreeB)) {
89-
neighboursB = cursorForNode(neighboursB, nodeB, degreeB);
89+
neighboursB = cursorForNode(
90+
neighboursB,
91+
nodeB,
92+
degreeB
93+
);
94+
9095
// find first neighbour Cb of B with id > B
9196
nodeCFromB = neighboursB.skipUntil(nodeB);
9297

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.triangle;
21+
22+
import org.junit.jupiter.api.Test;
23+
import org.neo4j.gds.Orientation;
24+
import org.neo4j.gds.api.Graph;
25+
import org.neo4j.gds.core.concurrency.Pools;
26+
import org.neo4j.gds.extension.GdlExtension;
27+
import org.neo4j.gds.extension.GdlGraph;
28+
import org.neo4j.gds.extension.Inject;
29+
30+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
31+
32+
@GdlExtension
33+
class UnionGraphTriangleCountingTest {
34+
@GdlGraph(orientation = Orientation.UNDIRECTED)
35+
static String DB_CYPHER="CREATE "+
36+
"(a0:L4)," +
37+
"(a1:L1)," +
38+
"(a2:L3)," +
39+
"(a3:L1)," +
40+
"(a5:L3)," +
41+
"(a6:L1)," +
42+
"(a7:L4)," +
43+
"(a8:L3)," +
44+
"(a9:L4)," +
45+
"(a10:L1)," +
46+
"(a11:L1)," +
47+
"(a12:L4)," +
48+
"(a13:L4)," +
49+
"(a14:L3)," +
50+
"(a15:L3)," +
51+
"(a17:L4)," +
52+
"(a18:L0)," +
53+
"(a19:L3)," +
54+
"(a20:L1)," +
55+
"(a21:L1)," +
56+
"(a22:L1)," +
57+
"(a23:L2)," +
58+
"(a24:L4)," +
59+
"(a25:L3)," +
60+
"(a26:L0)," +
61+
"(a28:L4)," +
62+
"(a29:L4)," +
63+
"(a11)-[:T1]->(a15), "+
64+
"(a0)-[:T1]->(a21), "+
65+
"(a8)-[:T2]->(a28), "+
66+
"(a12)-[:T3]->(a12), "+
67+
"(a9)-[:T4]->(a10), "+
68+
"(a3)-[:T2]->(a26), "+
69+
"(a7)-[:T0]->(a21), "+
70+
"(a11)-[:T3]->(a29), "+
71+
"(a1)-[:T3]->(a14), "+
72+
"(a14)-[:T0]->(a22), "+
73+
"(a10)-[:T1]->(a13), "+
74+
"(a3)-[:T0]->(a21), "+
75+
"(a5)-[:T3]->(a28), "+
76+
"(a10)-[:T3]->(a25), "+
77+
"(a8)-[:T1]->(a14), "+
78+
"(a11)-[:T3]->(a15), "+
79+
"(a13)-[:T2]->(a18), "+
80+
"(a13)-[:T4]->(a20), "+
81+
"(a6)-[:T1]->(a29), "+
82+
"(a12)-[:T3]->(a14), "+
83+
"(a3)-[:T2]->(a21), "+
84+
"(a2)-[:T1]->(a21), "+
85+
"(a0)-[:T0]->(a20), "+
86+
"(a24)-[:T0]->(a29), "+
87+
"(a10)-[:T4]->(a19), "+
88+
"(a0)-[:T1]->(a28), "+
89+
"(a9)-[:T4]->(a17), "+
90+
"(a15)-[:T4]->(a21), "+
91+
"(a21)-[:T1]->(a24) ";
92+
93+
@Inject
94+
Graph graph;
95+
96+
@Test
97+
void shouldWorkWithUnionGraphs() {
98+
var config=TriangleCountStreamConfigImpl.builder().concurrency(1).build();
99+
var a=IntersectingTriangleCount.create(graph,config, Pools.DEFAULT);
100+
var result=a.compute();
101+
assertThat(result.globalTriangles()).isEqualTo(0);
102+
}
103+
}

core/src/main/java/org/neo4j/gds/core/huge/CompositeAdjacencyCursor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.PriorityQueue;
3030

3131
public class CompositeAdjacencyCursor implements AdjacencyCursor {
32-
3332
private final PriorityQueue<AdjacencyCursor> cursorQueue;
3433
private final List<AdjacencyCursor> cursors;
3534

@@ -52,6 +51,10 @@ public List<AdjacencyCursor> cursors() {
5251
return cursors;
5352
}
5453

54+
void exchangeCursor(AdjacencyCursor oldCursor, AdjacencyCursor newCursor) {
55+
cursorQueue.remove(oldCursor); //remove the old cursor
56+
cursorQueue.add(newCursor); // add the new one
57+
}
5558
@Override
5659
public int size() {
5760
int sum = 0;

core/src/main/java/org/neo4j/gds/core/huge/CompositeAdjacencyList.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ public CompositeAdjacencyCursor adjacencyCursor(@Nullable AdjacencyCursor reuse,
130130
var cursor = iter.next();
131131
var newCursor = adjacencyLists.get(index).adjacencyCursor(cursor, node, fallbackValue);
132132
if (newCursor != cursor) {
133-
iter.set(adjacencyCursorWrapperFactory.create(newCursor));
133+
var newCursor1 = adjacencyCursorWrapperFactory.create(newCursor);
134+
iter.set(newCursor1);
135+
compositeReuse.exchangeCursor(cursor, newCursor1);
136+
134137
}
135138
}
136139
return compositeReuse;

0 commit comments

Comments
 (0)