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

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



Steffen Möller pushed to branch master 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
- - - - -
230f58a9 by Steffen Möller at 2020-07-26T23:54:28+02:00
Update upstream source from tag 'upstream/1.0_alpha.1+2020072524git5390b6c'

Update to upstream version '1.0~alpha.1+2020072524git5390b6c'
with Debian dir f64c9e356757d57c94e03712d99b4c89af0c6369
- - - - -
e9c3d482 by Steffen Möller at 2020-07-27T00:07:29+02:00
Added dep on hopscotch-map, fixed install

- - - - -


10 changed files:

- debian/changelog
- debian/control
- + debian/libxxsds-dynamic-dev.install
- + debian/patches/series
- + debian/patches/useOurHopscotchMap.patch
- debug.cpp
- include/dynamic/internal/hacked_vector.hpp
- include/dynamic/internal/packed_vector.hpp
- include/dynamic/internal/wm_string.hpp
- wm_string.cpp


Changes:

=====================================
debian/changelog
=====================================
@@ -1,7 +1,5 @@
-xxsds-dynamic (1.0~alpha.1-1) UNRELEASED; urgency=medium
+xxsds-dynamic (1.0~alpha.1+2020072524git5390b6c-1) UNRELEASED; urgency=medium
 
   * Initial release (Closes: #965272)
-    BLOCKER: Wait for upstream to react to core dumps
-             https://github.com/xxsds/DYNAMIC/issues/24
 
  -- Steffen Moeller <moeller at debian.org>  Sat, 18 Jul 2020 16:40:45 +0200


=====================================
debian/control
=====================================
@@ -1,7 +1,9 @@
 Source: xxsds-dynamic
 Priority: optional
 Maintainer: Steffen Moeller <moeller at debian.org>
-Build-Depends: debhelper-compat (= 12)
+Build-Depends: debhelper-compat (= 12),
+               cmake,
+               libtsl-hopscotch-map-dev
 Standards-Version: 4.5.0
 Section: libs
 Homepage: https://github.com/xxsds/DYNAMIC


=====================================
debian/libxxsds-dynamic-dev.install
=====================================
@@ -0,0 +1 @@
+include/dynamic usr/include/


=====================================
debian/patches/series
=====================================
@@ -0,0 +1 @@
+useOurHopscotchMap.patch


=====================================
debian/patches/useOurHopscotchMap.patch
=====================================
@@ -0,0 +1,31 @@
+Index: xxsds-dynamic/CMakeLists.txt
+===================================================================
+--- xxsds-dynamic.orig/CMakeLists.txt
++++ xxsds-dynamic/CMakeLists.txt
+@@ -14,24 +14,14 @@ project (dynamic)
+ 
+ include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
+ 
+-# hopscotch_map
+-ExternalProject_Add(hopscotch_map
+-  GIT_REPOSITORY "https://github.com/Tessil/hopscotch-map.git"
+-  BUILD_IN_SOURCE TRUE
+-  CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR} # TODO ADD static build flag
+-  UPDATE_COMMAND ""
+-  INSTALL_COMMAND ""
+-  BUILD_COMMAND ""
+-  CONFIGURE_COMMAND "")
+-ExternalProject_Get_property(hopscotch_map INSTALL_DIR)
+-set(hopscotch_map_INCLUDE "${INSTALL_DIR}/src/hopscotch_map/include/")
++set(hopscotch_map_INCLUDE "/usr/include/tsl")
+ 
+ include_directories(${PROJECT_SOURCE_DIR}/include)
+ #include_directories(${PROJECT_SOURCE_DIR}/include/dynamic)
+ #include_directories(${PROJECT_SOURCE_DIR}/include/dynamic/internal)
+ #include_directories(${PROJECT_SOURCE_DIR}/include/dynamic/algorithms)
+ #include_directories(${PROJECT_SOURCE_DIR}/include/dynamic/algorithms/cw-bwt)
+-include_directories(${INSTALL_DIR}/src/hopscotch_map/include)
++#include_directories(${INSTALL_DIR}/src/hopscotch_map/include)
+ 
+ message("Building in ${CMAKE_BUILD_TYPE} mode")
+ 


=====================================
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/-/compare/f7a4e37026989d5a758232458a517013b74734d1...e9c3d4823465a6ee0fadb1bd4922c16b56506841

-- 
View it on GitLab: https://salsa.debian.org/med-team/xxsds-dynamic/-/compare/f7a4e37026989d5a758232458a517013b74734d1...e9c3d4823465a6ee0fadb1bd4922c16b56506841
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/c4049979/attachment-0001.html>


More information about the debian-med-commit mailing list