public void checkSymmetryAndSorting()

in src/main/java/com/twitter/sbf/graph/Graph.java [213:243]


  public void checkSymmetryAndSorting() {
    for (int i = 0; i < this.getNumVertices(); i++) {
      int[] neighborsOfI = this.getNeighbors(i);
      for (int j = 0; j < neighborsOfI.length; j++) {
        if (j > 0 && neighborsOfI[j] <= neighborsOfI[j - 1]) {
          throw new IllegalStateException(
            "Input graph does not have ascendingly sorted neighbors! "
            + String.format(
              "Neighbor no. %d (value %d) of node %d is less than neighbor no. %d (value %d)",
              // add 1s to everything to get back 1-indexing
              j + 1, neighborsOfI[j] + 1, i + 1, j, neighborsOfI[j - 1] + 1
            )
          );
        }
        if (neighborsOfI[j] < i) {
          double diff = Math.abs(
            this.getWeightOfJInI(neighborsOfI[j], i) - this.getWeightOfJInI(i, neighborsOfI[j])
          );
          if (diff > 1e-5) {
            throw new IllegalStateException("Input graph is not symmetric! "
              + String.format(
                "Weight of (%d, %d) is %.2g, while weight of (%d, %d) is %.2g",
                i + 1, neighborsOfI[j] + 1, this.getWeightOfJInI(i, neighborsOfI[j]),
                neighborsOfI[j] + 1, i + 1, this.getWeightOfJInI(neighborsOfI[j], i)
              )
            );
          }
        }
      }
    }
  }