unsigned int bselect(bitRankW32Int * br,unsigned int x) { if(x==0) return 0; // returns i such that x=rank(i) && rank(i-1)<x or n if that i not exist // first binary search over first level rank structure // then sequential search using popcount over a int // then sequential search using popcount over a char // then sequential search bit a bit //binary search over first level rank structure unsigned int n= br->n; unsigned int s= br->s; unsigned int b=br->b; unsigned int l=0, r=n/s; unsigned int integers = br->integers; unsigned int factor = br->factor; unsigned int mid=(l+r)/2; unsigned int rankmid = br->Rs[mid]; while (l<=r) { if (rankmid<x) l = mid+1; else r = mid-1; mid = (l+r)/2; rankmid = br->Rs[mid]; } //sequential search using popcount over a int unsigned int left; left=mid*factor; x-=rankmid; unsigned int j=br->data[left]; unsigned int ones = popcount(j); while (ones < x) { x-=ones;left++; if (left > integers) return n; j = br->data[left]; ones = popcount(j); } //sequential search using popcount over a char left=left*b; rankmid = popcount8(j); if (rankmid < x) { j=j>>8; x-=rankmid; left+=8; rankmid = popcount8(j); if (rankmid < x) { j=j>>8; x-=rankmid; left+=8; rankmid = popcount8(j); if (rankmid < x) { j=j>>8; x-=rankmid; left+=8; }
bool MomentChi2Test ( struct HashInfo *info ) { pfHash hash = info->hash; const int size = info->hashbits / 8; const int step = 3; unsigned k = 0, s = 0; unsigned long l, h, x; unsigned mx = 0xfffffff0; long double sa=0, saa=0, sb=0, sbb=0, n = mx/step; hash(&k,sizeof(k),s,&l); printf("Running 1st unseeded MomentChi2 for the low 32bits/step %d ... ", step); fflush(NULL); for(unsigned i=1; i<=mx; i+=step){ hash(&i,sizeof(i),s,&h); x = popcount8(l^h); // check the lower 32bits only x = x*x*x*x*x; sa+=x; saa+=x*x; l=h; } sa/=n; saa=(saa/n-sa*sa)/n; printf("%Lf - %Lf\n", sa, saa); printf("Running 2nd seeded MomentChi2 for the low 32bits/step %d ... ", step); fflush(NULL); hash(&k,sizeof(k),s,&l); for(unsigned i=1; i<=mx; i+=step){ hash(&k,sizeof(k),i,&h); x = popcount8(l^h); x = x*x*x*x*x; sb+=x; sbb+=x*x; l=h; } sb/=n; sbb=(sbb/n-sb*sb)/n; double chi2=(sa-sb)*(sa-sb)/(saa+sbb); printf("%Lf - %Lf\nKeySeedMomentChi2:\t%g\t", sb, sbb, chi2); fflush(NULL); if (chi2 > 3.84145882069413) { printf("FAIL!!!!\n"); fflush(NULL); return false; } else { printf("PASS\n"); fflush(NULL); return true; } }