Skip to content

Commit 785a45c

Browse files
authored
Merge pull request #1639 from evoskuil/master
Refactor and optimize (using fast streams) golomb and neutrino.
2 parents 427f1c2 + a7eb521 commit 785a45c

7 files changed

Lines changed: 182 additions & 219 deletions

File tree

include/bitcoin/system/filter/golomb.hpp

Lines changed: 67 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,72 +22,81 @@
2222
#ifndef LIBBITCOIN_SYSTEM_FILTER_GOLOMB_HPP
2323
#define LIBBITCOIN_SYSTEM_FILTER_GOLOMB_HPP
2424

25-
#include <istream>
26-
#include <ostream>
2725
#include <bitcoin/system/data/data.hpp>
2826
#include <bitcoin/system/define.hpp>
2927
#include <bitcoin/system/hash/hash.hpp>
28+
#include <bitcoin/system/stream/stream.hpp>
3029

3130
namespace libbitcoin {
3231
namespace system {
33-
namespace golomb {
3432

35-
// Golomb-coded set construction
36-
// ----------------------------------------------------------------------------
33+
class BC_API golomb
34+
{
35+
public:
36+
37+
/// Golomb-coded set construction
38+
/// -----------------------------------------------------------------------
39+
40+
static void construct(bitwriter& writer, const data_stack& items,
41+
uint8_t bits, const siphash_key& entropy,
42+
uint64_t target_false_positive_rate) NOEXCEPT;
43+
44+
static data_chunk construct(const data_stack& items,
45+
uint8_t bits, const siphash_key& entropy,
46+
uint64_t target_false_positive_rate) NOEXCEPT;
47+
48+
static data_chunk construct(const data_stack& items,
49+
uint8_t bits, const half_hash& entropy,
50+
uint64_t target_false_positive_rate) NOEXCEPT;
51+
52+
/// Single element match
53+
/// -----------------------------------------------------------------------
54+
55+
static bool match_single(bitreader& reader,
56+
const data_chunk& target, uint64_t set_size,
57+
const siphash_key& entropy, uint8_t bits,
58+
uint64_t target_false_positive_rate) NOEXCEPT;
59+
60+
static bool match_single(const data_chunk& compressed_set,
61+
const data_chunk& target, uint64_t set_size,
62+
const half_hash& entropy, uint8_t bits,
63+
uint64_t target_false_positive_rate) NOEXCEPT;
64+
65+
static bool match_single(const data_chunk& compressed_set,
66+
const data_chunk& target, uint64_t set_size,
67+
const siphash_key& entropy, uint8_t bits,
68+
uint64_t target_false_positive_rate) NOEXCEPT;
69+
70+
/// Intersection match
71+
/// -----------------------------------------------------------------------
72+
73+
static bool match_stack(bitreader& reader,
74+
const data_stack& targets, uint64_t set_size,
75+
const siphash_key& entropy, uint8_t bits,
76+
uint64_t target_false_positive_rate) NOEXCEPT;
77+
78+
static bool match_stack(const data_chunk& compressed_set,
79+
const data_stack& targets, uint64_t set_size,
80+
const half_hash& entropy, uint8_t bits,
81+
uint64_t target_false_positive_rate) NOEXCEPT;
82+
83+
static bool match_stack(const data_chunk& compressed_set,
84+
const data_stack& targets, uint64_t set_size,
85+
const siphash_key& entropy, uint8_t bits,
86+
uint64_t target_false_positive_rate) NOEXCEPT;
87+
88+
private:
89+
static void encode(bitwriter& writer, uint64_t value,
90+
uint8_t modulo_exponent) NOEXCEPT;
91+
static uint64_t decode(bitreader& reader,
92+
uint8_t modulo_exponent) NOEXCEPT;
93+
static uint64_t hash_to_range(const data_slice& item,
94+
uint64_t bound, const siphash_key& key) NOEXCEPT;
95+
static std::vector<uint64_t> hashed_set_construct(const data_stack& items,
96+
uint64_t set_size, uint64_t target_false_positive_rate,
97+
const siphash_key& key) NOEXCEPT;
98+
};
3799

38-
BC_API data_chunk construct(const data_stack& items, uint8_t bits,
39-
const half_hash& entropy, uint64_t target_false_positive_rate) NOEXCEPT;
40-
41-
BC_API data_chunk construct(const data_stack& items, uint8_t bits,
42-
const siphash_key& entropy, uint64_t target_false_positive_rate) NOEXCEPT;
43-
44-
BC_API void construct(std::ostream& stream, const data_stack& items,
45-
uint8_t bits, const half_hash& entropy,
46-
uint64_t target_false_positive_rate) NOEXCEPT;
47-
48-
BC_API void construct(std::ostream& stream, const data_stack& items,
49-
uint8_t bits, const siphash_key& entropy,
50-
uint64_t target_false_positive_rate) NOEXCEPT;
51-
52-
// Single element match
53-
// ----------------------------------------------------------------------------
54-
55-
BC_API bool match(const data_chunk& target, const data_chunk& compressed_set,
56-
uint64_t set_size, const half_hash& entropy, uint8_t bits,
57-
uint64_t target_false_positive_rate) NOEXCEPT;
58-
59-
BC_API bool match(const data_chunk& target, const data_chunk& compressed_set,
60-
uint64_t set_size, const siphash_key& entropy, uint8_t bits,
61-
uint64_t target_false_positive_rate) NOEXCEPT;
62-
63-
BC_API bool match(const data_chunk& target, std::istream& compressed_set,
64-
uint64_t set_size, const half_hash& entropy, uint8_t bits,
65-
uint64_t target_false_positive_rate) NOEXCEPT;
66-
67-
BC_API bool match(const data_chunk& target, std::istream& compressed_set,
68-
uint64_t set_size, const siphash_key& entropy, uint8_t bits,
69-
uint64_t target_false_positive_rate) NOEXCEPT;
70-
71-
// Intersection match
72-
// ----------------------------------------------------------------------------
73-
74-
BC_API bool match(const data_stack& targets, const data_chunk& compressed_set,
75-
uint64_t set_size, const half_hash& entropy, uint8_t bits,
76-
uint64_t target_false_positive_rate) NOEXCEPT;
77-
78-
BC_API bool match(const data_stack& targets, const data_chunk& compressed_set,
79-
uint64_t set_size, const siphash_key& entropy, uint8_t bits,
80-
uint64_t target_false_positive_rate) NOEXCEPT;
81-
82-
BC_API bool match(const data_stack& targets, std::istream& compressed_set,
83-
uint64_t set_size, const half_hash& entropy, uint8_t bits,
84-
uint64_t target_false_positive_rate) NOEXCEPT;
85-
86-
BC_API bool match(const data_stack& targets, std::istream& compressed_set,
87-
uint64_t set_size, const siphash_key& entropy, uint8_t bits,
88-
uint64_t target_false_positive_rate) NOEXCEPT;
89-
90-
} // namespace golomb
91100
} // namespace system
92101
} // namespace libbitcoin
93102

