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.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /analysis/accumulables/include/G4AccUnorderedMap.icc (Version 11.3.0) and /analysis/accumulables/include/G4AccUnorderedMap.icc (Version 5.0)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26                                                   
 27 // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS    
 28                                                   
 29 #include <algorithm>                              
 30                                                   
 31 //                                                
 32 // public functions                               
 33 //                                                
 34                                                   
 35 // Default constructor (1)                        
 36 //____________________________________________    
 37 template <class Key, class T, class Hash, clas    
 38 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
 39   const G4String& name,                           
 40   G4MergeMode mergeMode)                          
 41 : G4VAccumulable(name, mergeMode),                
 42   fUMap(),                                        
 43   fMergeFunction(GetMergeFunction<T>(mergeMode    
 44 {                                                 
 45   if (G4Accumulables::VerboseLevel > 1 ) {        
 46     G4cout << "G4AccUnorderedMap ctor1" << G4e    
 47   }                                               
 48 }                                                 
 49                                                   
 50 // Constructor (2)                                
 51 //____________________________________________    
 52 template <class Key, class T, class Hash, clas    
 53 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
 54   std::size_t bucket_count,                       
 55   G4MergeMode mergeMode,                          
 56   const Allocator& allocator)                     
 57 : G4VAccumulable(mergeMode),                      
 58   fUMap(bucket_count, allocator),                 
 59   fMergeFunction(GetMergeFunction<T>(mergeMode    
 60 {                                                 
 61   if (G4Accumulables::VerboseLevel > 1 ) {        
 62     G4cout << "G4AccUnorderedMap ctor2" << G4e    
 63   }                                               
 64 }                                                 
 65                                                   
 66 // Constructor (2) with name                      
 67 //____________________________________________    
 68 template <class Key, class T, class Hash, clas    
 69 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
 70   const G4String& name,                           
 71   std::size_t bucket_count,                       
 72   G4MergeMode mergeMode,                          
 73   const Allocator& allocator)                     
 74 : G4VAccumulable(name, mergeMode),                
 75   fUMap(bucket_count, allocator),                 
 76   fMergeFunction(GetMergeFunction<T>(mergeMode    
 77 {                                                 
 78   if (G4Accumulables::VerboseLevel > 1 ) {        
 79     G4cout << "G4AccUnorderedMap ctor2n" << G4    
 80   }                                               
 81 }                                                 
 82                                                   
 83 // Constructor (3)                                
 84 //____________________________________________    
 85 template <class Key, class T, class Hash, clas    
 86 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
 87   std::size_t bucket_count,                       
 88   const Allocator& allocator,                     
 89   G4MergeMode mergeMode)                          
 90 : G4VAccumulable(mergeMode),                      
 91   fUMap(bucket_count, allocator),                 
 92   fMergeFunction(GetMergeFunction<T>(mergeMode    
 93 {                                                 
 94   if (G4Accumulables::VerboseLevel > 1 ) {        
 95     G4cout << "G4AccUnorderedMap ctor3" << G4e    
 96   }                                               
 97 }                                                 
 98                                                   
 99 // Constructor (3) with name                      
100 //____________________________________________    
101 template <class Key, class T, class Hash, clas    
102 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
103   const G4String& name,                           
104   std::size_t bucket_count,                       
105   const Allocator& allocator,                     
106   G4MergeMode mergeMode)                          
107 : G4VAccumulable(name, mergeMode),                
108   fUMap(bucket_count, allocator),                 
109   fMergeFunction(GetMergeFunction<T>(mergeMode    
110 {                                                 
111   if (G4Accumulables::VerboseLevel > 1 ) {        
112     G4cout << "G4AccUnorderedMap ctor3n" << G4    
113   }                                               
114 }                                                 
115                                                   
116 // Constructor (4)                                
117 //____________________________________________    
118 template <class Key, class T, class Hash, clas    
119 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
120   std::size_t bucket_count,                       
121   const Hash& hash,                               
122   const Allocator& allocator,                     
123   G4MergeMode mergeMode)                          
124 : G4VAccumulable(mergeMode),                      
125   fUMap(bucket_count, hash, allocator),           
126   fMergeFunction(GetMergeFunction<T>(mergeMode    
127 {                                                 
128   if (G4Accumulables::VerboseLevel > 1 ) {        
129     G4cout << "G4AccUnorderedMap ctor4" << G4e    
130   }                                               
131 }                                                 
132                                                   
133 // Constructor (4) with name                      
134 //____________________________________________    
135 template <class Key, class T, class Hash, clas    
136 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
137   const G4String& name,                           
138   std::size_t bucket_count,                       
139   const Hash& hash,                               
140   const Allocator& allocator,                     
141   G4MergeMode mergeMode)                          
142 : G4VAccumulable(name, mergeMode),                
143   fUMap(bucket_count, hash, allocator),           
144   fMergeFunction(GetMergeFunction<T>(mergeMode    
145 {                                                 
146   if (G4Accumulables::VerboseLevel > 1 ) {        
147     G4cout << "G4AccUnorderedMap ctor4n" << G4    
148   }                                               
149 }                                                 
150                                                   
151 // Constructor (5)                                
152 //____________________________________________    
153 template <class Key, class T, class Hash, clas    
154 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
155   const Allocator& allocator,                     
156   G4MergeMode mergeMode)                          
157 : G4VAccumulable(mergeMode),                      
158   fUMap(allocator),                               
159   fMergeFunction(GetMergeFunction<T>(mergeMode    
160 {                                                 
161   if (G4Accumulables::VerboseLevel > 1 ) {        
162     G4cout << "G4AccUnorderedMap ctor5" << G4e    
163   }                                               
164 }                                                 
165                                                   
166 // Constructor (5) with name                      
167 //____________________________________________    
168 template <class Key, class T, class Hash, clas    
169 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
170   const G4String& name,                           
171   const Allocator& allocator,                     
172   G4MergeMode mergeMode)                          
173 : G4VAccumulable(name, mergeMode),                
174   fUMap(allocator),                               
175   fMergeFunction(GetMergeFunction<T>(mergeMode    
176 {                                                 
177   if (G4Accumulables::VerboseLevel > 1 ) {        
178     G4cout << "G4AccUnorderedMap ctor5n" << G4    
179   }                                               
180 }                                                 
181                                                   
182 // Constructor (13)                               
183 //____________________________________________    
184 template <class Key, class T, class Hash, clas    
185 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
186   std::initializer_list<std::pair<const Key,T>    
187   G4MergeMode mergeMode,                          
188   std::size_t bucket_count,                       
189   const Hash& hash,                               
190   const KeyEqual& equal,                          
191   const Allocator& allocator)                     
192 : G4VAccumulable(mergeMode),                      
193   fUMap(init, bucket_count, hash, equal, alloc    
194   fMergeFunction(GetMergeFunction<T>(mergeMode    
195 {                                                 
196   if (G4Accumulables::VerboseLevel > 1 ) {        
197     G4cout << "G4AccUnorderedMap ctor13" << G4    
198   }                                               
199 }                                                 
200                                                   
201 // Constructor (13) with name                     
202 //____________________________________________    
203 template <class Key, class T, class Hash, clas    
204 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
205   const G4String& name,                           
206   std::initializer_list<std::pair<const Key,T>    
207   G4MergeMode mergeMode,                          
208   std::size_t bucket_count,                       
209   const Hash& hash,                               
210   const KeyEqual& equal,                          
211   const Allocator& allocator)                     
212 : G4VAccumulable(name, mergeMode),                
213   fUMap(init, bucket_count, hash, equal, alloc    
214   fMergeFunction(GetMergeFunction<T>(mergeMode    
215 {                                                 
216   if (G4Accumulables::VerboseLevel > 1 ) {        
217     G4cout << "G4AccUnorderedMap ctor13n" << G    
218   }                                               
219 }                                                 
220                                                   
221 // Copy ctor                                      
222 //____________________________________________    
223 template <class Key, class T, class Hash, clas    
224 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
225   const G4AccUnorderedMap& rhs,                   
226   const Allocator& allocator)                     
227 : G4VAccumulable(rhs),                            
228   fUMap(rhs, allocator),                          
229   fMergeFunction(rhs.fMergeFunction)              
230 {}                                                
231                                                   
232 // Move ctor                                      
233 //____________________________________________    
234 template <class Key, class T, class Hash, clas    
235 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo    
236   G4AccUnorderedMap&& rhs,                        
237   const Allocator& allocator)                     
238 : G4VAccumulable(std::move(rhs)),                 
239   fUMap(std::move(rhs), allocator),               
240   fMergeFunction(rhs.fMergeFunction)              
241 {}                                                
242                                                   
243 //____________________________________________    
244 template <class Key, class T, class Hash, clas    
245 void G4AccUnorderedMap<Key, T, Hash, KeyEqual,    
246 {                                                 
247   const auto& otherMap = static_cast<const G4A    
248                                                   
249   if (G4Accumulables::VerboseLevel > 2 ) {        
250     G4cout << "G4AccUnorderedMap<Key, T, Hash,    
251     G4cout << "destination: ";                    
252     for (const auto& [key, v] : fUMap) {          
253       G4cout << "[ " << key << ", " << v << "     
254     }                                             
255     G4cout << G4endl;                             
256     G4cout << "merged data: ";                    
257     for (const auto& [key, v] : otherMap.fUMap    
258       G4cout << "[ " << key << ", " << v << "     
259     }                                             
260     G4cout << G4endl;                             
261   }                                               
262                                                   
263   for (const auto& [key, value] : otherMap.fUM    
264     if ( fUMap.find(key) == fUMap.end()) {        
265       (fUMap)[key] = value;                       
266     }                                             
267     else {                                        
268       (fUMap)[key] = fMergeFunction((fUMap)[ke    
269     }                                             
270   }                                               
271 }                                                 
272                                                   
273 //____________________________________________    
274 template <class Key, class T, class Hash, clas    
275 void G4AccUnorderedMap<Key, T, Hash, KeyEqual,    
276 {                                                 
277   for (auto& [key, value] : fUMap) {              
278     fUMap[key] = fInitValue;                      
279   }                                               
280 }                                                 
281                                                   
282 //____________________________________________    
283 template <class Key, class T, class Hash, clas    
284 void G4AccUnorderedMap<Key, T, Hash, KeyEqual,    
285   G4PrintOptions options) const                   
286 {                                                 
287   if (options.Has(G4PrintOptions::kType)) {       
288     G4cout << "unordered_map<" << typeid(Key).    
289   }                                               
290                                                   
291   PrintBase(options);                             
292                                                   
293   bool first = true;                              
294   for (const auto& [key, value] : fUMap) {        
295     if (! first) { G4cout << ", "; }              
296     G4cout << "[ " << key << ", " << value <<     
297     first = false;                                
298   }                                               
299   G4cout << G4endl;                               
300 }                                                 
301                                                   
302 //____________________________________________    
303 template <class Key, class T, class Hash, clas    
304 void G4AccUnorderedMap<Key, T, Hash, KeyEqual,    
305 {                                                 
306   G4VAccumulable::SetMergeMode(value);            
307   fMergeFunction = GetMergeFunction<T>(fMergeM    
308 }                                                 
309                                                   
310 //____________________________________________    
311 template <class Key, class T, class Hash, clas    
312 void G4AccUnorderedMap<Key, T, Hash, KeyEqual,    
313 {                                                 
314   fInitValue = value;                             
315 }                                                 
316