Warning, file /include/Geant4/G4AccUnorderedMap.icc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 #include <algorithm>
0030
0031
0032
0033
0034
0035
0036
0037 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0038 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0039 const G4String& name,
0040 G4MergeMode mergeMode)
0041 : G4VAccumulable(name, mergeMode),
0042 fUMap(),
0043 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0044 {
0045 if (G4Accumulables::VerboseLevel > 1 ) {
0046 G4cout << "G4AccUnorderedMap ctor1" << G4endl;
0047 }
0048 }
0049
0050
0051
0052 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0053 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0054 std::size_t bucket_count,
0055 G4MergeMode mergeMode,
0056 const Allocator& allocator)
0057 : G4VAccumulable(mergeMode),
0058 fUMap(bucket_count, allocator),
0059 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0060 {
0061 if (G4Accumulables::VerboseLevel > 1 ) {
0062 G4cout << "G4AccUnorderedMap ctor2" << G4endl;
0063 }
0064 }
0065
0066
0067
0068 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0069 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0070 const G4String& name,
0071 std::size_t bucket_count,
0072 G4MergeMode mergeMode,
0073 const Allocator& allocator)
0074 : G4VAccumulable(name, mergeMode),
0075 fUMap(bucket_count, allocator),
0076 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0077 {
0078 if (G4Accumulables::VerboseLevel > 1 ) {
0079 G4cout << "G4AccUnorderedMap ctor2n" << G4endl;
0080 }
0081 }
0082
0083
0084
0085 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0086 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0087 std::size_t bucket_count,
0088 const Allocator& allocator,
0089 G4MergeMode mergeMode)
0090 : G4VAccumulable(mergeMode),
0091 fUMap(bucket_count, allocator),
0092 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0093 {
0094 if (G4Accumulables::VerboseLevel > 1 ) {
0095 G4cout << "G4AccUnorderedMap ctor3" << G4endl;
0096 }
0097 }
0098
0099
0100
0101 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0102 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0103 const G4String& name,
0104 std::size_t bucket_count,
0105 const Allocator& allocator,
0106 G4MergeMode mergeMode)
0107 : G4VAccumulable(name, mergeMode),
0108 fUMap(bucket_count, allocator),
0109 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0110 {
0111 if (G4Accumulables::VerboseLevel > 1 ) {
0112 G4cout << "G4AccUnorderedMap ctor3n" << G4endl;
0113 }
0114 }
0115
0116
0117
0118 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0119 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0120 std::size_t bucket_count,
0121 const Hash& hash,
0122 const Allocator& allocator,
0123 G4MergeMode mergeMode)
0124 : G4VAccumulable(mergeMode),
0125 fUMap(bucket_count, hash, allocator),
0126 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0127 {
0128 if (G4Accumulables::VerboseLevel > 1 ) {
0129 G4cout << "G4AccUnorderedMap ctor4" << G4endl;
0130 }
0131 }
0132
0133
0134
0135 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0136 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0137 const G4String& name,
0138 std::size_t bucket_count,
0139 const Hash& hash,
0140 const Allocator& allocator,
0141 G4MergeMode mergeMode)
0142 : G4VAccumulable(name, mergeMode),
0143 fUMap(bucket_count, hash, allocator),
0144 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0145 {
0146 if (G4Accumulables::VerboseLevel > 1 ) {
0147 G4cout << "G4AccUnorderedMap ctor4n" << G4endl;
0148 }
0149 }
0150
0151
0152
0153 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0154 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0155 const Allocator& allocator,
0156 G4MergeMode mergeMode)
0157 : G4VAccumulable(mergeMode),
0158 fUMap(allocator),
0159 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0160 {
0161 if (G4Accumulables::VerboseLevel > 1 ) {
0162 G4cout << "G4AccUnorderedMap ctor5" << G4endl;
0163 }
0164 }
0165
0166
0167
0168 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0169 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0170 const G4String& name,
0171 const Allocator& allocator,
0172 G4MergeMode mergeMode)
0173 : G4VAccumulable(name, mergeMode),
0174 fUMap(allocator),
0175 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0176 {
0177 if (G4Accumulables::VerboseLevel > 1 ) {
0178 G4cout << "G4AccUnorderedMap ctor5n" << G4endl;
0179 }
0180 }
0181
0182
0183
0184 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0185 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0186 std::initializer_list<std::pair<const Key,T>> init,
0187 G4MergeMode mergeMode,
0188 std::size_t bucket_count,
0189 const Hash& hash,
0190 const KeyEqual& equal,
0191 const Allocator& allocator)
0192 : G4VAccumulable(mergeMode),
0193 fUMap(init, bucket_count, hash, equal, allocator),
0194 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0195 {
0196 if (G4Accumulables::VerboseLevel > 1 ) {
0197 G4cout << "G4AccUnorderedMap ctor13" << G4endl;
0198 }
0199 }
0200
0201
0202
0203 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0204 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0205 const G4String& name,
0206 std::initializer_list<std::pair<const Key,T>> init,
0207 G4MergeMode mergeMode,
0208 std::size_t bucket_count,
0209 const Hash& hash,
0210 const KeyEqual& equal,
0211 const Allocator& allocator)
0212 : G4VAccumulable(name, mergeMode),
0213 fUMap(init, bucket_count, hash, equal, allocator),
0214 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0215 {
0216 if (G4Accumulables::VerboseLevel > 1 ) {
0217 G4cout << "G4AccUnorderedMap ctor13n" << G4endl;
0218 }
0219 }
0220
0221
0222
0223 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0224 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0225 const G4AccUnorderedMap& rhs,
0226 const Allocator& allocator)
0227 : G4VAccumulable(rhs),
0228 fUMap(rhs, allocator),
0229 fMergeFunction(rhs.fMergeFunction)
0230 {}
0231
0232
0233
0234 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0235 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
0236 G4AccUnorderedMap&& rhs,
0237 const Allocator& allocator)
0238 : G4VAccumulable(std::move(rhs)),
0239 fUMap(std::move(rhs), allocator),
0240 fMergeFunction(rhs.fMergeFunction)
0241 {}
0242
0243
0244 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0245 void G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::Merge(const G4VAccumulable& other)
0246 {
0247 const auto& otherMap = static_cast<const G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>&>(other);
0248
0249 if (G4Accumulables::VerboseLevel > 2 ) {
0250 G4cout << "G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::Merge: " << G4endl;
0251 G4cout << "destination: ";
0252 for (const auto& [key, v] : fUMap) {
0253 G4cout << "[ " << key << ", " << v << " ], ";
0254 }
0255 G4cout << G4endl;
0256 G4cout << "merged data: ";
0257 for (const auto& [key, v] : otherMap.fUMap) {
0258 G4cout << "[ " << key << ", " << v << " ], ";
0259 }
0260 G4cout << G4endl;
0261 }
0262
0263 for (const auto& [key, value] : otherMap.fUMap) {
0264 if ( fUMap.find(key) == fUMap.end()) {
0265 (fUMap)[key] = value;
0266 }
0267 else {
0268 (fUMap)[key] = fMergeFunction((fUMap)[key], value);
0269 }
0270 }
0271 }
0272
0273
0274 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0275 void G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::Reset()
0276 {
0277 for (auto& [key, value] : fUMap) {
0278 fUMap[key] = fInitValue;
0279 }
0280 }
0281
0282
0283 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0284 void G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::Print(
0285 G4PrintOptions options) const
0286 {
0287 if (options.Has(G4PrintOptions::kType)) {
0288 G4cout << "unordered_map<" << typeid(Key).name() << ", " << typeid(T).name() << ">: ";
0289 }
0290
0291 PrintBase(options);
0292
0293 bool first = true;
0294 for (const auto& [key, value] : fUMap) {
0295 if (! first) { G4cout << ", "; }
0296 G4cout << "[ " << key << ", " << value << "] ";
0297 first = false;
0298 }
0299 G4cout << G4endl;
0300 }
0301
0302
0303 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0304 void G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::SetMergeMode(G4MergeMode value)
0305 {
0306 G4VAccumulable::SetMergeMode(value);
0307 fMergeFunction = G4Accumulables::GetMergeFunction<T>(fMergeMode);
0308 }
0309
0310
0311 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0312 void G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::SetInitValue(const T& value)
0313 {
0314 fInitValue = value;
0315 }