Program: 109023
Project: 109023
Buggy source:
/** 
 * Returns the tree for the given sensitive attribute, if a generalization hierarchy is associated. Required for t-closeness with hierarchical distance EMD
 * @param attribute
 * @return tree
 */
public int[] getTree(String attribute){
  final int[][] data=dataSE.getArray();
  final int index=indexesSE.get(attribute);
  final int[][] hierarchy=hierarchiesSE.get(attribute).map;
  final int totalElementsP=data.length;
  final int height=hierarchy[0].length - 1;
  final int numLeafs=hierarchy.length;
  final ArrayList<Integer> treeList=new ArrayList<Integer>();
  treeList.add(totalElementsP);
  treeList.add(numLeafs);
  treeList.add(height);
  for (int i=0; i < numLeafs; i++) {
    treeList.add(0);
  }
  final int offsetLeafs=3;
  for (int i=0; i < data.length; i++) {
    if (subset == null || subset.get(i)) {
      int previousFreq=treeList.get(data[i][index] + offsetLeafs);
      previousFreq++;
      treeList.set(data[i][index] + offsetLeafs,previousFreq);
    }
  }
  for (int i=0; i < numLeafs; i++) {
    treeList.add(-1);
  }
class TNode {
    HashSet<Integer> children=new HashSet<Integer>();
    int offset=0;
    int level=0;
  }
  final int offsetsExtras=offsetLeafs + numLeafs;
  final HashMap<Integer,TNode> nodes=new HashMap<Integer,TNode>();
  final ArrayList<ArrayList<TNode>> levels=new ArrayList<ArrayList<TNode>>();
  for (int i=0; i < hierarchy[0].length; i++) {
    levels.add(new ArrayList<TNode>());
  }
  for (int i=0; i < hierarchy[0].length; i++) {
    for (int j=0; j < hierarchy.length; j++) {
      final int nodeID=hierarchy[j][i];
      TNode curNode=null;
      if (!nodes.containsKey(nodeID)) {
        curNode=new TNode();
        curNode.level=i;
        nodes.put(nodeID,curNode);
        final ArrayList<TNode> level=levels.get(curNode.level);
        level.add(curNode);
      }
 else {
        curNode=nodes.get(nodeID);
      }
      if (i > 0) {
        curNode.children.add(hierarchy[j][i - 1]);
      }
    }
  }
  for (  final ArrayList<TNode> level : levels) {
    for (    final TNode node : level) {
      if (node.level > 0) {
        node.offset=treeList.size();
        treeList.add(node.children.size());
        treeList.add(node.level);
        for (        final int child : node.children) {
          if (node.level == 1) {
            treeList.add(child + offsetsExtras);
          }
 else {
            treeList.add(nodes.get(child).offset);
          }
        }
        treeList.add(0);
        treeList.add(0);
      }
    }
  }
  final int[] treeArray=new int[treeList.size()];
  int count=0;
  for (  final int val : treeList) {
    treeArray[count++]=val;
  }
  return treeArray;
}

Fixed version (ground truth):
/** 
 * Returns the tree for the given sensitive attribute, if a generalization hierarchy is associated. Required for t-closeness with hierarchical distance EMD
 * @param attribute
 * @return tree
 */
public int[] getTree(String attribute){
  final int[][] data=dataSE.getArray();
  final int index=indexesSE.get(attribute);
  final int[][] hierarchy=hierarchiesSE.get(attribute).map;
  final int totalElementsP=subset == null ? data.length : subsetSize;
  final int height=hierarchy[0].length - 1;
  final int numLeafs=hierarchy.length;
  final ArrayList<Integer> treeList=new ArrayList<Integer>();
  treeList.add(totalElementsP);
  treeList.add(numLeafs);
  treeList.add(height);
  for (int i=0; i < numLeafs; i++) {
    treeList.add(0);
  }
  final int offsetLeafs=3;
  for (int i=0; i < data.length; i++) {
    if (subset == null || subset.get(i)) {
      int previousFreq=treeList.get(data[i][index] + offsetLeafs);
      previousFreq++;
      treeList.set(data[i][index] + offsetLeafs,previousFreq);
    }
  }
  for (int i=0; i < numLeafs; i++) {
    treeList.add(-1);
  }
class TNode {
    HashSet<Integer> children=new HashSet<Integer>();
    int offset=0;
    int level=0;
  }
  final int offsetsExtras=offsetLeafs + numLeafs;
  final HashMap<Integer,TNode> nodes=new HashMap<Integer,TNode>();
  final ArrayList<ArrayList<TNode>> levels=new ArrayList<ArrayList<TNode>>();
  for (int i=0; i < hierarchy[0].length; i++) {
    levels.add(new ArrayList<TNode>());
  }
  for (int i=0; i < hierarchy[0].length; i++) {
    for (int j=0; j < hierarchy.length; j++) {
      final int nodeID=hierarchy[j][i];
      TNode curNode=null;
      if (!nodes.containsKey(nodeID)) {
        curNode=new TNode();
        curNode.level=i;
        nodes.put(nodeID,curNode);
        final ArrayList<TNode> level=levels.get(curNode.level);
        level.add(curNode);
      }
 else {
        curNode=nodes.get(nodeID);
      }
      if (i > 0) {
        curNode.children.add(hierarchy[j][i - 1]);
      }
    }
  }
  for (  final ArrayList<TNode> level : levels) {
    for (    final TNode node : level) {
      if (node.level > 0) {
        node.offset=treeList.size();
        treeList.add(node.children.size());
        treeList.add(node.level);
        for (        final int child : node.children) {
          if (node.level == 1) {
            treeList.add(child + offsetsExtras);
          }
 else {
            treeList.add(nodes.get(child).offset);
          }
        }
        treeList.add(0);
        treeList.add(0);
      }
    }
  }
  final int[] treeArray=new int[treeList.size()];
  int count=0;
  for (  final int val : treeList) {
    treeArray[count++]=val;
  }
  return treeArray;
}