File indexing completed on 2025-08-02 08:28:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef G4AccUnorderedMap_h
0032 #define G4AccUnorderedMap_h 1
0033
0034 #include "G4VAccumulable.hh"
0035 #include "G4MergeMode.hh"
0036
0037 #include "globals.hh"
0038
0039 #include <unordered_map>
0040
0041 template <class Key,
0042 class T,
0043 class Hash = std::hash<Key>,
0044 class KeyEqual = std::equal_to<Key>,
0045 class Allocator = std::allocator<std::pair<const Key, T>>>
0046 class G4AccUnorderedMap : public G4VAccumulable
0047 {
0048 public:
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 G4AccUnorderedMap(const G4String& name = "",
0125 G4MergeMode mergeMode = G4MergeMode::kAddition);
0126
0127
0128
0129 G4AccUnorderedMap(std::size_t bucket_count,
0130 G4MergeMode mergeMode = G4MergeMode::kAddition,
0131 const Allocator& alloc = Allocator());
0132
0133
0134
0135 G4AccUnorderedMap(const G4String& name,
0136 std::size_t bucket_count,
0137 G4MergeMode mergeMode = G4MergeMode::kAddition,
0138 const Allocator& alloc = Allocator());
0139
0140
0141
0142 G4AccUnorderedMap(std::size_t bucket_count,
0143 const Allocator& alloc,
0144 G4MergeMode mergeMode = G4MergeMode::kAddition);
0145
0146
0147
0148 G4AccUnorderedMap(const G4String& name,
0149 std::size_t bucket_count,
0150 const Allocator& alloc,
0151 G4MergeMode mergeMode = G4MergeMode::kAddition);
0152
0153
0154 G4AccUnorderedMap(std::size_t bucket_count,
0155 const Hash& hash,
0156 const Allocator& alloc,
0157 G4MergeMode mergeMode = G4MergeMode::kAddition);
0158
0159
0160
0161 G4AccUnorderedMap(const G4String& name,
0162 std::size_t bucket_count,
0163 const Hash& hash,
0164 const Allocator& alloc,
0165 G4MergeMode mergeMode = G4MergeMode::kAddition);
0166
0167
0168 G4AccUnorderedMap(const Allocator& alloc,
0169 G4MergeMode mergeMode = G4MergeMode::kAddition);
0170
0171
0172
0173 G4AccUnorderedMap(const G4String& name,
0174 const Allocator& alloc,
0175 G4MergeMode mergeMode = G4MergeMode::kAddition);
0176
0177
0178
0179 G4AccUnorderedMap(std::initializer_list<std::pair<const Key,T>> init,
0180 G4MergeMode mergeMode = G4MergeMode::kAddition,
0181 std::size_t bucket_count = 0,
0182 const Hash& hash = Hash(),
0183 const KeyEqual& equal = KeyEqual(),
0184 const Allocator& alloc = Allocator() );
0185
0186
0187
0188 G4AccUnorderedMap(const G4String& name,
0189 std::initializer_list<std::pair<const Key,T>> init,
0190 G4MergeMode mergeMode = G4MergeMode::kAddition,
0191 std::size_t bucket_count = 0,
0192 const Hash& hash = Hash(),
0193 const KeyEqual& equal = KeyEqual(),
0194 const Allocator& alloc = Allocator() );
0195
0196
0197 G4AccUnorderedMap(const G4AccUnorderedMap& rhs) = default;
0198 G4AccUnorderedMap(const G4AccUnorderedMap& rhs, const Allocator& allocator);
0199
0200 G4AccUnorderedMap(G4AccUnorderedMap&& rhs) = default;
0201 G4AccUnorderedMap(G4AccUnorderedMap&& rhs, const Allocator& allocator);
0202
0203
0204 ~G4AccUnorderedMap() override = default;
0205
0206
0207
0208 inline T& operator[](const Key& key) { return fUMap[key]; }
0209 inline T& operator[](Key&& key) { return fUMap[std::move(key)]; }
0210
0211 inline T& at(const Key& key) { return fUMap[key]; }
0212 inline const T& at(const Key& key ) const { return fUMap[key]; }
0213
0214 inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::size_type size() const { return fUMap.size(); }
0215
0216 inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator begin() { return fUMap.begin(); }
0217 inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::const_iterator begin() const { return fUMap.begin(); }
0218 inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::const_iterator cbegin() const { return fUMap.cbegin(); }
0219
0220 inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator end() { return fUMap.end(); }
0221 inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::const_iterator end() const { return fUMap.end(); }
0222 inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::const_iterator cend() const { return fUMap.cend(); }
0223
0224 inline void clear() { fUMap.clear(); }
0225
0226 inline std::pair<typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator, bool> insert(const T& value) { return fUMap.insert(value); }
0227 template< class P >
0228 inline std::pair<typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator, bool> insert( P&& value ) { return fUMap.insert(std::move(value)); }
0229 inline std::pair<typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator, bool> insert( T&& value ) { return fUMap.insert(std::move(value)); }
0230
0231 inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator find( const Key& key ) { return fUMap.find(key); }
0232 inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::const_iterator find( const Key& key ) const { return fUMap.find(key); }
0233
0234
0235 void Merge(const G4VAccumulable& other) final;
0236 void Reset() final;
0237 void Print(G4PrintOptions options = G4PrintOptions()) const final;
0238 void SetMergeMode(G4MergeMode value) final;
0239 void SetInitValue(const T& value);
0240
0241
0242 G4AccType GetType() const final { return G4AccType::kUnorderedMap; }
0243 std::unordered_map<Key, T, Hash, KeyEqual, Allocator>& GetUnorderedMap() { return fUMap; }
0244 const std::unordered_map<Key, T, Hash, KeyEqual, Allocator>& GetUnorderedMap() const { return fUMap; }
0245
0246 private:
0247
0248 std::unordered_map<Key, T, Hash, KeyEqual, Allocator> fUMap;
0249 T fInitValue = 0;
0250 G4MergeFunction<T> fMergeFunction;
0251 };
0252
0253
0254
0255 #include "G4AccUnorderedMap.icc"
0256
0257 #endif