From a86e0e294db3019b8104c5a93506e2f08bc54a58 Mon Sep 17 00:00:00 2001 From: Yuri Gorshenin Date: Fri, 30 Jun 2017 20:30:56 +0300 Subject: [PATCH] Review fixes. --- base/base_tests/bwt_tests.cpp | 23 +++++++++++++++++++++++ base/bwt.cpp | 1 + base/suffix_array.cpp | 6 ++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/base/base_tests/bwt_tests.cpp b/base/base_tests/bwt_tests.cpp index 2338da3cc2..3a5d4c2fbb 100644 --- a/base/base_tests/bwt_tests.cpp +++ b/base/base_tests/bwt_tests.cpp @@ -3,6 +3,7 @@ #include "base/bwt.hpp" #include +#include #include using namespace base; @@ -64,4 +65,26 @@ UNIT_TEST(RevBWT_Smoke) TEST_EQUAL(s, RevRevBWT(s), ()); } } + +UNIT_TEST(RevBWT_AllBytes) +{ + int kSeed = 42; + int kMin = 1; + int kMax = 10; + + mt19937 engine(kSeed); + uniform_int_distribution uid(kMin, kMax); + + string s; + for (size_t i = 0; i < 256; ++i) + { + auto const count = uid(engine); + ASSERT_GREATER_OR_EQUAL(count, kMin, ()); + ASSERT_LESS_OR_EQUAL(count, kMax, ()); + for (int j = 0; j < count; ++j) + s.push_back(static_cast(i)); + } + shuffle(s.begin(), s.end(), engine); + TEST_EQUAL(s, RevRevBWT(s), ()); +} } // namespace diff --git a/base/bwt.cpp b/base/bwt.cpp index c416f673ad..0e56763adc 100644 --- a/base/bwt.cpp +++ b/base/bwt.cpp @@ -29,6 +29,7 @@ class FirstColumn public: FirstColumn(size_t n, uint8_t const * s) : m_n(n), m_starts({}) { + m_starts.fill(0); for (size_t i = 0; i < n; ++i) ++m_starts[s[i]]; diff --git a/base/suffix_array.cpp b/base/suffix_array.cpp index 7e5f5355ea..d77a473f78 100644 --- a/base/suffix_array.cpp +++ b/base/suffix_array.cpp @@ -60,6 +60,8 @@ struct SkewWrapper return 0; } + size_t MaxValue() const { return static_cast(numeric_limits::max()) + 1; } + size_t const m_n; uint8_t const * const m_s; }; @@ -241,8 +243,8 @@ namespace base { void Skew(size_t n, uint8_t const * s, size_t * sa) { - auto const maxValue = static_cast(numeric_limits::max()); - RawSkew(n, maxValue, SkewWrapper(n, s), sa); + SkewWrapper wrapper(n, s); + RawSkew(n, wrapper.MaxValue(), wrapper, sa); } void Skew(string const & s, vector & sa)