code: @SuppressWarnings("unchecked")
    static Map<String, Integer>[] countCompanionBlocks(
        Collection<LocatedBlock> companionBlocks) {
      Map<String, Integer>[] result = new HashMap[2];
      result[0] = new HashMap<String, Integer>();
      result[1] = new HashMap<String, Integer>();
      
      for (LocatedBlock block : companionBlocks) {
        for (DatanodeInfo d : block.getLocations()) {
          // count the companion blocks on the datanodes
          String name = d.getName();
          Integer currentCount = result[0].get(name);
          result[0].put(name, currentCount == null ? 1 : currentCount + 1);
          
          // count the companion blocks on the racks of datanodes
          name = d.getParent().getName();
          currentCount = result[1].get(name);
          result[1].put(name, currentCount == null ? 1 : currentCount + 1);
        }
      }
      return result;
    }
docs: Count how many companion blocks are on each datanode or the each rack
  @param companionBlocks a collection of all the companion blocks
  @param result the map from node name to the number of companion blocks
  [0] for datanodes [1] for racks