[med-svn] [Git][med-team/xxsds-dynamic][upstream] New upstream version 1.0~alpha.1+2020072524git5390b6c

Steffen Möller gitlab at salsa.debian.org
Sun Jul 26 23:08:08 BST 2020



Steffen Möller pushed to branch upstream at Debian Med / xxsds-dynamic


Commits:
441819a5 by Steffen Möller at 2020-07-26T23:54:27+02:00
New upstream version 1.0~alpha.1+2020072524git5390b6c
- - - - -


5 changed files:

- debug.cpp
- include/dynamic/internal/hacked_vector.hpp
- include/dynamic/internal/packed_vector.hpp
- include/dynamic/internal/wm_string.hpp
- wm_string.cpp


Changes:

=====================================
debug.cpp
=====================================
@@ -11,14 +11,14 @@ int main() {
    dyn::succinct_spsi spsi;
    dyn::spsi_check<> check;
 
-   int n=40000;
+   int n=100000;
    int sigma=120;
 
    srand(time(NULL));
 
    for(int i=0;i<n;++i){
 
-	   cout << i << endl;
+	   cout << "insert number " << i << endl;
 
 	   int j = rand()%(i+1);
 	   int x = rand()%sigma;
@@ -35,5 +35,24 @@ int main() {
     }
 
 
+
+   for(int i=0;i<n/2;++i){
+
+	   cout << "remove number " << i << endl;
+
+	   int j = rand()%spsi.size();
+
+	   spsi.remove(j);
+	   check.remove(j);
+
+   }
+
+   for(int i=0;i<spsi.size();++i){
+
+ 	   assert(spsi[i]==check[i]);
+
+    }
+
+
    return 0;
 }


=====================================
include/dynamic/internal/hacked_vector.hpp
=====================================
@@ -228,7 +228,7 @@ public:
             }
         }
 
-        //shift ints left, from position i + 1 onwords
+        //shift ints left, from position i + 1 onwards
         shift_left( i );
 
 	 


=====================================
include/dynamic/internal/packed_vector.hpp
=====================================
@@ -129,10 +129,10 @@ namespace dyn{
 
 	 words = vector<uint64_t>( size_/int_per_word_ +  ( size_%int_per_word_ != 0 ) );
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+	 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+	 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+            && "uninitialized non-zero values in the end of the vector");
       }
 
       packed_vector(vector<uint64_t>&& _words, uint64_t size, uint8_t width) {
@@ -148,10 +148,10 @@ namespace dyn{
 
 	 psum_=psum(size_-1);
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+	 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+	 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+            && "uninitialized non-zero values in the end of the vector");
       }
 
       virtual ~packed_vector() {}
@@ -423,47 +423,60 @@ namespace dyn{
 
       }
 
-      void remove(uint64_t i) {
-        assert(i < size_);
-        auto x = this->at(i);
+     void remove(uint64_t i) {
+
+		 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+		 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                    || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+                && "uninitialized non-zero values in the end of the vector");
 
-	 if (width_>1) { // otherwise, cannot rebuild
-	    if (bitsize(x) == width_) {
+         assert(i < size_);
+         auto x = this->at(i);
 
-	       uint8_t max_b = 0;
+		 if (width_>1) { // otherwise, cannot rebuild
+			if (bitsize(x) == width_) {
 
-	       for(ulint j = 0; j < size_ ;++j){
-		  if (j != i) {
-		     auto x = this->at(j);
+				uint8_t max_b = 0;
 
-		     uint8_t bs = bitsize(x);
+				for(ulint j = 0; j < size_ ;++j){
+				  if (j != i) {
+					 auto x = this->at(j);
 
-		     if(bs>max_b) max_b=bs;
-		  }
-	       
-	       }
+					 uint8_t bs = bitsize(x);
 
-	       //rebuild entire vector
-	       rebuild_rem( i, max_b );
+					 if(bs>max_b) max_b=bs;
+				  }
 
-	       return;
+				}
 
-	    }
-	 }
+				//rebuild entire vector
+				rebuild_rem( i, max_b );
 
-	 //shift ints left, from position i + 1 onwords
-	 shift_left( i );
+				return;
 
-	 --size_;
-	 psum_ -= x;
+			}
+		 }
 
-        while ( words.size() > size_ / int_per_word_ + extra_ ) {
+		 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+		 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                    || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+                && "uninitialized non-zero values in the end of the vector");
+
+		 //shift ints left, from position i + 1 onwards
+		 shift_left( i );
+
+		 //set_without_psum_update(size_-1, 0);
+
+		 --size_;
+		 psum_ -= x;
+
+		 while ( words.size() > size_ / int_per_word_  + (size_%int_per_word_!=0) + extra_ ) {
             words.pop_back();
-        }
+		 }
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
+		 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+		 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                    || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
                 && "uninitialized non-zero values in the end of the vector");
 
       }
