Skip to content

Commit 24a5927

Browse files
author
Aapo Kyrola
committed
reverse bytes so compatible with C/C++ (thanks Clive Cox)
1 parent a26c474 commit 24a5927

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/edu/cmu/graphchi/apps/Pagerank.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class Pagerank implements GraphChiProgram<Float, Float> {
1919

2020

21-
public void update(ChiVertex<Float, Float> vertex, GraphChiContext context) {
21+
public void update(ChiVertex<Float, Float> vertex, GraphChiContext context) {
2222
if (context.getIteration() == 0) {
2323
vertex.setValue(1.0f);
2424
} else {
@@ -34,6 +34,7 @@ public void update(ChiVertex<Float, Float> vertex, GraphChiContext context) {
3434
vertex.outEdge(i).setValue(outValue);
3535
}
3636

37+
3738
if (vertex.getId() % 100000 == 0 || vertex.getId() == 8737 || vertex.getId() == 2914) {
3839
System.out.println(vertex.getId() + " => " + vertex.getValue());
3940
}

src/edu/cmu/graphchi/datablocks/FloatConverter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public int sizeOf() {
2222
}
2323

2424
public Float getValue(byte[] array) {
25-
int x = ((array[0] & 0xff) << 24) + ((array[1] & 0xff) << 16) + ((array[2] & 0xff) << 8) + (array[3] & 0xff);
25+
int x = ((array[3] & 0xff) << 24) + ((array[2] & 0xff) << 16) + ((array[1] & 0xff) << 8) + (array[0] & 0xff);
2626
return Float.intBitsToFloat(x);
2727
}
2828

2929
public void setValue(byte[] array, Float val) {
3030
int x = Float.floatToIntBits(val);
31-
array[0] = (byte) ((x >>> 24) & 0xff);
32-
array[1] = (byte) ((x >>> 16) & 0xff);
33-
array[2] = (byte) ((x >>> 8) & 0xff);
34-
array[3] = (byte) ((x >>> 0) & 0xff);
31+
array[0] = (byte) ((x >>> 0) & 0xff);
32+
array[1] = (byte) ((x >>> 8) & 0xff);
33+
array[2] = (byte) ((x >>> 16) & 0xff);
34+
array[3] = (byte) ((x >>> 24) & 0xff);
3535
}
3636
}

src/edu/cmu/graphchi/datablocks/IntConverter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public int sizeOf() {
2121
}
2222

2323
public Integer getValue(byte[] array) {
24-
int x = ((array[0] & 0xff) << 24) + ((array[1] & 0xff) << 16) + ((array[2] & 0xff) << 8) + (array[3] & 0xff);
24+
int x = ((array[3] & 0xff) << 24) + ((array[2] & 0xff) << 16) + ((array[1] & 0xff) << 8) + (array[0] & 0xff);
2525
return x;
2626
}
2727

2828
public void setValue(byte[] array, Integer x) {
29-
array[0] = (byte) ((x >>> 24) & 0xff);
30-
array[1] = (byte) ((x >>> 16) & 0xff);
31-
array[2] = (byte) ((x >>> 8) & 0xff);
32-
array[3] = (byte) ((x >>> 0) & 0xff);
29+
array[3] = (byte) ((x >>> 24) & 0xff);
30+
array[2] = (byte) ((x >>> 16) & 0xff);
31+
array[1] = (byte) ((x >>> 8) & 0xff);
32+
array[0] = (byte) ((x >>> 0) & 0xff);
3333
}
3434
}

0 commit comments

Comments
 (0)