Skip to content
Permalink
Browse files
Use BytesId unify the Id classes (#78)
  • Loading branch information
Linary committed Aug 11, 2021
1 parent 9a14659 commit 5cde5201742b38f67289073591a1a67c1cd2a28f
Showing 56 changed files with 945 additions and 1,433 deletions.
@@ -24,15 +24,14 @@
import com.baidu.hugegraph.computer.core.combiner.Combiner;
import com.baidu.hugegraph.computer.core.graph.edge.Edge;
import com.baidu.hugegraph.computer.core.graph.id.Id;
import com.baidu.hugegraph.computer.core.graph.value.IdValue;
import com.baidu.hugegraph.computer.core.graph.vertex.Vertex;
import com.baidu.hugegraph.computer.core.worker.Computation;
import com.baidu.hugegraph.computer.core.worker.ComputationContext;

/**
* Wcc stands for Weak Connected Component.
*/
public class Wcc implements Computation<IdValue> {
public class Wcc implements Computation<Id> {

@Override
public String name() {
@@ -41,7 +40,7 @@ public String name() {

@Override
public String category() {
return "wcc";
return "community";
}

@Override
@@ -52,20 +51,19 @@ public void compute0(ComputationContext context, Vertex vertex) {
min = edge.targetId();
}
}
IdValue value = min.idValue();
Id value = min;
vertex.value(value);
vertex.inactivate();
context.sendMessageToAllEdgesIf(vertex, value, (result, target) -> {
return result.compareTo(target.idValue()) < 0;
return result.compareTo(target) < 0;
});
}

@Override
public void compute(ComputationContext context, Vertex vertex,
Iterator<IdValue> messages) {
IdValue message = Combiner.combineAll(context.combiner(),
messages);
IdValue value = vertex.value();
Iterator<Id> messages) {
Id message = Combiner.combineAll(context.combiner(), messages);
Id value = vertex.value();
if (value.compareTo(message) > 0) {
vertex.value(message);
context.sendMessageToAllEdges(vertex, message);
@@ -24,7 +24,7 @@
import com.baidu.hugegraph.computer.algorithm.AlgorithmParams;
import com.baidu.hugegraph.computer.core.combiner.ValueMinCombiner;
import com.baidu.hugegraph.computer.core.config.ComputerOptions;
import com.baidu.hugegraph.computer.core.graph.value.IdValue;
import com.baidu.hugegraph.computer.core.graph.id.BytesId;
import com.baidu.hugegraph.computer.core.output.LimitedLogOutput;

public class WccParams implements AlgorithmParams {
@@ -34,9 +34,9 @@ public void setAlgorithmParameters(Map<String, String> params) {
this.setIfAbsent(params, ComputerOptions.WORKER_COMPUTATION_CLASS,
Wcc.class.getName());
this.setIfAbsent(params, ComputerOptions.ALGORITHM_RESULT_CLASS,
IdValue.class.getName());
BytesId.class.getName());
this.setIfAbsent(params, ComputerOptions.ALGORITHM_MESSAGE_CLASS,
IdValue.class.getName());
BytesId.class.getName());
this.setIfAbsent(params, ComputerOptions.WORKER_COMBINER_CLASS,
ValueMinCombiner.class.getName());
this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS,
@@ -19,19 +19,13 @@

package com.baidu.hugegraph.computer.core.graph.id;

import com.baidu.hugegraph.computer.core.graph.value.IdValue;
import com.baidu.hugegraph.computer.core.io.Readable;
import com.baidu.hugegraph.computer.core.io.Writable;
import com.baidu.hugegraph.computer.core.graph.value.Value;

public interface Id extends Readable, Writable, Comparable<Id> {
public interface Id extends Value<Id> {

IdType type();
IdType idType();

IdValue idValue();
int length();

Object asObject();

long asLong();

byte[] asBytes();
}
@@ -21,12 +21,13 @@

import java.io.IOException;

import com.baidu.hugegraph.computer.core.graph.id.Id;
import com.baidu.hugegraph.computer.core.io.RandomAccessInput;
import com.baidu.hugegraph.computer.core.io.RandomAccessOutput;

public class IdValueList extends ListValue<IdValue> {
public class IdList extends ListValue<Id> {

public IdValueList() {
public IdList() {
super(ValueType.ID_VALUE);
}

@@ -46,10 +47,10 @@ public void write(RandomAccessOutput out) throws IOException {
}

@Override
public IdValueList copy() {
IdValueList values = new IdValueList();
for (IdValue value : this.values()) {
values.add(value);
public IdList copy() {
IdList values = new IdList();
for (Id value : this.values()) {
values.add((Id) value.copy());
}
return values;
}
@@ -24,9 +24,9 @@
import com.baidu.hugegraph.computer.core.io.RandomAccessInput;
import com.baidu.hugegraph.computer.core.io.RandomAccessOutput;

public class IdValueListList extends ListValue<IdValueList> {
public class IdListList extends ListValue<IdList> {

public IdValueListList() {
public IdListList() {
super(ValueType.ID_VALUE_LIST);
}

This file was deleted.

@@ -115,9 +115,12 @@ public void assign(Value<ListValue<T>> other) {
}

@Override
@SuppressWarnings("unchecked")
public ListValue<T> copy() {
List<T> values = GRAPH_FACTORY.createList();
values.addAll(this.values);
for (T value : this.values) {
values.add((T) value.copy());
}
return new ListValue<>(this.elemType, values);
}

@@ -34,18 +34,15 @@
import com.baidu.hugegraph.computer.core.graph.edge.DefaultEdges;
import com.baidu.hugegraph.computer.core.graph.edge.Edge;
import com.baidu.hugegraph.computer.core.graph.edge.Edges;
import com.baidu.hugegraph.computer.core.graph.id.BytesId;
import com.baidu.hugegraph.computer.core.graph.id.Id;
import com.baidu.hugegraph.computer.core.graph.id.LongId;
import com.baidu.hugegraph.computer.core.graph.id.Utf8Id;
import com.baidu.hugegraph.computer.core.graph.id.UuidId;
import com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties;
import com.baidu.hugegraph.computer.core.graph.properties.Properties;
import com.baidu.hugegraph.computer.core.graph.value.BooleanValue;
import com.baidu.hugegraph.computer.core.graph.value.DoubleValue;
import com.baidu.hugegraph.computer.core.graph.value.FloatValue;
import com.baidu.hugegraph.computer.core.graph.value.IdValue;
import com.baidu.hugegraph.computer.core.graph.value.IdValueList;
import com.baidu.hugegraph.computer.core.graph.value.IdValueListList;
import com.baidu.hugegraph.computer.core.graph.value.IdList;
import com.baidu.hugegraph.computer.core.graph.value.IdListList;
import com.baidu.hugegraph.computer.core.graph.value.IntValue;
import com.baidu.hugegraph.computer.core.graph.value.ListValue;
import com.baidu.hugegraph.computer.core.graph.value.LongValue;
@@ -65,17 +62,17 @@ public BuiltinGraphFactory(Config config) {

@Override
public Id createId(long id) {
return new LongId(id);
return BytesId.of(id);
}

@Override
public Id createId(String id) {
return new Utf8Id(id);
return BytesId.of(id);
}

@Override
public Id createId(UUID id) {
return new UuidId(id);
return BytesId.of(id);
}

@Override
@@ -164,11 +161,11 @@ public Value<?> createValue(ValueType type) {
case DOUBLE:
return new DoubleValue();
case ID_VALUE:
return new IdValue();
return BytesId.of();
case ID_VALUE_LIST:
return new IdValueList();
return new IdList();
case ID_VALUE_LIST_LIST:
return new IdValueListList();
return new IdListList();
case LIST_VALUE:
return new ListValue<>();
default:

0 comments on commit 5cde520

Please sign in to comment.