Skip to content

Commit f5f20c9

Browse files
committed
[ISSUE-1094] add basic graph data structure
1 parent 122019a commit f5f20c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3602
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.tencent.angel.graph.common.conf;
2+
3+
public class AngelGraphConf {
4+
public static final String ANGEL_GRAPH_USE_BYTES_FOR_READONLY = "angel.graph.use.bytes.for.readonly";
5+
public static final Boolean DEFAULT_ANGEL_GRAPH_USE_BYTES_FOR_READONLY = true;
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.tencent.angel.graph.common.conf;
2+
3+
public class Constents {
4+
5+
public static final int[] emptyInts = new int[0];
6+
public static final float[] emptyFloats = new float[0];
7+
public static final long[] emptyLongs = new long[0];
8+
public static final byte[] emptyBytes = new byte[0];
9+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.tencent.angel.graph.common.data;
2+
3+
import com.tencent.angel.common.ByteBufSerdeUtils;
4+
import com.tencent.angel.common.StreamSerdeUtils;
5+
import com.tencent.angel.ps.storage.vector.element.IElement;
6+
import io.netty.buffer.ByteBuf;
7+
import java.io.DataInputStream;
8+
import java.io.DataOutputStream;
9+
import java.io.IOException;
10+
11+
public class EdgeType implements IElement {
12+
private int[] types;
13+
14+
public EdgeType(int[] types) {
15+
this.types = types;
16+
}
17+
18+
public EdgeType() {
19+
this(null);
20+
}
21+
22+
@Override
23+
public Object deepClone() {
24+
return types;
25+
}
26+
27+
@Override
28+
public void serialize(ByteBuf output) {
29+
ByteBufSerdeUtils.serializeInts(output, types);
30+
}
31+
32+
@Override
33+
public void deserialize(ByteBuf input) {
34+
types = ByteBufSerdeUtils.deserializeInts(input);
35+
}
36+
37+
@Override
38+
public int bufferLen() {
39+
return ByteBufSerdeUtils.serializedIntsLen(types);
40+
}
41+
42+
@Override
43+
public void serialize(DataOutputStream output) throws IOException {
44+
StreamSerdeUtils.serializeInts(output, types);
45+
}
46+
47+
@Override
48+
public void deserialize(DataInputStream input) throws IOException {
49+
types = StreamSerdeUtils.deserializeInts(input);
50+
}
51+
52+
@Override
53+
public int dataLen() {
54+
return bufferLen();
55+
}
56+
57+
public int[] getTypes() {
58+
return types;
59+
}
60+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.tencent.angel.graph.common.data;
2+
3+
import com.tencent.angel.common.ByteBufSerdeUtils;
4+
import com.tencent.angel.common.StreamSerdeUtils;
5+
import com.tencent.angel.ml.math2.vector.IntFloatVector;
6+
import com.tencent.angel.ps.storage.vector.element.IElement;
7+
import io.netty.buffer.ByteBuf;
8+
import java.io.DataInputStream;
9+
import java.io.DataOutputStream;
10+
import java.io.IOException;
11+
12+
public class Feature implements IElement {
13+
private IntFloatVector features;
14+
15+
public Feature(IntFloatVector features) {
16+
this.features = features;
17+
}
18+
19+
public Feature() {
20+
this(null);
21+
}
22+
23+
@Override
24+
public Object deepClone() {
25+
// Just return original features
26+
return features;
27+
}
28+
29+
@Override
30+
public void serialize(ByteBuf output) {
31+
ByteBufSerdeUtils.serializeVector(output, features);
32+
}
33+
34+
@Override
35+
public void deserialize(ByteBuf input) {
36+
features = (IntFloatVector) ByteBufSerdeUtils.deserializeVector(input);
37+
}
38+
39+
@Override
40+
public int bufferLen() {
41+
return ByteBufSerdeUtils.serializedVectorLen(features);
42+
}
43+
44+
@Override
45+
public void serialize(DataOutputStream output) throws IOException {
46+
StreamSerdeUtils.serializeVector(output, features);
47+
}
48+
49+
@Override
50+
public void deserialize(DataInputStream input) throws IOException {
51+
features = (IntFloatVector) StreamSerdeUtils.deserializeVector(input);
52+
}
53+
54+
@Override
55+
public int dataLen() {
56+
return StreamSerdeUtils.serializedVectorLen(features);
57+
}
58+
59+
public IntFloatVector getFeatures() {
60+
return features;
61+
}
62+
63+
public void setFeatures(IntFloatVector features) {
64+
this.features = features;
65+
}
66+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.tencent.angel.graph.common.data;
2+
3+
import com.tencent.angel.common.ByteBufSerdeUtils;
4+
import com.tencent.angel.common.StreamSerdeUtils;
5+
import com.tencent.angel.ml.math2.vector.IntFloatVector;
6+
import com.tencent.angel.ps.storage.vector.element.IElement;
7+
import io.netty.buffer.ByteBuf;
8+
import java.io.DataInputStream;
9+
import java.io.DataOutputStream;
10+
import java.io.IOException;
11+
12+
public class Features implements IElement {
13+
14+
private IntFloatVector[] features;
15+
16+
public Features(IntFloatVector[] features) {
17+
this.features = features;
18+
}
19+
20+
public Features() {
21+
this(null);
22+
}
23+
24+
@Override
25+
public Object deepClone() {
26+
return features;
27+
}
28+
29+
@Override
30+
public void serialize(ByteBuf output) {
31+
ByteBufSerdeUtils.serializeIntFloatVectors(output, features);
32+
}
33+
34+
@Override
35+
public void deserialize(ByteBuf input) {
36+
features = ByteBufSerdeUtils.deserializeIntFloatVectors(input);
37+
}
38+
39+
@Override
40+
public int bufferLen() {
41+
return ByteBufSerdeUtils.serializedIntFloatVectorsLen(features);
42+
}
43+
44+
@Override
45+
public void serialize(DataOutputStream output) throws IOException {
46+
StreamSerdeUtils.serializeIntFloatVectors(output, features);
47+
}
48+
49+
@Override
50+
public void deserialize(DataInputStream input) throws IOException {
51+
features = StreamSerdeUtils.deserializeIntFloatVectors(input);
52+
}
53+
54+
@Override
55+
public int dataLen() {
56+
return bufferLen();
57+
}
58+
59+
public IntFloatVector[] getFeatures() {
60+
return features;
61+
}
62+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.tencent.angel.graph.common.data;
2+
3+
import com.tencent.angel.common.ByteBufSerdeUtils;
4+
import com.tencent.angel.common.StreamSerdeUtils;
5+
import com.tencent.angel.ps.storage.vector.element.IElement;
6+
import io.netty.buffer.ByteBuf;
7+
import java.io.DataInputStream;
8+
import java.io.DataOutputStream;
9+
import java.io.IOException;
10+
11+
public class Labels implements IElement {
12+
private float[] labels;
13+
14+
public Labels(float[] labels) {
15+
this.labels = labels;
16+
}
17+
18+
public Labels() {
19+
this(null);
20+
}
21+
22+
@Override
23+
public Object deepClone() {
24+
return labels;
25+
}
26+
27+
@Override
28+
public void serialize(ByteBuf output) {
29+
ByteBufSerdeUtils.serializeFloats(output, labels);
30+
}
31+
32+
@Override
33+
public void deserialize(ByteBuf input) {
34+
labels = ByteBufSerdeUtils.deserializeFloats(input);
35+
}
36+
37+
@Override
38+
public int bufferLen() {
39+
return ByteBufSerdeUtils.serializedFloatsLen(labels);
40+
}
41+
42+
@Override
43+
public void serialize(DataOutputStream output) throws IOException {
44+
StreamSerdeUtils.serializeFloats(output, labels);
45+
}
46+
47+
@Override
48+
public void deserialize(DataInputStream input) throws IOException {
49+
labels = StreamSerdeUtils.deserializeFloats(input);
50+
}
51+
52+
@Override
53+
public int dataLen() {
54+
return bufferLen();
55+
}
56+
57+
public float[] getWeights() {
58+
return labels;
59+
}
60+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.tencent.angel.graph.common.data;
2+
3+
import com.tencent.angel.common.ByteBufSerdeUtils;
4+
import com.tencent.angel.ps.storage.vector.element.IElement;
5+
import io.netty.buffer.ByteBuf;
6+
import java.io.DataInputStream;
7+
import java.io.DataOutputStream;
8+
import java.io.IOException;
9+
10+
public class LongNeighbor implements IElement {
11+
12+
private long[] nodeIds;
13+
14+
public LongNeighbor(long[] nodeIds) {
15+
this.nodeIds = nodeIds;
16+
}
17+
18+
public LongNeighbor() {
19+
this(null);
20+
}
21+
22+
@Override
23+
public Object deepClone() {
24+
long[] newNodeIds = new long[nodeIds.length];
25+
System.arraycopy(nodeIds, 0, newNodeIds, 0, nodeIds.length);
26+
return new LongNeighbor(newNodeIds);
27+
}
28+
29+
@Override
30+
public void serialize(ByteBuf output) {
31+
ByteBufSerdeUtils.serializeLongs(output, nodeIds);
32+
}
33+
34+
@Override
35+
public void deserialize(ByteBuf input) {
36+
nodeIds = ByteBufSerdeUtils.deserializeLongs(input);
37+
}
38+
39+
@Override
40+
public int bufferLen() {
41+
return ByteBufSerdeUtils.serializedLongsLen(nodeIds);
42+
}
43+
44+
@Override
45+
public void serialize(DataOutputStream output) throws IOException {
46+
output.writeInt(nodeIds.length);
47+
for (int i = 0; i < nodeIds.length; i++) {
48+
output.writeLong(nodeIds[i]);
49+
}
50+
}
51+
52+
@Override
53+
public void deserialize(DataInputStream input) throws IOException {
54+
nodeIds = new long[input.readInt()];
55+
for (int i = 0; i < nodeIds.length; i++) {
56+
nodeIds[i] = input.readLong();
57+
}
58+
}
59+
60+
@Override
61+
public int dataLen() {
62+
return bufferLen();
63+
}
64+
65+
public long[] getNodeIds() {
66+
return nodeIds;
67+
}
68+
69+
public void setNodeIds(long[] nodeIds) {
70+
this.nodeIds = nodeIds;
71+
}
72+
}

0 commit comments

Comments
 (0)