X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=results.c;h=4e7b4ec0b62751dbeef8e4f8dd6cadfdcb321996;hb=861944c24f8cad360fb9478cb0a15863cb52e803;hp=161f2956bf86ee75cc027f148717156fc30db21a;hpb=34c353ceb1b989394b9f8c09cfc4c1c51ab42bc4;p=SXSI%2Fxpathcomp.git diff --git a/results.c b/results.c index 161f295..4e7b4ec 100644 --- a/results.c +++ b/results.c @@ -26,8 +26,11 @@ results createResults (int n) { fprintf(stderr,"Error, redefine logW as %i and recompile\n",lg(W)-1); exit(1); } + 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)); R.tree = (int*) malloc (((R.n+W-1)/W)*sizeof(int)); clearBit(R.tree,0); // clear all return R; @@ -42,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 @@ -181,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 = -1; + int i = 0; + while ( i != -1 && i < R.n) { + result ++; + i = unconv(nextLarger(R.tree,R.n,conv(i+1,R.n,R.lgn),0,R.lgn),R.n,R.lgn); + }; + return result; + +} + + static void prnspace (int k) { while (k--) putchar(' ');