if (partition.length==1) {  return fuse(sj); } else if (partition.length==sj.size()) {  return sj; }   SIRStream dispatchResult = dispatchToSimple(sj); if (dispatchResult!=null) { return dispatchResult; }  if (!isFusable(sj)) { return sj; } else { System.err.println("Fusing " + (sj.size()) + " SplitJoin filters into " + partition.length + " filters..."); }  int[] oldSplit=sj.getSplitter().getWeights(); int[] oldJoin=sj.getJoiner().getWeights(); JExpression[] newSplit=new JExpression[partition.length]; JExpression[] newJoin=new JExpression[partition.length]; SIRSplitJoin newSplitJoin=new SIRSplitJoin(); newSplitJoin.setParent(sj.getParent()); newSplitJoin.setIdent(sj.getIdent()); newSplitJoin.setFields(sj.getFields()); newSplitJoin.setMethods(sj.getMethods()); for(int i=0,j=0;i<partition.length;i++) { int incr=partition[i]; if(incr==1) { newSplitJoin.add(sj.get(j)); newSplit[i]=new JIntLiteral(oldSplit[j]); newJoin[i]=new JIntLiteral(oldJoin[j]); } else { int sumSplit=0; int sumJoin=0; JExpression[] childSplit=new JExpression[incr]; JExpression[] childJoin=new JExpression[incr]; SIRSplitJoin childSplitJoin=new SIRSplitJoin(); for(int k=incr,l=j,m=0;k>0;k--,l++,m++) { sumSplit+=oldSplit[l]; sumJoin+=oldJoin[l]; childSplit[m]=new JIntLiteral(oldSplit[l]); childJoin[m]=new JIntLiteral(oldJoin[l]); childSplitJoin.add(sj.get(l)); } newSplit[i]=new JIntLiteral(sumSplit); newJoin[i]=new JIntLiteral(sumJoin); childSplitJoin.setSplitter(SIRSplitter.create(childSplitJoin,sj.getSplitter().getType(),childSplit)); childSplitJoin.setJoiner(SIRJoiner.create(childSplitJoin,sj.getJoiner().getType(),childJoin)); newSplitJoin.add(childSplitJoin); fuse(childSplitJoin); } j+=incr; } newSplitJoin.setSplitter(SIRSplitter.create(newSplitJoin,sj.getSplitter().getType(),newSplit)); newSplitJoin.setJoiner(SIRJoiner.create(newSplitJoin,sj.getJoiner().getType(),newJoin));  sj.getParent().replace(sj,newSplitJoin); return newSplitJoin; }
    public static SIRStream fuse(SIRSplitJoin sj,int[] partition) {	{//Quick check	    int sum=0;	    for(int i=0;i<partition.length;i++) {		Utils.assert(partition[i]>0);		sum+=partition[i];	    }	    if(sum!=sj.size()) {		Utils.fail("Illformated partition "+partition+" for SIRSplitJoin "+sj+" of size "+sj.size());	    }	}	if (partition.length==1) {	    // if fusing whole thing	    return fuse(sj);	} else if (partition.length==sj.size()) {	    // if not fusing at all	    return sj;	}	// dispatch to simple fusion	SIRStream dispatchResult = dispatchToSimple(sj);	if (dispatchResult!=null) {	    return dispatchResult;	}		if (!isFusable(sj)) {	    return sj;	} else {	    System.err.println("Fusing " + (sj.size()) + " SplitJoin filters into " + partition.length + " filters..."); 	}	int[] oldSplit=sj.getSplitter().getWeights();	int[] oldJoin=sj.getJoiner().getWeights();	JExpression[] newSplit=new JExpression[partition.length];	JExpression[] newJoin=new JExpression[partition.length];	SIRSplitJoin newSplitJoin=new SIRSplitJoin();	newSplitJoin.setParent(sj.getParent());	newSplitJoin.setIdent(sj.getIdent());	newSplitJoin.setFields(sj.getFields());	newSplitJoin.setMethods(sj.getMethods());	for(int i=0,j=0;i<partition.length;i++) {	    int incr=partition[i];	    if(incr==1) {		newSplitJoin.add(sj.get(j));		newSplit[i]=new JIntLiteral(oldSplit[j]);		newJoin[i]=new JIntLiteral(oldJoin[j]);	    } else {		int sumSplit=0;		int sumJoin=0;		JExpression[] childSplit=new JExpression[incr];		JExpression[] childJoin=new JExpression[incr];		SIRSplitJoin childSplitJoin=new SIRSplitJoin();		for(int k=incr,l=j,m=0;k>0;k--,l++,m++) {		    sumSplit+=oldSplit[l];		    sumJoin+=oldJoin[l];		    childSplit[m]=new JIntLiteral(oldSplit[l]);		    childJoin[m]=new JIntLiteral(oldJoin[l]);		    childSplitJoin.add(sj.get(l));		}		newSplit[i]=new JIntLiteral(sumSplit);		newJoin[i]=new JIntLiteral(sumJoin);		childSplitJoin.setSplitter(SIRSplitter.create(childSplitJoin,sj.getSplitter().getType(),childSplit));		childSplitJoin.setJoiner(SIRJoiner.create(childSplitJoin,sj.getJoiner().getType(),childJoin));		newSplitJoin.add(childSplitJoin);		fuse(childSplitJoin);	    }	    j+=incr;	}	newSplitJoin.setSplitter(SIRSplitter.create(newSplitJoin,sj.getSplitter().getType(),newSplit));	newSplitJoin.setJoiner(SIRJoiner.create(newSplitJoin,sj.getJoiner().getType(),newJoin));	// replace in parent	sj.getParent().replace(sj,newSplitJoin);	return newSplitJoin;    }