Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:38:33

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_HASHMAP_H
0012 #define GAUDIKERNEL_HASHMAP_H 1
0013 
0014 // Include files
0015 #include "GaudiKernel/Hash.h"
0016 #include "GaudiKernel/Map.h"
0017 #include <unordered_map>
0018 
0019 namespace GaudiUtils {
0020   // ==========================================================================
0021   /** @class HashMap HashMap.h GaudiKernel/HashMap.h
0022    *
0023    * Common class providing an architecture-independent hash map.
0024    *
0025    *
0026    *  Due to helper base class Gaudi::Utils::MapBase, this class
0027    *  is "python-friendly", and one can perform all python
0028    *  manipulaitons
0029    *  in intuitive way:
0030    *  @code
0031    *
0032    *    >>> m = ...        ## get the map
0033    *    >>> print m        ## print the map a'la python class dict
0034    *    ...
0035    *    >>> for key in m :  print key, m[key]   ## iteration over the map
0036    *    ...
0037    *    >>> for key,value in m.iteritems() : print key, value
0038    *    ...
0039    *    >>> keys   = m.keys()                     ## get the list of keys
0040    *    >>> values = m.values ()                  ## get the list of values
0041    *    >>  items  = m.items  ()                  ## get the list of items
0042    *
0043    *    >>> if 'one' in m           ## check the presence of the key in map
0044    *
0045    *    >>>  v = m.get(key', None) ## return m[key] for existing key, else None
0046    *
0047    *    >>>  del m[key]      ## erase the key form the map
0048    *
0049    *    >>> value m[key]     ## unchecked access through the key
0050    *    ...
0051    *    >>> m.update( key, value ) ## update/insert key/value pair
0052    *
0053    *   @endcode
0054    *
0055    *   @attention One needs to redfine  <c>__setitem__</c> and <c>__getitem__</c>
0056    *              methods in python:
0057    *
0058    *   @code
0059    *
0060    *    >>> type(m).__setitem__ = Gaudi.Utils.MapBase.__setitem__
0061    *    >>> type(m).__getitem__ = Gaudi.Utils.MapBase.__getitem__
0062    *
0063    *    >>> m[key] = value  ## much more intuitive semantics for key insertion
0064    *
0065    *   @endcode
0066    *   In a similar way <c>__delitem__</c> methods can be redefined.
0067    *   @warning
0068    *   To bypass some compilation problme (and to avoid the unnesessary
0069    *   expansion of dictionaries) it is nesessary to exclude from
0070    *   dictionary the following methods:
0071    *     - lower_bound
0072    *     - upper_bound
0073    *     - equal_range
0074    *     - insert
0075    *
0076    *   @see Gaudi::Utils::MapBase
0077    *
0078    * @author Marco Clemencic
0079    * @date 2005-10-06
0080    */
0081 
0082   template <typename K, typename T, typename H = Hash<K>, typename M = std::unordered_map<K, T, H>>
0083   class HashMap : public Map<K, T, M> {
0084   public:
0085     typedef H     hasher;
0086     inline hasher hash_funct() const { return this->m_map.hash_funct(); }
0087   };
0088 } // namespace GaudiUtils
0089 
0090 #endif // GAUDIKERNEL_GAUDIHASHMAP_H