X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=results.c;h=4e7b4ec0b62751dbeef8e4f8dd6cadfdcb321996;hb=0c2338bfcdae0df1c68112a10247dc4e68a483ff;hp=7570e5ab3c38bbd3ee1f481a9f2d7f348f796524;hpb=cf6d366b25132eea7b0f1966c11d034d748af0fa;p=SXSI%2Fxpathcomp.git diff --git a/results.c b/results.c index 7570e5a..4e7b4ec 100644 --- a/results.c +++ b/results.c @@ -29,8 +29,8 @@ results createResults (int n) R.n = 2*n-1; R.lgn = lg(n); - fprintf(stderr,"Size of the result set : %i elements, %li kB\n", n, - (((R.n+W-1)/W)*sizeof(int)/1024)); + //fprintf(stderr,"Size of the result set : %i elements, %li kB\n", n, + //(((R.n+W-1)/W)*sizeof(int)/1024)); R.tree = (int*) malloc (((R.n+W-1)/W)*sizeof(int)); clearBit(R.tree,0); // clear all return R; @@ -45,15 +45,13 @@ void freeResults (results R) static int conv (int p, int n, int lgn) { int t = n+1-(1<>1; + return (p < t) ? p : (p+t)>>1; } int readResult (results R, int p) // returns 0 or 1 @@ -184,9 +182,9 @@ static int nextLarger (int *tree, int n, int p, int pos, int pot) { int answ; if (!getBit(tree,pos)) return -1; // no answer - pot--; pos = (pos<<1)+1; if (pos >= n) return 0; // when n is not a power of 2, missing leaves + pot--; if ((p>>pot) == 0) // p goes left { answ = nextLarger(tree,n,p&~(1< R.n) return -1; // next(last), p+1 out of bounds answ = nextLarger(R.tree,R.n,conv(p+1,R.n,R.lgn),0,R.lgn); - if (answ == -1) return -1; - return unconv(answ,R.n,R.lgn); + return (answ == -1) ? -1 : unconv(answ,R.n,R.lgn); } // Naively implemented by kim unsigned int countResult(results R) { - unsigned int result = 0; + unsigned int result = -1; int i = 0; while ( i != -1 && i < R.n) { result ++;