spot  0.9.2
hash.hh
Go to the documentation of this file.
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 2 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 Spot; see the file COPYING. If not, write to the Free
21 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 // 02111-1307, USA.
23 
24 #ifndef SPOT_MISC_HASH_HH
25 # define SPOT_MISC_HASH_HH
26 
27 # include <string>
28 # include <functional>
29 # include "misc/hashfunc.hh"
30 # include "misc/_config.h"
31 
32 #ifdef SPOT_HAVE_UNORDERED_MAP
33 # include <unordered_map>
34 # include <unordered_set>
35  namespace Sgi = std;
36 # define hash_map unordered_map
37 # define hash_multimap unordered_multimap
38 # define hash_set unordered_set
39 #else
40 #ifdef SPOT_HAVE_TR1_UNORDERED_MAP
41 # include <tr1/unordered_map>
42 # include <tr1/unordered_set>
43  namespace Sgi = std::tr1;
44 # define hash_map unordered_map
45 # define hash_multimap unordered_multimap
46 # define hash_set unordered_set
47 #else
48 #ifdef SPOT_HAVE_EXT_HASH_MAP
49 # include <ext/hash_map>
50 # include <ext/hash_set>
51 # if __GNUC__ == 3 && __GNUC_MINOR__ == 0
52  namespace Sgi = std; // GCC 3.0
53 # else
54  namespace Sgi = ::__gnu_cxx; // GCC 3.1 to 4.2
55 # endif
56 #else
57 # if defined(__GNUC__) && (__GNUC__ < 3)
58 # include <hash_map.h>
59 # include <hash_set.h>
60  namespace Sgi
61  { // inherit globals
65  using ::hash;
66  }
67 # else
68 # include <hash_map>
69 # include <hash_set>
70  namespace Sgi = std;
71 # endif
72 #endif
73 #endif
74 #endif
75 
76 namespace spot
77 {
78 
81  template <class T>
82  struct ptr_hash :
83  public std::unary_function<const T*, size_t>
84  {
85  size_t operator()(const T* p) const
86  {
87  return knuth32_hash(reinterpret_cast<const char*>(p)
88  - static_cast<const char*>(0));
89  }
90  };
91 
95 #if defined(SPOT_HAVE_UNORDERED_MAP) || defined(SPOT_HAVE_TR1_UNORDERED_MAP)
96  typedef Sgi::hash<std::string> string_hash;
97 #else // e.g. GCC < 4.3
98  struct string_hash:
99  public Sgi::hash<const char*>,
100  public std::unary_function<const std::string&, size_t>
101  {
102  size_t operator()(const std::string& s) const
103  {
104  // We are living dangerously. Be sure to call operator()
105  // from the super-class, not this one.
106  return Sgi::hash<const char*>::operator()(s.c_str());
107  }
108  };
110 #endif
111 
114  template<typename T>
116  public std::unary_function<const T&, size_t>
117  {
118  size_t operator()(const T& s) const
119  {
120  return s;
121  }
122  };
123 }
124 
125 #endif // SPOT_MISC_HASH_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Mon Jul 2 2012 17:35:47 for spot by doxygen 1.8.1.1