23
23
24
24
#include < algorithm>
25
25
#include < iostream>
26
- #include < iterator >
26
+ #include < utility >
27
27
#include < vector>
28
- #include < bitcoin/system/data/data .hpp>
28
+ #include < bitcoin/system/math/math .hpp>
29
29
30
+ // TODO: change to ipp and duck type streams for performance.
31
+ // TODO: not actually cryptographic functions, move to wallet.
30
32
// Avoid in header, circular dependency with stream to crypto.
31
33
#include < bitcoin/system/stream/stream.hpp>
32
34
@@ -37,8 +39,8 @@ namespace golomb {
37
39
static void encode (bitwriter& sink, uint64_t value,
38
40
uint8_t modulo_exponent) NOEXCEPT
39
41
{
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 )
42
44
sink.write_bit (true );
43
45
44
46
sink.write_bit (false );
@@ -49,10 +51,10 @@ static uint64_t decode(bitreader& source, uint8_t modulo_exponent) NOEXCEPT
49
51
{
50
52
uint64_t quotient = 0 ;
51
53
while (source.read_bit ())
52
- quotient++ ;
54
+ ++quotient ;
53
55
54
56
const auto remainder = source.read_bits (modulo_exponent);
55
- return (( quotient << modulo_exponent) + remainder ) ;
57
+ return shift_left ( quotient, modulo_exponent) + remainder ;
56
58
}
57
59
58
60
inline 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,
69
71
if (is_multiply_overflow (target_false_positive_rate, set_size))
70
72
return {};
71
73
72
- const auto bound = target_false_positive_rate * set_size;
73
74
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;
76
76
std::transform (items.begin (), items.end (), hashes.begin (),
77
77
[&](const data_chunk& item) NOEXCEPT
78
78
{
@@ -92,7 +92,7 @@ static void construct(bitwriter& sink, const data_stack& items, uint8_t bits,
92
92
target_false_positive_rate, entropy);
93
93
94
94
uint64_t previous = 0 ;
95
- for (auto value: set)
95
+ for (const auto value: set)
96
96
{
97
97
encode (sink, value - previous, bits);
98
98
previous = value;
0 commit comments