spot  1.2.1a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
hash.hh
1 // Copyright (C) 2008, 2011 Laboratoire de Recherche et Développement
2 // de l'Epita (LRDE).
3 // Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de
4 // Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
5 // Université Pierre et Marie Curie.
6 //
7 // This file is part of Spot, a model checking library.
8 //
9 // Spot is free software; you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // Spot is distributed in the hope that it will be useful, but WITHOUT
15 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 // License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef SPOT_MISC_HASH_HH
23 # define SPOT_MISC_HASH_HH
24 
25 # include <string>
26 # include <functional>
27 # include "misc/hashfunc.hh"
28 # include "misc/_config.h"
29 
30 #ifdef SPOT_HAVE_UNORDERED_MAP
31 # include <unordered_map>
32 # include <unordered_set>
33  namespace Sgi = std;
34 # define hash_map unordered_map
35 # define hash_multimap unordered_multimap
36 # define hash_set unordered_set
37 #else
38 #ifdef SPOT_HAVE_TR1_UNORDERED_MAP
39 # include <tr1/unordered_map>
40 # include <tr1/unordered_set>
41  namespace Sgi = std::tr1;
42 # define hash_map unordered_map
43 # define hash_multimap unordered_multimap
44 # define hash_set unordered_set
45 #else
46 #ifdef SPOT_HAVE_EXT_HASH_MAP
47 # include <ext/hash_map>
48 # include <ext/hash_set>
49 # if __GNUC__ == 3 && __GNUC_MINOR__ == 0
50  namespace Sgi = std; // GCC 3.0
51 # else
52  namespace Sgi = ::__gnu_cxx; // GCC 3.1 to 4.2
53 # endif
54 #else
55 # if defined(__GNUC__) && (__GNUC__ < 3)
56 # include <hash_map.h>
57 # include <hash_set.h>
58  namespace Sgi
59  { // inherit globals
60  using ::hash_map;
61  using ::hash_multimap;
62  using ::hash_set;
63  using ::hash;
64  }
65 # else
66 # include <hash_map>
67 # include <hash_set>
68  namespace Sgi = std;
69 # endif
70 #endif
71 #endif
72 #endif
73 
74 namespace spot
75 {
76 
79  template <class T>
80  struct ptr_hash :
81  public std::unary_function<const T*, size_t>
82  {
83  size_t operator()(const T* p) const
84  {
85  return knuth32_hash(reinterpret_cast<const char*>(p)
86  - static_cast<const char*>(0));
87  }
88  };
89 
93 #if defined(SPOT_HAVE_UNORDERED_MAP) || defined(SPOT_HAVE_TR1_UNORDERED_MAP)
94  typedef Sgi::hash<std::string> string_hash;
95 #else // e.g. GCC < 4.3
96  struct string_hash:
97  public Sgi::hash<const char*>,
98  public std::unary_function<const std::string&, size_t>
99  {
100  size_t operator()(const std::string& s) const
101  {
102  // We are living dangerously. Be sure to call operator()
103  // from the super-class, not this one.
104  return Sgi::hash<const char*>::operator()(s.c_str());
105  }
106  };
108 #endif
109 
112  template<typename T>
114  public std::unary_function<const T&, size_t>
115  {
116  size_t operator()(const T& s) const
117  {
118  return s;
119  }
120  };
121 }
122 
123 #endif // SPOT_MISC_HASH_HH
Sgi::hash< std::string > string_hash
A hash function for strings.
Definition: hash.hh:94
A hash function for pointers.
Definition: hash.hh:80
size_t knuth32_hash(size_t key)
Knuth&#39;s Multiplicative hash function.
Definition: hashfunc.hh:54
A hash function that returns identity.
Definition: hash.hh:113

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Tue Jan 21 2014 16:52:01 for spot by doxygen 1.8.5