ltemp.add(newPair);
temp.add(newPair);
    private Pair findSmallest() {        // if there is only one key left, return it        if (pairs.size()==1) {            return (Pair)pairs.firstKey();        }        Pair smallest=(Pair)pairs.firstKey(); //Get smallest pair        int work=smallest.work;        ArrayList temp=new ArrayList();	/* There may be several filters with smallest work though. If	 * there are prefer the ones near the top of the container.	 * This guarantees that we come out even if there is a	 * perfect fusion option. */        boolean cont;        do {            cont=false;            temp.add(smallest); //Save smallest            pairs.remove(smallest); //Remove smallest so next smallest can be reached            Pair newPair=(Pair)pairs.firstKey();            int newWork=newPair.work;            if(newWork==work) { //There are several filters with smallest work                cont=true;                SIRContainer parent1=smallest.n1.filter.getParent();                SIRContainer parent2=newPair.n1.filter.getParent();                if(parent1==parent2) {		    //If there are several smallest in same parent		    //prefer the ones at the top (this will let us		    //come out even if we need to fuse 32 down to 16)                    if(parent1.indexOf(newPair.n1.filter) < parent1.indexOf(smallest.n1.filter)) {                        smallest=newPair;                        work=newWork;                    } else {                        // remove the pair we just considered                        pairs.remove(newPair);                        temp.add(newPair);                    }                } else {                    pairs.remove(newPair);                    ltemp.add(newPair);                }            }        } while(cont && pairs.size()>0);	//Restore the Pairs temporarily removed from pairs        Object[] fix=temp.toArray();        for(int i=0;i<fix.length;i++)            pairs.put(fix[i],null);        return smallest;    }