De-duplicate pagerank implementation in PageRankBenchmark
---------------------------------------------------------

                 Key: GIRAPH-137
                 URL: https://issues.apache.org/jira/browse/GIRAPH-137
             Project: Giraph
          Issue Type: Improvement
            Reporter: Jakob Homan
            Priority: Minor


Currently in PageRankBenchmark we have the code for pagerank duplicated in each 
of the implementations of Vertex:
{noformat}    public static class PageRankHashMapVertex extends HashMapVertex<
            LongWritable, DoubleWritable, DoubleWritable, DoubleWritable> {
        @Override
        public void compute(Iterator<DoubleWritable> msgIterator) {
            if (getSuperstep() >= 1) {
                double sum = 0;
                while (msgIterator.hasNext()) {
                    sum += msgIterator.next().get();
                }
                DoubleWritable vertexValue =
                    new DoubleWritable((0.15f / getNumVertices()) + 0.85f *
                                       sum);
                setVertexValue(vertexValue);
            }

            if (getSuperstep() < getConf().getInt(SUPERSTEP_COUNT, -1)) {
                long edges = getNumOutEdges();
                sendMsgToAllEdges(
                    new DoubleWritable(getVertexValue().get() / edges));
            } else {
                voteToHalt();
            }
        }
    }

    public static class PageRankEdgeListVertex extends EdgeListVertex<
            LongWritable, DoubleWritable, DoubleWritable, DoubleWritable> {
        @Override
        public void compute(Iterator<DoubleWritable> msgIterator) {
            if (getSuperstep() >= 1) {
                double sum = 0;
                while (msgIterator.hasNext()) {
                    sum += msgIterator.next().get();
                }
                DoubleWritable vertexValue =
                    new DoubleWritable((0.15f / getNumVertices()) + 0.85f *
                                       sum);
                setVertexValue(vertexValue);
            }

            if (getSuperstep() < getConf().getInt(SUPERSTEP_COUNT, -1)) {
                long edges = getNumOutEdges();
                sendMsgToAllEdges(
                        new DoubleWritable(getVertexValue().get() / edges));
            } else {
                voteToHalt();
            }
        }
    }{noformat}
This code can be consolidated into private class and the two implementations 
just extend that.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to