File tree Expand file tree Collapse file tree 4 files changed +49
-2
lines changed Expand file tree Collapse file tree 4 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,7 @@ BITCOIN_CORE_H = \
183
183
txmempool.h \
184
184
ui_interface.h \
185
185
undo.h \
186
+ util/bytevectorhash.h \
186
187
util/system.h \
187
188
util/memory.h \
188
189
util/moneystr.h \
@@ -429,6 +430,7 @@ libbitcoin_util_a_SOURCES = \
429
430
support/cleanse.cpp \
430
431
sync.cpp \
431
432
threadinterrupt.cpp \
433
+ util/bytevectorhash.cpp \
432
434
util/system.cpp \
433
435
util/moneystr.cpp \
434
436
util/strencodings.cpp \
Original file line number Diff line number Diff line change 5
5
#ifndef BITCOIN_BLOCKFILTER_H
6
6
#define BITCOIN_BLOCKFILTER_H
7
7
8
- #include < set>
9
8
#include < stdint.h>
9
+ #include < unordered_set>
10
10
#include < vector>
11
11
12
12
#include < primitives/block.h>
13
13
#include < serialize.h>
14
14
#include < uint256.h>
15
15
#include < undo.h>
16
+ #include < util/bytevectorhash.h>
16
17
17
18
/* *
18
19
* This implements a Golomb-coded set as defined in BIP 158. It is a
@@ -22,7 +23,7 @@ class GCSFilter
22
23
{
23
24
public:
24
25
typedef std::vector<unsigned char > Element;
25
- typedef std::set <Element> ElementSet;
26
+ typedef std::unordered_set <Element, ByteVectorHash > ElementSet;
26
27
27
28
private:
28
29
uint64_t m_siphash_k0;
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2018 The Bitcoin Core developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ #include < crypto/siphash.h>
6
+ #include < random.h>
7
+ #include < util/bytevectorhash.h>
8
+
9
+ ByteVectorHash::ByteVectorHash ()
10
+ {
11
+ GetRandBytes (reinterpret_cast <unsigned char *>(&m_k0), sizeof (m_k0));
12
+ GetRandBytes (reinterpret_cast <unsigned char *>(&m_k1), sizeof (m_k1));
13
+ }
14
+
15
+ size_t ByteVectorHash::operator ()(const std::vector<unsigned char >& input) const
16
+ {
17
+ return CSipHasher (m_k0, m_k1).Write (input.data (), input.size ()).Finalize ();
18
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2018 The Bitcoin Core developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ #ifndef BITCOIN_UTIL_BYTEVECTORHASH_H
6
+ #define BITCOIN_UTIL_BYTEVECTORHASH_H
7
+
8
+ #include < stdint.h>
9
+ #include < vector>
10
+
11
+ /* *
12
+ * Implementation of Hash named requirement for types that internally store a byte array. This may
13
+ * be used as the hash function in std::unordered_set or std::unordered_map over such types.
14
+ * Internally, this uses a random instance of SipHash-2-4.
15
+ */
16
+ class ByteVectorHash final
17
+ {
18
+ private:
19
+ uint64_t m_k0, m_k1;
20
+
21
+ public:
22
+ ByteVectorHash ();
23
+ size_t operator ()(const std::vector<unsigned char >& input) const ;
24
+ };
25
+
26
+ #endif // BITCOIN_UTIL_BYTEVECTORHASH_H
You can’t perform that action at this time.
0 commit comments