@Override
public void reduce(IntWritable key, Iterator<VertexEdgeUnionType> iter,
OutputCollector<Text, Text> out, Reporter reporter) throws IOException {
VertexEdgeUnionType next;
HashMap<Pair<Object, Object>, Writable> edgeset = new HashMap();
HashMap<Object, Writable> vertexset = new HashMap();
while (iter.hasNext()) {
next = iter.next();
// Apply reduce on vertex
if (next.flag() == VertexEdgeUnionType.VERTEXVAL) {
Object vid = next.vertex().vid();
if (vertexset.containsKey(vid)) { // duplicate vertex
if (VertexFunc != null)
vertexset.put(vid,
VertexFunc.reduce(next.vertex().vdata(), vertexset.get(vid)));
} else {
if (VertexFunc != null)
vertexset.put(vid,
VertexFunc.reduce(next.vertex().vdata(), VertexFunc.base()));
else
vertexset.put(vid, next.vertex().vdata());
}
} else {
// Apply reduce on edges, remove self and (or merge) duplicate edges.
// Optionally remove bidirectional edge.
Pair p = new Pair(next.edge().source(), next.edge().target());
// self edge
if (p.getL().equals(p.getR()))
continue;
// duplicate edge
if (edgeset.containsKey(p)) {
if (EdgeFunc != null)
edgeset.put(p,
EdgeFunc.reduce(next.edge().EdgeData(), edgeset.get(p)));
} else {
if (EdgeFunc != null)
edgeset.put(p,
EdgeFunc.reduce(next.edge().EdgeData(), EdgeFunc.base()));
else
edgeset.put(p, next.edge().EdgeData());
}
}
}
int nverts = 0;