code: private boolean domainsOverlap(TableFactor f1, TableFactor f2) {
      for (int n1 : f1.neighborIndices) {
        for (int n2 : f2.neighborIndices) {
          if (n1 == n2) return true;
        }
      }
      return false;
    }
docs: Just a quick inline to check if two factors have overlapping domains. Since factor neighbor sets are super small,
  this n^2 algorithm is fine.
  
  @param f1 first factor to compare
  @param f2 second factor to compare
  @return whether their domains overlap