Skip to content

Commit a7eb521

Browse files
committed
Refactor and optimize (using fast streams) golomb and neutrino.
1 parent bd28bd7 commit a7eb521

6 files changed

Lines changed: 176 additions & 212 deletions

File tree

include/bitcoin/system/filter/golomb.hpp

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

25-
#include <iostream>
2625
#include <bitcoin/system/data/data.hpp>
2726
#include <bitcoin/system/define.hpp>
2827
#include <bitcoin/system/hash/hash.hpp>
28+
#include <bitcoin/system/stream/stream.hpp>
2929

3030
namespace libbitcoin {
3131
namespace system {
32-
namespace golomb {
3332

34-
// Golomb-coded set construction
35-
// ----------------------------------------------------------------------------
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+
};
3699

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

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.

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)