Program: 142527
Project: 142527
Buggy source:
private void triangles(HierarchicalGraph hgraph,AttributeModel attributeModel){
  int ProgressCount=0;
  Progress.start(progress,7 * hgraph.getNodeCount());
  hgraph.readLock();
  N=hgraph.getNodeCount();
  nodeClustering=new double[N];
  network=new ArrayWrapper[N];
  HashMap<Node,Integer> indicies=new HashMap<Node,Integer>();
  int index=0;
  for (  Node s : hgraph.getNodes()) {
    indicies.put(s,index);
    network[index]=new ArrayWrapper();
    index++;
    Progress.progress(progress,++ProgressCount);
  }
  index=0;
  for (  Node node : hgraph.getNodes()) {
    HashMap<Node,EdgeWrapper> neighborTable=new HashMap<Node,EdgeWrapper>();
    if (!isDirected) {
      for (      Node neighbor : hgraph.getNeighbors(node)) {
        neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
      }
    }
 else {
      for (      Edge in : ((HierarchicalDirectedGraph)hgraph).getInEdgesAndMetaInEdges(node)) {
        Node neighbor=in.getSource();
        neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
      }
      for (      Edge out : ((HierarchicalDirectedGraph)hgraph).getOutEdgesAndMetaOutEdges(node)) {
        Node neighbor=out.getTarget();
        EdgeWrapper ew=neighborTable.get(neighbor);
        if (ew == null) {
          neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
        }
 else {
          ew.count++;
        }
      }
    }
    EdgeWrapper[] edges=new EdgeWrapper[neighborTable.size()];
    int i=0;
    for (    EdgeWrapper e : neighborTable.values()) {
      edges[i]=e;
      i++;
    }
    network[index].node=node;
    network[index].setArray(edges);
    index++;
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      hgraph.readUnlockAll();
      return;
    }
  }
  Arrays.sort(network);
  for (int j=0; j < N; j++) {
    network[j].setID(j);
    Progress.progress(progress,++ProgressCount);
  }
  for (int j=0; j < N; j++) {
    Arrays.sort(network[j].getArray(),new Renumbering());
    Progress.progress(progress,++ProgressCount);
  }
  triangles=new int[N];
  K=(int)Math.sqrt(N);
  for (int v=0; v < K && v < N; v++) {
    newVertex(v);
    Progress.progress(progress,++ProgressCount);
  }
  for (int v=N - 1; (v >= 0) && (v >= K); v--) {
    for (int i=closest_in_array(v); i >= 0; i--) {
      int u=network[v].get(i);
      if (u >= K) {
        tr_link_nohigh(u,v,network[v].getCount(i));
      }
    }
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      hgraph.readUnlockAll();
      return;
    }
  }
  avgClusteringCoeff=0;
  for (int v=0; v < N; v++) {
    if (network[v].length() > 1) {
      double cc=triangles[v];
      totalTriangles+=triangles[v];
      cc/=(network[v].length() * (network[v].length() - 1));
      if (!isDirected) {
        cc*=2.0f;
      }
      nodeClustering[v]=cc;
      avgClusteringCoeff+=cc;
    }
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      hgraph.readUnlockAll();
      return;
    }
  }
  totalTriangles/=3;
  avgClusteringCoeff/=N;
  hgraph.readUnlock();
}

Fixed version (ground truth):
public void triangles(HierarchicalGraph hgraph){
  int ProgressCount=0;
  Progress.start(progress,7 * hgraph.getNodeCount());
  hgraph.readLock();
  N=hgraph.getNodeCount();
  nodeClustering=new double[N];
  network=new ArrayWrapper[N];
  HashMap<Node,Integer> indicies=new HashMap<Node,Integer>();
  int index=0;
  for (  Node s : hgraph.getNodes()) {
    indicies.put(s.getNodeData().getRootNode(),index);
    network[index]=new ArrayWrapper();
    index++;
    Progress.progress(progress,++ProgressCount);
  }
  index=0;
  for (  Node node : hgraph.getNodes()) {
    HashMap<Node,EdgeWrapper> neighborTable=new HashMap<Node,EdgeWrapper>();
    if (!isDirected) {
      for (      Node neighbor : hgraph.getNeighbors(node)) {
        neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
      }
    }
 else {
      for (      Edge in : ((HierarchicalDirectedGraph)hgraph).getInEdgesAndMetaInEdges(node)) {
        Node neighbor=in.getSource();
        neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
      }
      for (      Edge out : ((HierarchicalDirectedGraph)hgraph).getOutEdgesAndMetaOutEdges(node)) {
        Node neighbor=out.getTarget();
        EdgeWrapper ew=neighborTable.get(neighbor);
        if (ew == null) {
          neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
        }
 else {
          ew.count++;
        }
      }
    }
    EdgeWrapper[] edges=new EdgeWrapper[neighborTable.size()];
    int i=0;
    for (    EdgeWrapper e : neighborTable.values()) {
      edges[i]=e;
      i++;
    }
    network[index].node=node;
    network[index].setArray(edges);
    index++;
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      hgraph.readUnlockAll();
      return;
    }
  }
  Arrays.sort(network);
  for (int j=0; j < N; j++) {
    network[j].setID(j);
    Progress.progress(progress,++ProgressCount);
  }
  for (int j=0; j < N; j++) {
    Arrays.sort(network[j].getArray(),new Renumbering());
    Progress.progress(progress,++ProgressCount);
  }
  triangles=new int[N];
  K=(int)Math.sqrt(N);
  for (int v=0; v < K && v < N; v++) {
    newVertex(v);
    Progress.progress(progress,++ProgressCount);
  }
  for (int v=N - 1; (v >= 0) && (v >= K); v--) {
    for (int i=closest_in_array(v); i >= 0; i--) {
      int u=network[v].get(i);
      if (u >= K) {
        tr_link_nohigh(u,v,network[v].getCount(i));
      }
    }
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      hgraph.readUnlockAll();
      return;
    }
  }
  avgClusteringCoeff=0;
  totalTriangles=0;
  for (int v=0; v < N; v++) {
    if (network[v].length() > 1) {
      double cc=triangles[v];
      totalTriangles+=triangles[v];
      cc/=(network[v].length() * (network[v].length() - 1));
      if (!isDirected) {
        cc*=2.0f;
      }
      nodeClustering[v]=cc;
      avgClusteringCoeff+=cc;
    }
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      hgraph.readUnlockAll();
      return;
    }
  }
  totalTriangles/=3;
  avgClusteringCoeff/=N;
  hgraph.readUnlock();
}