Skip to content

Commit 620ad77

Browse files
committed
Use computation instead of RelationshipWeightApplier
1 parent e411ce5 commit 620ad77

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

pregel/src/main/java/org/neo4j/gds/beta/pregel/ForkJoinComputer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void release() {
103103
Supplier<ComputeContext<CONFIG>> computeContext = () -> new ComputeContext<>(
104104
graph.concurrentCopy(),
105105
config,
106-
((PregelComputation<CONFIG>) computation)::applyRelationshipWeight,
106+
computation,
107107
nodeValues,
108108
messenger,
109109
voteBits,
@@ -144,7 +144,7 @@ void release() {
144144
Supplier<BidirectionalComputeContext<CONFIG>> computeContext = () -> new BidirectionalComputeContext<>(
145145
graph.concurrentCopy(),
146146
config,
147-
((BidirectionalPregelComputation<CONFIG>) computation)::applyRelationshipWeight,
147+
computation,
148148
nodeValues,
149149
messenger,
150150
voteBits,

pregel/src/main/java/org/neo4j/gds/beta/pregel/PartitionedComputer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void release() {
149149
var computeContext = new ComputeContext<>(
150150
graph,
151151
config,
152-
((PregelComputation<CONFIG>) computation)::applyRelationshipWeight,
152+
computation,
153153
nodeValues,
154154
messenger,
155155
voteBits,
@@ -192,7 +192,7 @@ void release() {
192192
var computeContext = new BidirectionalComputeContext<>(
193193
graph,
194194
config,
195-
((BidirectionalPregelComputation<CONFIG>) computation)::applyRelationshipWeight,
195+
computation,
196196
nodeValues,
197197
messenger,
198198
voteBits,

pregel/src/main/java/org/neo4j/gds/beta/pregel/context/ComputeContext.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.commons.lang3.mutable.MutableInt;
2323
import org.neo4j.gds.api.Graph;
24+
import org.neo4j.gds.beta.pregel.BasePregelComputation;
2425
import org.neo4j.gds.beta.pregel.Messenger;
2526
import org.neo4j.gds.beta.pregel.NodeValue;
2627
import org.neo4j.gds.beta.pregel.PregelConfig;
@@ -36,24 +37,24 @@
3637
*/
3738
public class ComputeContext<CONFIG extends PregelConfig> extends NodeCentricContext<CONFIG> {
3839

39-
final RelationshipWeightApplier relationshipWeightApplier;
4040
private final HugeAtomicBitSet voteBits;
4141

4242
private final Messenger<?> messenger;
4343
private final MutableInt iteration;
4444
private final AtomicBoolean hasSendMessage;
45+
protected BasePregelComputation<CONFIG> computation;
4546

4647
public ComputeContext(Graph graph,
4748
CONFIG config,
48-
RelationshipWeightApplier relationshipWeightApplier,
49+
BasePregelComputation<CONFIG> computation,
4950
NodeValue nodeValue,
5051
Messenger<?> messenger,
5152
HugeAtomicBitSet voteBits,
5253
MutableInt iteration,
5354
AtomicBoolean hasSendMessage,
5455
ProgressTracker progressTracker) {
5556
super(graph, config, nodeValue, progressTracker);
56-
this.relationshipWeightApplier = relationshipWeightApplier;
57+
this.computation = computation;
5758
this.sendMessagesFunction = config.hasRelationshipWeightProperty()
5859
? this::sendToNeighborsWeighted
5960
: this::sendToNeighbors;
@@ -163,7 +164,7 @@ private void sendToNeighbors(long sourceNodeId, double message) {
163164

164165
private void sendToNeighborsWeighted(long sourceNodeId, double message) {
165166
graph.forEachRelationship(sourceNodeId, 1.0, (ignored, targetNodeId, weight) -> {
166-
sendTo(targetNodeId, relationshipWeightApplier.applyRelationshipWeight(message, weight));
167+
sendTo(targetNodeId, computation.applyRelationshipWeight(message, weight));
167168
return true;
168169
});
169170
}
@@ -173,19 +174,14 @@ interface SendMessagesFunction {
173174
void sendToNeighbors(long sourceNodeId, double message);
174175
}
175176

176-
@FunctionalInterface
177-
public interface RelationshipWeightApplier {
178-
double applyRelationshipWeight(double nodeValue, double relationshipWeight);
179-
}
180-
181177
public static final class BidirectionalComputeContext<CONFIG extends PregelConfig> extends ComputeContext<CONFIG> implements BidirectionalNodeCentricContext {
182178

183179
private final SendMessagesIncomingFunction sendMessagesIncomingFunction;
184180

185181
public BidirectionalComputeContext(
186182
Graph graph,
187183
CONFIG config,
188-
RelationshipWeightApplier relationshipWeightApplier,
184+
BasePregelComputation<CONFIG> computation,
189185
NodeValue nodeValue,
190186
Messenger<?> messenger,
191187
HugeAtomicBitSet voteBits,
@@ -196,7 +192,7 @@ public BidirectionalComputeContext(
196192
super(
197193
graph,
198194
config,
199-
relationshipWeightApplier,
195+
computation,
200196
nodeValue,
201197
messenger,
202198
voteBits,
@@ -226,7 +222,7 @@ private void sendToIncomingNeighbors(long sourceNodeId, double message) {
226222

227223
private void sendToIncomingNeighborsWeighted(long sourceNodeId, double message) {
228224
graph.forEachInverseRelationship(sourceNodeId, 1.0, (ignored, targetNodeId, weight) -> {
229-
sendTo(targetNodeId, relationshipWeightApplier.applyRelationshipWeight(message, weight));
225+
sendTo(targetNodeId, computation.applyRelationshipWeight(message, weight));
230226
return true;
231227
});
232228
}

0 commit comments

Comments
 (0)