You are on page 1of 1

public static class BFSReducer extends Reducer<LongWritable, EValue, LongWri table, EValue> { @Override public void reduce(LongWritable key,

Iterable<EValue> values, Context co ntext) throws IOException, InterruptedException { boolean reachable = false; LinkedList<EValue> copy = new LinkedList<EValue>(); HashMap<Long, Integer> passed = new HashMap<Long, Integer>(); HashSet<EValue> sources = new HashSet<EValue>(); //System.out.println("Starting reduce for key #" + key.get()); for(EValue tmp : values) { //System.out.println("Checking EVALUE: " + tmp); if(tmp.reachable) { //System.out.println("key #" + key.get() + " is reachable fr om key #" + tmp.value + " in " + tmp.distance); if(!tmp.passedOn) { reachable = true; sources.add(tmp.copy()); tmp.passed(); //context.getCounter(ValueUse.NOTIFICATIONS).increment(1 ); } else if(passed.keySet().contains(tmp.value)) passed.put(new Long(tmp.value), new Integer(Math.min(pas sed.get(tmp.value), tmp.distance))); else passed.put(new Long(tmp.value), new Integer(tmp.distance )); //break; } else { //System.out.println("copying " + tmp); copy.add(tmp.copy()); } } for(Long source : passed.keySet()) context.write(key, new EValue(true, true, passed.get(source), so urce)); for(EValue ev : copy) { if(reachable) { //System.out.println("attempting to notify..."); for(EValue s : sources) { if(!passed.keySet().contains(s.value)) { //System.out.println("notifying key #" + ev.value); context.write(new LongWritable(ev.value), new EValue (true, false, s.distance + 1, s.value)); context.getCounter(ValueUse.NOTIFICATIONS).increment (1); } } } //System.out.println("propagating graph..."); context.write(key, ev); } } }

You might also like