| 80 | } |
| 81 | |
| 82 | private void computeDiff( |
| 83 | DataBag bag1, |
| 84 | DataBag bag2, |
| 85 | DataBag emitTo) { |
| 86 | // Build two hash tables and probe with first one, then the other. |
| 87 | // This does make the assumption that the distinct set of keys from |
| 88 | // each bag will fit in memory. |
| 89 | Set<Tuple> s1 = new HashSet<Tuple>(); |
| 90 | Iterator<Tuple> i1 = bag1.iterator(); |
| 91 | while (i1.hasNext()) s1.add(i1.next()); |
| 92 | |
| 93 | Set<Tuple> s2 = new HashSet<Tuple>(); |
| 94 | Iterator<Tuple> i2 = bag2.iterator(); |
| 95 | while (i2.hasNext()) s2.add(i2.next()); |
| 96 | |
| 97 | for (Tuple t : s1) if (!s2.contains(t)) emitTo.add(t); |
| 98 | for (Tuple t : s2) if (!s1.contains(t)) emitTo.add(t); |
| 99 | |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public boolean allowCompileTimeCalculation() { |