@Override
    public void map(IntWritable nid, PersonalizedPageRankNode node, Context context)
        throws IOException, InterruptedException {

      for (int sourceIndex = 0; sourceIndex < sources.size(); sourceIndex++) {
        float p = node.getPageRank(sourceIndex);

        float jump = 0.0f;
        float link = 0.0f;

        // float jump = (float) (Math.log(ALPHA) - Math.log(nodeCnt));
        // IS A SOURCE NODE
        if (sources.get(sourceIndex) == node.getNodeId()) {
          jump = (float) Math.log(ALPHA);
          link =
              (float) Math.log(1.0f - ALPHA)
                  + sumLogProbs(p, (float) (Math.log(missingMass[sourceIndex])));
        } else {
          // NOT A SOURCE NODE
          jump = (float) Math.log(0);
          link = (float) Math.log(1.0f - ALPHA) + p;
        }

        p = sumLogProbs(jump, link);
        node.setPageRank(sourceIndex, p);
      }

      context.write(nid, node);
    }
    @Override
    public void map(IntWritable nid, PersonalizedPageRankNode node, Context context)
        throws IOException, InterruptedException {
      // Pass along node structure.
      intermediateStructure.setNodeId(node.getNodeId());
      intermediateStructure.setType(PersonalizedPageRankNode.Type.Structure);
      intermediateStructure.setAdjacencyList(node.getAdjacenyList());

      context.write(nid, intermediateStructure);

      int massMessages = 0;

      // Distribute PageRank mass to neighbors (along outgoing edges).
      if (node.getAdjacenyList().size() > 0) {
        // Each neighbor gets an equal share of PageRank mass.
        ArrayListOfIntsWritable list = node.getAdjacenyList();
        float mass[] = new float[sources.size()];
        for (int i = 0; i < sources.size(); i++) {
          mass[i] = node.getPageRank(i) - (float) StrictMath.log(list.size());
        }

        context.getCounter(PageRank.edges).increment(list.size());

        // Iterate over neighbors.
        for (int i = 0; i < list.size(); i++) {
          neighbor.set(list.get(i));
          intermediateMass.setNodeId(list.get(i));
          intermediateMass.setType(PersonalizedPageRankNode.Type.Mass);

          for (int j = 0; j < sources.size(); j++) {
            intermediateMass.setPageRank(j, mass[j]);
          }

          // Emit messages with PageRank mass to neighbors.
          context.write(neighbor, intermediateMass);

          massMessages++;
        }
      }

      // Bookkeeping.
      context.getCounter(PageRank.nodes).increment(1);
      context.getCounter(PageRank.massMessages).increment(massMessages);
    }