public static double dot_product(FeatureNode [] x, FeatureNode [] z) {
                double sum=0;
                int i,j;
                for (i=0,j=0;x!=null && z!=null && i<x.length && j<z.length;) {
                        if (x[i].index<z[j].index) {
                                i++;
                        }
                        else if (z[j].index<x[i].index) {
                                j++;
                        }
                        else {
                                sum+=x[i].value*z[j].value;
                                i++;
                                j++;
                        }
                }
                return sum;
        }