X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=results.c;h=4e7b4ec0b62751dbeef8e4f8dd6cadfdcb321996;hb=a223af3254fb51c279cfbccdc18c59484fdca74e;hp=1f1deda13bc3c66708a43d29494e9580419d9313;hpb=cad5e2e2831477cba1f6211c57b9a4cc5b58bd55;p=SXSI%2Fxpathcomp.git diff --git a/results.c b/results.c index 1f1deda..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