use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.
the class RingsDetection method compute0.
@Override
public void compute0(ComputationContext context, Vertex vertex) {
vertex.value(new IdListList());
if (vertex.edges().size() == 0) {
return;
}
// Init path
Id id = vertex.id();
IdList path = new IdList();
path.add(id);
for (Edge edge : vertex.edges()) {
/*
* Only send path to vertex whose id is larger than
* or equals current vertex id
*/
if (id.compareTo(edge.targetId()) <= 0) {
context.sendMessage(edge.targetId(), path);
}
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.
the class TriangleCount method compute0.
@Override
public void compute0(ComputationContext context, Vertex vertex) {
IdList selfId = new IdList();
selfId.add(vertex.id());
context.sendMessageToAllEdgesIf(vertex, selfId, (ids, targetId) -> {
return !ids.get(0).equals(targetId);
});
vertex.value(new TriangleCountValue());
}
use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.
the class RingsDetectionWithFilter method compute.
@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<RingsDetectionMessage> messages) {
boolean halt = true;
if (this.filter.filter(vertex)) {
Id vertexId = vertex.id();
while (messages.hasNext()) {
halt = false;
RingsDetectionMessage message = messages.next();
IdList path = message.path();
if (vertexId.equals(path.get(0))) {
// Use the smallest vertex record ring
boolean isMin = true;
for (int i = 0; i < path.size(); i++) {
Id pathVertexValue = path.get(i);
if (vertexId.compareTo(pathVertexValue) > 0) {
isMin = false;
break;
}
}
if (isMin) {
path.add(vertexId);
IdListList value = vertex.value();
value.add(path.copy());
}
} else {
boolean contains = false;
// Drop sequence if path contains this vertex
for (int i = 0; i < path.size(); i++) {
Id pathVertexValue = path.get(i);
if (pathVertexValue.equals(vertex.id())) {
contains = true;
break;
}
}
if (!contains) {
path.add(vertex.id());
for (Edge edge : vertex.edges()) {
if (this.filter.filter(edge, message)) {
message.walkEdgeProp(edge.properties());
context.sendMessage(edge.targetId(), message);
}
}
}
}
}
}
if (halt) {
vertex.inactivate();
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.
the class ComputeMessageRecvPartitionTest method addTwentyDuplicateIdValueListMessageBuffer.
private static void addTwentyDuplicateIdValueListMessageBuffer(Consumer<ManagedBuffer> consumer) throws IOException {
for (long i = 0L; i < 10L; i++) {
for (int j = 0; j < 2; j++) {
Id id = BytesId.of(i);
IdList message = new IdList();
message.add(id);
ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
}
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.
the class MessageInputTest method addMessages.
private static void addMessages(Consumer<ManagedBuffer> consumer) throws IOException {
Random random = new Random(1);
for (long i = 0L; i < 200L; i++) {
int count = random.nextInt(5);
for (int j = 0; j < count; j++) {
Id id = BytesId.of(random.nextInt(200));
IdList message = new IdList();
message.add(id);
ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
}
}
}
Aggregations