class NetworkTopologyImpl implements NetworkTopology {

  public List<? extends Node> sortByDistanceCost(Node reader,
      List<? extends Node> nodes, int activeLen) {
    /** Sort weights for the nodes array */
    if (reader == null) {
      return nodes;
    }
    int[] costs = new int[activeLen];
    for (int i = 0; i < activeLen; i++) {
      costs[i] = getDistanceCost(reader, nodes.get(i));
    }
    // Add cost/node pairs to a TreeMap to sort
    TreeMap<Integer, List<Node>> tree = new TreeMap<Integer, List<Node>>();
    for (int i = 0; i < activeLen; i++) {
      int cost = costs[i];
      Node node = nodes.get(i);
      List<Node> list = tree.get(cost);
      if (list == null) {
        list = Lists.newArrayListWithExpectedSize(1);
        tree.put(cost, list);
      }
      list.add(node);
    }

    List<Node> ret = new ArrayList<>();
    for (List<Node> list: tree.values()) {
      if (list != null) {
        Collections.shuffle(list);
        for (Node n: list) {
          ret.add(n);
        }
      }
    }

    Preconditions.checkState(ret.size() == activeLen,
        "Wrong number of nodes sorted!");
    return ret;
  }

  public  NetworkTopologyImpl(ConfigurationSource conf);
  @VisibleForTesting public  NetworkTopologyImpl(NodeSchemaManager manager);

}