Untitled

 avatar
unknown
plain_text
3 years ago
2.2 kB
4
Indexable
        @Override
        protected void reduce(
                BlockIdxKeys in_key,
                Iterable<BlockIdxValues> in_vals,
                Reducer<BlockIdxKeys, BlockIdxValues, Text, Text>.Context context
        ) throws IOException, InterruptedException {
            HashSet<BlockIdxValues> left_buffer = new HashSet<BlockIdxValues>();
            HashSet<BlockIdxValues> right_buffer = new HashSet<BlockIdxValues>();
//            System.out.println(in_key);
            for (BlockIdxValues val : in_vals) {
//                System.out.println(val);
                boolean side = val.matrix_side.get();
                if (side)
                    left_buffer.add(new BlockIdxValues(val));
                else
                    right_buffer.add(new BlockIdxValues(val));
            }

            HashMap<IdxKeys, Double> hm = new HashMap<IdxKeys, Double>();

            for (BlockIdxValues left_val : left_buffer) {
                for (BlockIdxValues right_val : right_buffer) {
                    if (left_val.i.get() != right_val.i.get()) {
                        continue;
                    }
                    IdxKeys key = new IdxKeys(left_val.o.get(), right_val.o.get());
                    if (hm.containsKey(key)) {
                        hm.put(key, hm.get(key) + (double) (left_val.value.get() * right_val.value.get()));
                    } else {
                        IdxValues value = new IdxValues(left_val.value.get() * right_val.value.get());
                        hm.put(key, (double) (left_val.value.get() * right_val.value.get()));
                    }
                }
            }

            Text tag = new Text(new String(new byte[]{tag_output}, StandardCharsets.US_ASCII));
            Text output = new Text();
            for (Map.Entry<IdxKeys, Double> entry : hm.entrySet()) {
                IdxKeys key = entry.getKey();
                float value = entry.getValue().floatValue();
//                System.out.println(key.toString() + value.toString());
                output.set(make_element(key.i.get(), key.j.get(), value));
                context.write(tag, output);
            }
        }
    }
Editor is loading...