2323
2424#include < algorithm>
2525#include < iostream>
26- #include < iterator >
26+ #include < utility >
2727#include < vector>
28- #include < bitcoin/system/data/data .hpp>
28+ #include < bitcoin/system/math/math .hpp>
2929
30+ // TODO: change to ipp and duck type streams for performance.
31+ // TODO: not actually cryptographic functions, move to wallet.
3032// Avoid in header, circular dependency with stream to crypto.
3133#include < bitcoin/system/stream/stream.hpp>
3234
@@ -37,8 +39,8 @@ namespace golomb {
3739static void encode (bitwriter& sink, uint64_t value,
3840 uint8_t modulo_exponent) NOEXCEPT
3941{
40- const uint64_t quotient = value >> modulo_exponent;
41- for (uint64_t index = 0 ; index < quotient; index++ )
42+ const auto quotient = shift_right ( value, modulo_exponent) ;
43+ for (uint64_t index = 0 ; index < quotient; ++index )
4244 sink.write_bit (true );
4345
4446 sink.write_bit (false );
@@ -49,10 +51,10 @@ static uint64_t decode(bitreader& source, uint8_t modulo_exponent) NOEXCEPT
4951{
5052 uint64_t quotient = 0 ;
5153 while (source.read_bit ())
52- quotient++ ;
54+ ++quotient ;
5355
5456 const auto remainder = source.read_bits (modulo_exponent);
55- return (( quotient << modulo_exponent) + remainder) ;
57+ return shift_left ( quotient, modulo_exponent) + remainder;
5658}
5759
5860inline uint64_t hash_to_range (const data_slice& item, uint64_t bound,
@@ -69,10 +71,8 @@ static std::vector<uint64_t> hashed_set_construct(const data_stack& items,
6971 if (is_multiply_overflow (target_false_positive_rate, set_size))
7072 return {};
7173
72- const auto bound = target_false_positive_rate * set_size;
7374 std::vector<uint64_t > hashes (items.size ());
74-
75- // C++17: parallel policy for std::transform.
75+ const auto bound = target_false_positive_rate * set_size;
7676 std::transform (items.begin (), items.end (), hashes.begin (),
7777 [&](const data_chunk& item) NOEXCEPT
7878 {
@@ -92,7 +92,7 @@ static void construct(bitwriter& sink, const data_stack& items, uint8_t bits,
9292 target_false_positive_rate, entropy);
9393
9494 uint64_t previous = 0 ;
95- for (auto value: set)
95+ for (const auto value: set)
9696 {
9797 encode (sink, value - previous, bits);
9898 previous = value;
0 commit comments