diff --git a/src/encoder_advanced.hpp b/src/encoder_advanced.hpp index 389f706..7f10c22 100644 --- a/src/encoder_advanced.hpp +++ b/src/encoder_advanced.hpp @@ -18,39 +18,25 @@ #include "autogen_ldpc_QC.hpp" -void noise_bitstring_inplace(auto &src, double err_prob, unsigned int seed = 0) { - std::mt19937_64 rng{seed}; // hard-coded seed for testing purposes. - std::bernoulli_distribution distribution(err_prob); - - for (std::size_t i = 0; i < src.size(); i++) { - if (distribution(rng)) { - src[i] = !src[i]; - } else { - src[i] = src[i]; +namespace LDPC4QKD { + template + constexpr auto bits_needed() { + auto n = N; + std::size_t number_of_bits{0ul}; + while (n > 0) { + n >>= 1; + number_of_bits++; } + return number_of_bits; } -} - -template -constexpr auto bits_needed() { - auto n = N; - std::size_t number_of_bits{0ul}; - while (n > 0) { - n >>= 1; - number_of_bits++; - } - return number_of_bits; -} -template -using smallest_type = std::conditional_t() <= 8 * sizeof(std::uint8_t), std::uint8_t, - std::conditional_t() <= 8 * sizeof(std::uint16_t), std::uint16_t, - std::conditional_t() <= 8 * sizeof(std::uint32_t), std::uint32_t, std::uint64_t>>>; + template + using smallest_type = std::conditional_t() <= 8 * sizeof(std::uint8_t), std::uint8_t, + std::conditional_t() <= 8 * sizeof(std::uint16_t), std::uint16_t, + std::conditional_t() <= 8 * sizeof(std::uint32_t), std::uint32_t, std::uint64_t>>>; -namespace LDPC4QKD { - template constexpr bool xor_as_bools(Bit1 lhs, Bit2 rhs) { return (static_cast(lhs) != static_cast(rhs)); diff --git a/tests/test_encoder_advanced.cpp b/tests/test_encoder_advanced.cpp index e4401f5..10cd9f8 100644 --- a/tests/test_encoder_advanced.cpp +++ b/tests/test_encoder_advanced.cpp @@ -14,6 +14,22 @@ using namespace LDPC4QKD; +namespace { + void noise_bitstring_inplace(auto &src, double err_prob, unsigned int seed = 0) { + std::mt19937_64 rng{seed}; // hard-coded seed for testing purposes. + + std::bernoulli_distribution distribution(err_prob); + + for (std::size_t i = 0; i < src.size(); i++) { + if (distribution(rng)) { + src[i] = !src[i]; + } else { + src[i] = src[i]; + } + } + } +} + TEST(test_encoder_advanced, basic_example) { std::cout << "hello\n"; unsigned seed = 42; // seed for PRNG @@ -40,7 +56,7 @@ TEST(test_encoder_advanced, basic_example) { // Use the non-generic version of `encode_with`: std::cout << "Syndrome of runtime known size " << syndrome_vec.size() << std::endl; for (auto v: syndrome_vec) { - std::cout << static_cast(v) << ' '; // print syndrome bits + std::cout << static_cast(v) << ' '; // print syndrome bits } std::cout << std::endl; }