improvements...
[SXSI/XMLTree.git] / libcds / tests / static_bitsequence_tester.cpp
index bd801ed..509107d 100644 (file)
@@ -65,6 +65,7 @@ void load(char *fname, uint ** text, uint * n) {
 
 void test_bitsequence(uint * bitseq, uint len, static_bitsequence * bs) {
   uint ones = 0;
+       uint last_one = 0;
   bool error = false;
   for(uint i=0;i<len && !error;i++) {
     //cout << "i="<<i<< endl;
@@ -72,7 +73,20 @@ void test_bitsequence(uint * bitseq, uint len, static_bitsequence * bs) {
       if(i%max((uint)1,(bs->length()/100))==0) { cout << "."; cout.flush(); }
       if(i%max((uint)1,(bs->length()/10))==0) { cout << endl; cout.flush(); }
     }
-    if(bitget(bitseq,i)) ones++;
+    if(bitget(bitseq,i)) {
+                       for(uint k=last_one; !error && k<i;k++) {
+                               if(bs->select_next1(k)!=i) {
+                                       uint ans= bs->select_next1(k);
+                                       cout << "Error select_next1" << endl;
+                                       cout << " got: (k=" << k << ") " << ans << " expected: " << i << endl;
+                                       cout << " rank(" << k << ")=" << bs->rank1(k) << " access(" << k << ")=" << bs->access(k) << endl;
+                                       cout << " rank(" << ans << ")=" << bs->rank1(ans) << " access(" << ans << ")=" << bs->access(ans) << endl;
+                                       error = true;
+                               }
+                       }
+                       last_one = i;
+                       ones++;
+               }
     if(bs->access(i) != (bitget(bitseq,i)!=0)) {
       cout << "Access error for position " << i << endl;
       cout << " got: " << bs->access(i) << " expected: " << (bitget(bitseq,i)!=0) << endl;
@@ -178,3 +192,18 @@ void speed_select1(static_bitsequence * ss, uint * bitseq, uint n) {
   cout << " * Time per select1: " << 1000*t/NQUERIES << " msecs" << endl;
   cout << " - Check sum: " << acc << endl;
 }
+
+void speed_selectnext1(static_bitsequence * ss, uint * bitseq, uint n) {
+  uint acc=0;
+  srand(SEED);
+
+  start_clock();
+  for(uint i=0;i<NQUERIES;i++) {
+    uint pos = rand()%n;
+    acc += ss->select_next1(pos);
+  }
+  double t = stop_clock();
+  cout << " * Time for " << NQUERIES << " select_next1s: " << t << " secs" << endl;
+  cout << " * Time per select_next1: " << 1000*t/NQUERIES << " msecs" << endl;
+  cout << " - Check sum: " << acc << endl;
+}