@@ -503,10 +516,10 @@ namespace dyn{
 	 psum_+=x;
 	 ++size_;
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+	 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+	 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+            && "uninitialized non-zero values in the end of the vector");
       }
 
       void insert_word(uint64_t i,
@@ -580,10 +593,10 @@ namespace dyn{
 	 psum_+=x;
 	 size_++;
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+	 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+	 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+            && "uninitialized non-zero values in the end of the vector");
       }
 
       uint64_t size() const {
@@ -599,6 +612,11 @@ namespace dyn{
 	*/
 	packed_vector* split(){
 
+		 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+		 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                   || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+               && "uninitialized non-zero values in the end of the vector");
+
 		uint64_t tot_words = (size_/int_per_word_) + (size_%int_per_word_!=0);
 
 		assert(tot_words <= words.size());
@@ -632,10 +650,10 @@ namespace dyn{
 		words.shrink_to_fit();
 		words[size_ / int_per_word_] &= ((~uint64_t(0)) >> (64 - ((size_ % int_per_word_) * width_)));
 
-		assert(size_ / int_per_word_ <= words.size());
-		assert((size_ / int_per_word_ == words.size()
-				|| !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-			&& "uninitialized non-zero values in the end of the vector");
+		 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+		 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                   || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+               && "uninitialized non-zero values in the end of the vector");
 
 		return right;
 
@@ -663,10 +681,10 @@ namespace dyn{
 	 //insert x inside i-th position
 	 words[word_nr] |= (x<<(width_*pos));
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+	 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+	 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+            && "uninitialized non-zero values in the end of the vector");
       }
 
       /*
@@ -736,10 +754,10 @@ namespace dyn{
 
 	 in.read((char*)&int_per_word_,sizeof(int_per_word_));
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+	 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+	 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+            && "uninitialized non-zero values in the end of the vector");
       }
 
       uint64_t width() const {
@@ -859,9 +877,15 @@ namespace dyn{
       //from the (i + 1)-st.
       void shift_left(uint64_t i){
 
+ 		 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+ 		 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                     || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+                 && "uninitialized non-zero values in the end of the vector");
+
+
 	 //number of integers that fit in a memory word
 	 assert(int_per_word_>0);
-        assert(i < size_);
+     assert(i < size_);
 
 	 if (i == (size_ - 1)) {
 	    set_without_psum_update( i, 0 );
@@ -901,6 +925,13 @@ namespace dyn{
             set_without_psum_update(j * int_per_word_ + int_per_word_ - 1, falling_in_idx);
         }
 
+
+		 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+		 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                   || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+               && "uninitialized non-zero values in the end of the vector");
+
+
       }
 
       // Rebuilds entire vector, setting j to value y
@@ -946,10 +977,10 @@ namespace dyn{
 	 width_ = new_width_;
 	 int_per_word_ = new_int_per_word_;
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+	 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+	 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+            && "uninitialized non-zero values in the end of the vector");
       }
 
       // Rebuilds entire vector, removing j from the vector
@@ -962,10 +993,10 @@ namespace dyn{
 	    int_per_word_ = 0;
 	    psum_ = 0;
 
-           assert(size_ / int_per_word_ <= words.size());
-           assert((size_ / int_per_word_ == words.size()
-                       || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                   && "uninitialized non-zero values in the end of the vector");
+		 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+		 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                   || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+               && "uninitialized non-zero values in the end of the vector");
 	    return;
 	 }
 	 
@@ -1001,10 +1032,10 @@ namespace dyn{
 	 width_ = new_width_;
 	 int_per_word_ = new_int_per_word_;
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+	 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+	 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+            && "uninitialized non-zero values in the end of the vector");
       }
 
       // Rebuilds entire vector, inserting y at position j
@@ -1058,10 +1089,10 @@ namespace dyn{
 
 	 words.assign( new_words.begin(), new_words.end() );
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+	 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+	 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+            && "uninitialized non-zero values in the end of the vector");
       }
       
       void rebuild(packed_vector& vec){
@@ -1086,10 +1117,10 @@ namespace dyn{
 
 	 }
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+	 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+	 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+            && "uninitialized non-zero values in the end of the vector");
 
       }
 
@@ -1171,11 +1202,10 @@ public:
             words[(size_ - 1) / int_per_word_] |= static_cast<uint64_t>(1) << ((size_ - 1) % 64);
             psum_++;
         }
-
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+		 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+		 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                   || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+               && "uninitialized non-zero values in the end of the vector");
     }
 
     virtual void set_without_psum_update(uint64_t i, uint64_t x) override final {
@@ -1218,10 +1248,10 @@ public:
 
         auto right = new packed_bit_vector(std::move(right_words), nr_right_ints);
 
-        assert(size_ / int_per_word_ <= words.size());
-        assert((size_ / int_per_word_ == words.size()
-                    || !(words[size_ / int_per_word_] >> ((size_ % int_per_word_) * width_)))
-                && "uninitialized non-zero values in the end of the vector");
+		 assert(size_ / int_per_word_ + (size_%int_per_word_!=0) <= words.size());
+		 assert((size_ / int_per_word_ + (size_%int_per_word_!=0) == words.size()
+                   || !(words[words.size()-1] >> ((size_ % int_per_word_) * width_)))
+               && "uninitialized non-zero values in the end of the vector");
 
         return right;
     }


=====================================
include/dynamic/internal/wm_string.hpp
=====================================
@@ -196,9 +196,9 @@ public:
 
     // i番目のcの位置 + 1を返す。rankは1-origin
     ulint select(ulint rank, ulint c) const {
-        --rank; // hmm
         assert(rank > 0);
         assert(c < sigma);
+        --rank;
 
         ulint left = 0;
         for (ulint i = 0; i < bit_width; ++i) {


=====================================
wm_string.cpp
=====================================
@@ -1,19 +1,16 @@
 #include <bits/stdc++.h>
+#include <random>
 #include "dynamic/dynamic.hpp"
 
 using namespace std;
 
-unsigned long randxor(){
-    static unsigned long x=123456789,y=362436069,z=521288629,w=88675123;
-    unsigned long t;
-    t=(x^(x<<11));x=y;y=z;z=w;
-    return( w=(w^(w>>19))^(t^(t>>8)) );
-}
-
 double speed_access(uint64_t num, uint64_t num_of_alphabet) {
     vector<uint64_t> data(num);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data[i] = (uint64_t)randxor() % num_of_alphabet;
+        data[i] = alpha_distrib(gen);
     }
 
     dyn::wm_str wm(num_of_alphabet, data);
@@ -35,16 +32,20 @@ double speed_access(uint64_t num, uint64_t num_of_alphabet) {
 
 double speed_rank(uint64_t num, uint64_t num_of_alphabet) {
     vector<uint64_t> data(num);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data[i] = (uint64_t)randxor() % num_of_alphabet;
+        data[i] = alpha_distrib(gen);
     }
 
     dyn::wm_str wm(num_of_alphabet, data);
 
+    std::uniform_int_distribution<uint64_t> data_distrib(0, num-1);
     int dummy = 0;
     auto start = std::chrono::system_clock::now();
     for (uint64_t rank = 1; rank < data.size(); ++rank) {
-        uint64_t val = data[randxor() % num];
+        uint64_t val = data[data_distrib(gen)];
         if (wm.rank(rank, val) == -1) {
             dummy++;
         }
@@ -59,18 +60,24 @@ double speed_rank(uint64_t num, uint64_t num_of_alphabet) {
 
 double speed_select(uint64_t num, uint64_t num_of_alphabet) {
     vector<uint64_t> data(num), count(num_of_alphabet, 0);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data[i] = (uint64_t)randxor() % num_of_alphabet;
+        data[i] = alpha_distrib(gen);
         count[data[i]]++;
     }
 
     dyn::wm_str wm(num_of_alphabet, data);
 
+    std::uniform_int_distribution<uint64_t> data_distrib(0, num-1);
     int dummy = 0;
     auto start = std::chrono::system_clock::now();
     for (int i = 0; i < num; ++i) {
-        uint64_t val = data[randxor() % num];
-        uint64_t rank  = randxor() % count.at(val) + 1;
+        uint64_t val = data[data_distrib(gen)];
+        std::uniform_int_distribution<uint64_t> rank_distrib(1, count.at(val));
+        uint64_t rank  = rank_distrib(gen);
+        //std::cerr << "select(" << rank << ", " << val << ")" << std::endl;
         if (wm.select(rank, val) == -1) {
             dummy++;
         }
@@ -85,21 +92,23 @@ double speed_select(uint64_t num, uint64_t num_of_alphabet) {
 
 double speed_remove(uint64_t num, uint64_t num_of_alphabet) {
     vector<uint64_t> data;
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data.emplace_back((uint64_t)randxor() % num_of_alphabet);
+        data.emplace_back(alpha_distrib(gen));
     }
 
     dyn::wm_str dwm(num_of_alphabet, data);
 
     auto start = std::chrono::system_clock::now();
     for (int i = 0; i < num; ++i) {
-        uint64_t pos = i == 0 ? 0 : randxor() % dwm.size();
+        std::uniform_int_distribution<uint64_t> pos_distrib(0, dwm.size()-1);
+        uint64_t pos = pos_distrib(gen);
         dwm.remove(pos);
     }
     auto end = std::chrono::system_clock::now();
-    if (dwm.at(0) == 1) {
-        cout << "dummy" << endl;
-    }
+    assert(dwm.size() == 0);
 
     return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
 }
@@ -107,10 +116,15 @@ double speed_remove(uint64_t num, uint64_t num_of_alphabet) {
 double speed_insert(uint64_t num, uint64_t num_of_alphabet) {
 
     dyn::wm_str dwm(num_of_alphabet);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
+
     auto start = std::chrono::system_clock::now();
     for (int i = 0; i < num; ++i) {
-        uint64_t pos = i == 0 ? 0 : randxor() % i;
-        uint64_t c = randxor() % num_of_alphabet;
+        std::uniform_int_distribution<uint64_t> pos_distrib(0, dwm.size());
+        uint64_t pos = pos_distrib(gen);
+        uint64_t c = alpha_distrib(gen);
         dwm.insert(pos, c);
     }
     auto end = std::chrono::system_clock::now();
@@ -122,17 +136,22 @@ double speed_insert(uint64_t num, uint64_t num_of_alphabet) {
 }
 
 double speed_update(uint64_t num, uint64_t num_of_alphabet) {
-    vector<uint64_t> data;
+
+    vector<uint64_t> data(num);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data.emplace_back((uint64_t)randxor() % num_of_alphabet);
+        data[i] = alpha_distrib(gen);
     }
 
     dyn::wm_str dwm(num_of_alphabet, data);
+    std::uniform_int_distribution<uint64_t> pos_distrib(0, dwm.size()-1);
 
     auto start = std::chrono::system_clock::now();
     for (int i = 0; i < num - 1; ++i) {
-        uint64_t pos = randxor() % data.size();
-        uint64_t c = randxor() % num_of_alphabet;
+        uint64_t pos = pos_distrib(gen);
+        uint64_t c = alpha_distrib(gen);
         dwm.update(pos, c);
     }
     auto end = std::chrono::system_clock::now();
@@ -145,8 +164,11 @@ double speed_update(uint64_t num, uint64_t num_of_alphabet) {
 
 bool test_access(uint64_t num, uint64_t num_of_alphabet) {
     vector<uint64_t> data(num);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data[i] = (uint64_t)randxor() % num_of_alphabet;
+        data[i] = alpha_distrib(gen);
     }
 
     dyn::wm_str wm(num_of_alphabet, data);
@@ -160,8 +182,11 @@ bool test_access(uint64_t num, uint64_t num_of_alphabet) {
 
 bool test_rank(uint64_t num, uint64_t num_of_alphabet) {
     vector<uint64_t> data(num);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data[i] = (uint64_t)randxor() % num_of_alphabet;
+        data[i] = alpha_distrib(gen);
     }
 
     dyn::wm_str wm(num_of_alphabet, data);
@@ -187,13 +212,13 @@ bool test_rank(uint64_t num, uint64_t num_of_alphabet) {
 
 bool test_select(uint64_t num, uint64_t num_of_alphabet) {
     vector<uint64_t> data(num), count(num_of_alphabet, 0);
-    //cerr << "data: ";
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data[i] = (uint64_t)randxor() % num_of_alphabet;
-        //cerr << data[i] << " ";
+        data[i] = alpha_distrib(gen);
         count[data[i]]++;
     }
-    //cerr << endl;
 
     dyn::wm_str wm(num_of_alphabet, data);
 
@@ -270,15 +295,20 @@ bool same(dyn::wm_str expected, dyn::wm_str actual) {
 }
 
 bool test_remove(uint64_t num, uint64_t num_of_alphabet) {
-    vector<uint64_t> data;
+    vector<uint64_t> data(num);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data.emplace_back((uint64_t)randxor() % num_of_alphabet);
+        data[i] = alpha_distrib(gen);
     }
 
     dyn::wm_str actual(num_of_alphabet, data);
 
     for (int i = 0; i < num; ++i) {
-        uint64_t pos = i == 0 ? 0 : randxor() % data.size();
+        std::uniform_int_distribution<uint64_t> pos_distrib(0, actual.size()-1);
+        uint64_t pos = pos_distrib(gen);
+
         data.erase(data.begin() + pos);
 
         dyn::wm_str expected(num_of_alphabet, data);
@@ -295,10 +325,15 @@ bool test_remove(uint64_t num, uint64_t num_of_alphabet) {
 bool test_insert(uint64_t num, uint64_t num_of_alphabet) {
 
     dyn::wm_str actual(num_of_alphabet);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
+
     vector<uint64_t> data;
     for (int i = 0; i < num; ++i) {
-        uint64_t pos = data.size() == 0 ? 0 : randxor() % data.size();
-        uint64_t c = randxor() % num_of_alphabet;
+        std::uniform_int_distribution<uint64_t> pos_distrib(0, actual.size()-1);
+        uint64_t pos = pos_distrib(gen);
+        uint64_t c = alpha_distrib(gen);
 
         data.insert(data.begin() + pos, c);
 
@@ -315,15 +350,19 @@ bool test_insert(uint64_t num, uint64_t num_of_alphabet) {
 
 bool test_update(uint64_t num, uint64_t num_of_alphabet) {
     vector<uint64_t> data(num);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data[i] = (uint64_t)randxor() % num_of_alphabet;
+        data[i] = alpha_distrib(gen);
     }
 
     dyn::wm_str actual(num_of_alphabet, data);
+    std::uniform_int_distribution<uint64_t> pos_distrib(0, actual.size()-1);
 
     for (int i = 0; i < num - 1; ++i) {
-        uint64_t pos = randxor() % data.size();
-        uint64_t c = randxor() % num_of_alphabet;
+        uint64_t pos = pos_distrib(gen);
+        uint64_t c = alpha_distrib(gen);
         data[pos] = c;
 
         dyn::wm_str expected(num_of_alphabet, data);
@@ -339,8 +378,11 @@ bool test_update(uint64_t num, uint64_t num_of_alphabet) {
 
 bool test_serialize(uint64_t num, uint64_t num_of_alphabet) {
     vector<uint64_t> data(num);
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(0, num_of_alphabet-1);
     for (int i = 0; i < num; ++i) {
-        data[i] = (uint64_t)randxor() % num_of_alphabet;
+        data[i] = alpha_distrib(gen);
     }
 
     dyn::wm_str expected(num_of_alphabet, data);
@@ -373,15 +415,12 @@ void speed_test(uint64_t num, uint64_t num_of_alphabet) {
 
 bool test(uint64_t num, uint64_t num_of_alphabet) {
     bool ok = true;
-
-    cout << "test access:" << ((ok &= test_access(num, num_of_alphabet)) ? "OK" : "NG") << endl;
-    cout << "test rank:" << ((ok &= test_rank(num, num_of_alphabet)) ? "OK" : "NG") << endl;
-    cout << "test select:" << ((ok &= test_select(num, num_of_alphabet)) ? "OK" : "NG") << endl;
-    cout << "test erase:" << (test_remove(num, num_of_alphabet) ? "OK" : "NG") << endl;
-    cout << "test insert:" << (test_insert(num, num_of_alphabet) ? "OK" : "NG") << endl;
-    cout << "test update:" << (test_update(num, num_of_alphabet) ? "OK" : "NG") << endl;
-    cout << "test serialize:" << (test_serialize(num, num_of_alphabet) ? "OK" : "NG") << endl;
-
+    ok &= test_access(num, num_of_alphabet);
+    ok &= test_rank(num, num_of_alphabet);
+    ok &= test_select(num, num_of_alphabet);
+    ok &= test_remove(num, num_of_alphabet);
+    ok &= test_update(num, num_of_alphabet);
+    ok &= test_serialize(num, num_of_alphabet);
     return ok;
 }
 
@@ -390,19 +429,27 @@ int main() {
     uint64_t num = 100000;
     uint64_t num_of_alphabet = 10000000;
 
-    cout << "SPEED" << endl;
+    cout << "SPEED alpha=100" << endl;
+    speed_test(num, 100);
+    cout << "SPEED alpha=" << num_of_alphabet << endl;
     speed_test(num, num_of_alphabet);
 
     cout << "TEST" << endl;
-    for (int i = 0; i < 1000; ++i) {
-        cout << "Test:" << i << endl;
-        num = randxor() % 100 + 1;
-        num_of_alphabet = randxor() % 50 + 1;
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<uint64_t> alpha_distrib(1, 1000);
+    std::uniform_int_distribution<uint64_t> len_distrib(1, 100);
+
+    for (int i = 0; i < 100; ++i) {
+        num = len_distrib(gen);
+        num_of_alphabet = alpha_distrib(gen);
+        cout << "TEST size=" << num << " alpha=" << num_of_alphabet << endl;
         if (not test(num, num_of_alphabet)) {
-            cout << "ERROR" << endl;
+            cout << "ERROR!" << std::endl;
             break;
         }
     }
+    cout << "OK" << endl;
 
     return 0;
 }



View it on GitLab: https://salsa.debian.org/med-team/xxsds-dynamic/-/commit/441819a572de3112a26efc6a93b6604334d88971

-- 
View it on GitLab: https://salsa.debian.org/med-team/xxsds-dynamic/-/commit/441819a572de3112a26efc6a93b6604334d88971
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20200726/f458809e/attachment-0001.html>


More information about the debian-med-commit mailing list