include/bitcoin/system/stream/streamers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace write
118118
/// A bit writer that writes to a std::ostream.
119119
using ostream = bit_writer<std::ostream>;
120120

121-
/// A fast bit writer that writes to a std::ostream.
121+
/// A fast bit writer that writes to a system::ostream.
122122
using fast = bit_writer<system::ostream<>>;
123123

124124
/// A bit writer that copies to a data_slab.

include/bitcoin/system/wallet/neutrino.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ struct BC_API block_filter
3939
data_chunk filter;
4040
};
4141

42-
bool BC_API compute_filter(data_chunk& out,
42+
BC_API bool compute_filter(data_chunk& out,
4343
const chain::block& block) NOEXCEPT;
4444

45-
hash_digest BC_API compute_filter_header(const hash_digest& previous_header,
45+
BC_API hash_digest compute_filter_header(const hash_digest& previous_header,
4646
const data_chunk& filter) NOEXCEPT;
4747

48-
bool BC_API match_filter(const block_filter& filter,
48+
BC_API bool match_filter(const block_filter& filter,
4949
const chain::script& script) NOEXCEPT;
5050

51-
bool BC_API match_filter(const block_filter& filter,
51+
BC_API bool match_filter(const block_filter& filter,
5252
const chain::scripts& scripts) NOEXCEPT;
5353

54-
bool BC_API match_filter(const block_filter& filter,
54+
BC_API bool match_filter(const block_filter& filter,
5555
const wallet::payment_address& address) NOEXCEPT;
5656

57-
bool BC_API match_filter(const block_filter& filter,
57+
BC_API bool match_filter(const block_filter& filter,
5858
const wallet::payment_address::list& addresses) NOEXCEPT;
5959

6060
} // namespace neutrino

src/define.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@
5555
// /radix : /words
5656
// /serial : /radix
5757
// /hash : /radix /endian
58-
// /filter : /hash
5958
// /crypto : /hash
6059
// /stream : /crypto /endian /error
60+
// /filter : /stream
6161
// /chain : /stream forks [forward: settings]
6262
// /machine : /chain
6363
// /config : /chain
64-
// /wallet : /chain
64+
// /wallet : /chain filter
6565
// settings : /chain forks
6666

6767
// When a symbol is unexplainably undefined, its defining include is probably

0 commit comments

Comments
 (0)