private void emitEdgeInfo(PageRankValueWritable value, Context context) throws IOException, InterruptedException { int degree = 0; if (edgeSet.containsKey(value.getVertexId())) { Set<Integer> destinations = edgeSet.get(value.getVertexId()); degree = destinations.size(); } String ouput = "" + value.getVertexId() + " " + value.getCurrentPageRank() + " " + value.getEdgeBlock() + " " + value.getEdgeVertex() + " " + degree; outputText.set(ouput); context.write(blockIdWritable, outputText); }
@Override public void reduce(IntWritable key, Iterable<PageRankValueWritable> values, Context context) throws IOException, InterruptedException { edgeSet = new HashMap<Integer, Set<Integer>>(); list = new ArrayList<PageRankValueWritable>(); writtenSelfLoopedNode = new HashSet<Integer>(); for (PageRankValueWritable value : values) { if (value.isNodeInformation()) { if (!value.isSelfLooped()) { if (!edgeSet.containsKey(value.getVertexId())) { edgeSet.put(value.getVertexId(), new HashSet<Integer>()); } Set<Integer> destinations = edgeSet.get(value.getVertexId()); destinations.add(value.getEdgeVertex()); edgeSet.put(value.getVertexId(), destinations); } list.add(value.clone()); } } this.blockIdWritable.set(key.get()); for (PageRankValueWritable value : list) { if (value.isNodeInformation()) { if (!value.isSelfLooped()) { if (!edgeSet.containsKey(value.getVertexId())) { System.err.println("serious error"); ouputTestInfo(-1, "serious error", context); break; } emitEdgeInfo(value, context); } else { if (!this.writtenSelfLoopedNode.contains(value.getVertexId())) { emitEdgeInfo(value, context); this.writtenSelfLoopedNode.add(value.getVertexId()); } } } } }