/root/bitcoin/src/util/vector.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2019-2022 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_VECTOR_H |
6 | | #define BITCOIN_UTIL_VECTOR_H |
7 | | |
8 | | #include <functional> |
9 | | #include <initializer_list> |
10 | | #include <optional> |
11 | | #include <type_traits> |
12 | | #include <utility> |
13 | | #include <vector> |
14 | | |
15 | | /** Construct a vector with the specified elements. |
16 | | * |
17 | | * This is preferable over the list initializing constructor of std::vector: |
18 | | * - It automatically infers the element type from its arguments. |
19 | | * - If any arguments are rvalue references, they will be moved into the vector |
20 | | * (list initialization always copies). |
21 | | */ |
22 | | template<typename... Args> |
23 | | inline std::vector<std::common_type_t<Args...>> Vector(Args&&... args) |
24 | 84.0k | { |
25 | 84.0k | std::vector<std::common_type_t<Args...>> ret; |
26 | 84.0k | ret.reserve(sizeof...(args)); |
27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html |
28 | 84.0k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; |
29 | 84.0k | return ret; |
30 | 84.0k | } _Z6VectorIJSt6vectorIhSaIhEEEES0_INSt11common_typeIJDpT_EE4typeESaIS7_EEDpOS4_ Line | Count | Source | 24 | 111 | { | 25 | 111 | std::vector<std::common_type_t<Args...>> ret; | 26 | 111 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 111 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 111 | return ret; | 30 | 111 | } |
_Z6VectorIJN10miniscript8internal6MaxIntIjEEEESt6vectorINSt11common_typeIJDpT_EE4typeESaIS9_EEDpOS6_ Line | Count | Source | 24 | 236 | { | 25 | 236 | std::vector<std::common_type_t<Args...>> ret; | 26 | 236 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 236 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 236 | return ret; | 30 | 236 | } |
_Z6VectorIJN10miniscript8internal7SatInfoEEESt6vectorINSt11common_typeIJDpT_EE4typeESaIS8_EEDpOS5_ Line | Count | Source | 24 | 118 | { | 25 | 118 | std::vector<std::common_type_t<Args...>> ret; | 26 | 118 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 118 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 118 | return ret; | 30 | 118 | } |
_Z6VectorIJ7CPubKeyEESt6vectorINSt11common_typeIJDpT_EE4typeESaIS6_EEDpOS3_ Line | Count | Source | 24 | 256 | { | 25 | 256 | std::vector<std::common_type_t<Args...>> ret; | 26 | 256 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 256 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 256 | return ret; | 30 | 256 | } |
_Z6VectorIJSt10unique_ptrIKN10miniscript4NodeI7CPubKeyEESt14default_deleteIS5_EEEESt6vectorINSt11common_typeIJDpT_EE4typeESaISE_EEDpOSB_ Line | Count | Source | 24 | 3.50k | { | 25 | 3.50k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.50k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 3.50k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.50k | return ret; | 30 | 3.50k | } |
_Z6VectorIJSt10unique_ptrIKN10miniscript4NodeI7CPubKeyEESt14default_deleteIS5_EES8_EESt6vectorINSt11common_typeIJDpT_EE4typeESaISE_EEDpOSB_ Line | Count | Source | 24 | 836 | { | 25 | 836 | std::vector<std::common_type_t<Args...>> ret; | 26 | 836 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 836 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 836 | return ret; | 30 | 836 | } |
_Z6VectorIJSt10unique_ptrIKN10miniscript4NodeI7CPubKeyEESt14default_deleteIS5_EES8_S8_EESt6vectorINSt11common_typeIJDpT_EE4typeESaISE_EEDpOSB_ Line | Count | Source | 24 | 3 | { | 25 | 3 | std::vector<std::common_type_t<Args...>> ret; | 26 | 3 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 3 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3 | return ret; | 30 | 3 | } |
Unexecuted instantiation: _Z6VectorIJRKN10miniscript8internal10InputStackEEESt6vectorINSt11common_typeIJDpT_EE4typeESaISA_EEDpOS7_ Unexecuted instantiation: _Z6VectorIJhEESt6vectorINSt11common_typeIJDpT_EE4typeESaIS5_EEDpOS2_ Unexecuted instantiation: miniscript.cpp:_Z6VectorIJN12_GLOBAL__N_119ScriptParserContext3KeyEEESt6vectorINSt11common_typeIJDpT_EE4typeESaIS8_EEDpOS5_ Unexecuted instantiation: miniscript.cpp:_Z6VectorIJSt10unique_ptrIKN10miniscript4NodeIN12_GLOBAL__N_119ScriptParserContext3KeyEEESt14default_deleteIS7_EEEESt6vectorINSt11common_typeIJDpT_EE4typeESaISG_EEDpOSD_ Unexecuted instantiation: miniscript.cpp:_Z6VectorIJSt10unique_ptrIKN10miniscript4NodeIN12_GLOBAL__N_119ScriptParserContext3KeyEEESt14default_deleteIS7_EESA_EESt6vectorINSt11common_typeIJDpT_EE4typeESaISG_EEDpOSD_ Unexecuted instantiation: miniscript.cpp:_Z6VectorIJSt10unique_ptrIKN10miniscript4NodeIN12_GLOBAL__N_119ScriptParserContext3KeyEEESt14default_deleteIS7_EESA_SA_EESt6vectorINSt11common_typeIJDpT_EE4typeESaISG_EEDpOSD_ descriptor.cpp:_Z6VectorIJSt10unique_ptrIN12_GLOBAL__N_114PubkeyProviderESt14default_deleteIS2_EEEESt6vectorINSt11common_typeIJDpT_EE4typeESaISB_EEDpOS8_ Line | Count | Source | 24 | 9.15k | { | 25 | 9.15k | std::vector<std::common_type_t<Args...>> ret; | 26 | 9.15k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 9.15k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 9.15k | return ret; | 30 | 9.15k | } |
_Z6VectorIJ7CScriptEESt6vectorINSt11common_typeIJDpT_EE4typeESaIS6_EEDpOS3_ Line | Count | Source | 24 | 33.8k | { | 25 | 33.8k | std::vector<std::common_type_t<Args...>> ret; | 26 | 33.8k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 33.8k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 33.8k | return ret; | 30 | 33.8k | } |
descriptor.cpp:_Z6VectorIJSt10unique_ptrIN12_GLOBAL__N_114DescriptorImplESt14default_deleteIS2_EEEESt6vectorINSt11common_typeIJDpT_EE4typeESaISB_EEDpOS8_ Line | Count | Source | 24 | 35.9k | { | 25 | 35.9k | std::vector<std::common_type_t<Args...>> ret; | 26 | 35.9k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 35.9k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 35.9k | return ret; | 30 | 35.9k | } |
Unexecuted instantiation: _Z6VectorIJRK7CScriptEESt6vectorINSt11common_typeIJDpT_EE4typeESaIS8_EEDpOS5_ Unexecuted instantiation: _Z6VectorIJSt10unique_ptrIKN10miniscript4NodeIjEESt14default_deleteIS4_EEEESt6vectorINSt11common_typeIJDpT_EE4typeESaISD_EEDpOSA_ Unexecuted instantiation: _Z6VectorIJjEESt6vectorINSt11common_typeIJDpT_EE4typeESaIS5_EEDpOS2_ Unexecuted instantiation: _Z6VectorIJSt10unique_ptrIKN10miniscript4NodeIjEESt14default_deleteIS4_EES7_EESt6vectorINSt11common_typeIJDpT_EE4typeESaISD_EEDpOSA_ Unexecuted instantiation: _Z6VectorIJSt10unique_ptrIKN10miniscript4NodeIjEESt14default_deleteIS4_EES7_S7_EESt6vectorINSt11common_typeIJDpT_EE4typeESaISD_EEDpOSA_ Unexecuted instantiation: _Z6VectorIJRSt6vectorIhSaIhEEEES0_INSt11common_typeIJDpT_EE4typeESaIS8_EEDpOS5_ Unexecuted instantiation: _Z6VectorIJ11XOnlyPubKeyEESt6vectorINSt11common_typeIJDpT_EE4typeESaIS6_EEDpOS3_ Unexecuted instantiation: _Z6VectorIJSt10unique_ptrIKN10miniscript4NodeI11XOnlyPubKeyEESt14default_deleteIS5_EEEESt6vectorINSt11common_typeIJDpT_EE4typeESaISE_EEDpOSB_ Unexecuted instantiation: _Z6VectorIJSt10unique_ptrIKN10miniscript4NodeI11XOnlyPubKeyEESt14default_deleteIS5_EES8_EESt6vectorINSt11common_typeIJDpT_EE4typeESaISE_EEDpOSB_ Unexecuted instantiation: _Z6VectorIJSt10unique_ptrIKN10miniscript4NodeI11XOnlyPubKeyEESt14default_deleteIS5_EES8_S8_EESt6vectorINSt11common_typeIJDpT_EE4typeESaISE_EEDpOSB_ Unexecuted instantiation: _Z6VectorIJRK7uint256RS0_EESt6vectorINSt11common_typeIJDpT_EE4typeESaIS9_EEDpOS6_ |
31 | | |
32 | | /** Concatenate two vectors, moving elements. */ |
33 | | template<typename V> |
34 | | inline V Cat(V v1, V&& v2) |
35 | 250 | { |
36 | 250 | v1.reserve(v1.size() + v2.size()); |
37 | 250 | for (auto& arg : v2) { |
38 | 214 | v1.push_back(std::move(arg)); |
39 | 214 | } |
40 | 250 | return v1; |
41 | 250 | } _Z3CatISt6vectorIS0_IhSaIhEESaIS2_EEET_S5_OS5_ Line | Count | Source | 35 | 250 | { | 36 | 250 | v1.reserve(v1.size() + v2.size()); | 37 | 250 | for (auto& arg : v2) { | 38 | 214 | v1.push_back(std::move(arg)); | 39 | 214 | } | 40 | 250 | return v1; | 41 | 250 | } |
Unexecuted instantiation: _Z3CatISt6vectorI9RPCResultSaIS1_EEET_S4_OS4_ Unexecuted instantiation: _Z3CatISt6vectorI6RPCArgSaIS1_EEET_S4_OS4_ Unexecuted instantiation: _Z3CatISt6vectorIPKcSaIS2_EEET_S5_OS5_ |
42 | | |
43 | | /** Concatenate two vectors. */ |
44 | | template<typename V> |
45 | | inline V Cat(V v1, const V& v2) |
46 | 0 | { |
47 | 0 | v1.reserve(v1.size() + v2.size()); |
48 | 0 | for (const auto& arg : v2) { |
49 | 0 | v1.push_back(arg); |
50 | 0 | } |
51 | 0 | return v1; |
52 | 0 | } |
53 | | |
54 | | /** Clear a vector (or std::deque) and release its allocated memory. */ |
55 | | template<typename V> |
56 | | inline void ClearShrink(V& v) noexcept |
57 | 0 | { |
58 | | // There are various ways to clear a vector and release its memory: |
59 | | // |
60 | | // 1. V{}.swap(v) |
61 | | // 2. v = V{} |
62 | | // 3. v = {}; v.shrink_to_fit(); |
63 | | // 4. v.clear(); v.shrink_to_fit(); |
64 | | // |
65 | | // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit() |
66 | | // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding |
67 | | // request. Therefore, we use method (1). |
68 | |
|
69 | 0 | V{}.swap(v); |
70 | 0 | } Unexecuted instantiation: _Z11ClearShrinkI8bitdequeILi32768EEEvRT_ Unexecuted instantiation: _Z11ClearShrinkISt5dequeI16CompressedHeaderSaIS1_EEEvRT_ Unexecuted instantiation: _Z11ClearShrinkISt6vectorIhSaIhEEEvRT_ Unexecuted instantiation: txgraph.cpp:_Z11ClearShrinkISt6vectorISt12_Node_handleIN12_GLOBAL__N_111TxGraphImpl9ChunkDataES4_SaISt13_Rb_tree_nodeIS4_EEESaIS8_EEEvRT_ |
71 | | |
72 | | template<typename V, typename L> |
73 | | inline std::optional<V> FindFirst(const std::vector<V>& vec, const L fnc) |
74 | 0 | { |
75 | 0 | for (const auto& el : vec) { |
76 | 0 | if (fnc(el)) { |
77 | 0 | return el; |
78 | 0 | } |
79 | 0 | } |
80 | 0 | return std::nullopt; |
81 | 0 | } Unexecuted instantiation: _Z9FindFirstI14AssumeutxoDataZNK12CChainParams19AssumeutxoForHeightEiEUlRKT_E_ESt8optionalIS2_ERKSt6vectorIS2_SaIS2_EET0_ Unexecuted instantiation: _Z9FindFirstI14AssumeutxoDataZNK12CChainParams22AssumeutxoForBlockhashERK7uint256EUlRKT_E_ESt8optionalIS5_ERKSt6vectorIS5_SaIS5_EET0_ |
82 | | |
83 | | #endif // BITCOIN_UTIL_VECTOR_H |