jpayne@68: package tax; jpayne@68: jpayne@68: import java.util.ArrayList; jpayne@68: import java.util.BitSet; jpayne@68: import java.util.Locale; jpayne@68: import java.util.PriorityQueue; jpayne@68: jpayne@68: import shared.Tools; jpayne@68: jpayne@68: /** jpayne@68: * Support class for IDTree. jpayne@68: * @author Brian Bushnell jpayne@68: * @date July 1, 2016 jpayne@68: * jpayne@68: */ jpayne@68: public class IDNode implements Comparable{ jpayne@68: jpayne@68: public static IDNode makeTree(IDNode[] nodes){ jpayne@68: jpayne@68: PriorityQueue heap=new PriorityQueue(nodes.length); jpayne@68: ArrayList list=new ArrayList(2*nodes.length); jpayne@68: for(IDNode n : nodes){ jpayne@68: list.add(n); jpayne@68: heap.add(n); jpayne@68: } jpayne@68: jpayne@68: while(heap.size()>1){ jpayne@68: IDNode a=heap.poll(); jpayne@68: // System.err.println("Found A node "+a); jpayne@68: if(a.parent==null){ jpayne@68: IDNode b=nodes[a.maxPos]; jpayne@68: if(b.parent!=null){ jpayne@68: // System.err.println("Skipped node "+b); jpayne@68: } jpayne@68: while(b.parent!=null){ jpayne@68: b=b.parent; jpayne@68: // System.err.println("to parent "+b); jpayne@68: } jpayne@68: // System.err.println("Found B node "+b); jpayne@68: IDNode c=new IDNode(a, b, list.size()); jpayne@68: list.add(c); jpayne@68: heap.add(c); jpayne@68: // System.err.println("Made C node "+c); jpayne@68: // System.err.println(c.toNewick()); jpayne@68: } jpayne@68: jpayne@68: // System.err.println(); jpayne@68: } jpayne@68: jpayne@68: return heap.poll(); jpayne@68: } jpayne@68: jpayne@68: @Override jpayne@68: public int compareTo(IDNode idn) { jpayne@68: if(max==idn.max){return number-idn.number;} jpayne@68: return max0 ? Tools.maxIndex(array) : 0); jpayne@68: max=(maxPos>=array.length ? 0 : array[maxPos]); jpayne@68: bs=new BitSet(number+1); jpayne@68: bs.set(number); jpayne@68: } jpayne@68: jpayne@68: double[] shorter(double[] a, double[] b){ jpayne@68: return a.length=b.max); jpayne@68: jpayne@68: number=number_; jpayne@68: jpayne@68: double[] array1=longer(a.array, b.array); jpayne@68: double[] array2=shorter(a.array, b.array); jpayne@68: assert(array1!=array2) : a.array.length+", "+b.array.length+", "+a.array+", "+b.array; jpayne@68: jpayne@68: bs=new BitSet(); jpayne@68: bs.or(a.bs); jpayne@68: bs.or(b.bs); jpayne@68: array=array1.clone(); jpayne@68: for(int i=0; i