Skip to content

Commit cf79677

Browse files
authored
Merge pull request #1634 from evoskuil/master
Style, comments.
2 parents 84b6db6 + e1b2af8 commit cf79677

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

src/crypto/golomb_coding.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
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 {
3739
static 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

5860
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,
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;

src/wallet/neutrino_filter.cpp

+5-13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ namespace libbitcoin {
3131
namespace system {
3232
namespace neutrino {
3333

34+
// iostreams
35+
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
36+
3437
// Golomb-Rice related values (bip158).
3538
constexpr uint8_t golomb_bits = 19;
3639
constexpr uint64_t golomb_target_false_positive_rate = 784931;
@@ -74,18 +77,11 @@ bool compute_filter(data_chunk& out, const chain::block& block) NOEXCEPT
7477
// Order and remove duplicates.
7578
distinct(scripts);
7679

77-
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
7880
stream::out::data stream(out);
79-
BC_POP_WARNING()
80-
8181
write::bytes::ostream writer(stream);
8282
writer.write_variable(scripts.size());
8383
golomb::construct(stream, scripts, golomb_bits, key, rate);
84-
85-
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
8684
stream.flush();
87-
BC_POP_WARNING()
88-
8985
return true;
9086
}
9187

@@ -101,10 +97,7 @@ bool match_filter(const block_filter& filter,
10197
if (script.ops().empty())
10298
return false;
10399

104-
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
105100
stream::in::copy stream(filter.filter);
106-
BC_POP_WARNING()
107-
108101
read::bytes::istream reader(stream);
109102
const auto set_size = reader.read_variable();
110103

@@ -138,10 +131,7 @@ bool match_filter(const block_filter& filter,
138131
if (stack.empty())
139132
return false;
140133

141-
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
142134
stream::in::copy stream(filter.filter);
143-
BC_POP_WARNING()
144-
145135
read::bytes::istream reader(stream);
146136
const auto set_size = reader.read_variable();
147137

@@ -178,6 +168,8 @@ bool match_filter(const block_filter& filter,
178168
return match_filter(filter, stack);
179169
}
180170

171+
BC_POP_WARNING()
172+
181173
} // namespace neutrino
182174
} // namespace system
183175
} // namespace libbitcoin

0 commit comments

Comments
 (0)