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

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Sat Dec 6 2014 12:28:43 for spot by doxygen 1.8.4