spot
0.8.1
|
00001 // Copyright (C) 2008, 2011 Laboratoire de Recherche et Développement 00002 // de l'Epita (LRDE). 00003 // Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de 00004 // Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC), 00005 // Université Pierre et Marie Curie. 00006 // 00007 // This file is part of Spot, a model checking library. 00008 // 00009 // Spot is free software; you can redistribute it and/or modify it 00010 // under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation; either version 2 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // Spot is distributed in the hope that it will be useful, but WITHOUT 00015 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00016 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 00017 // License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with Spot; see the file COPYING. If not, write to the Free 00021 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00022 // 02111-1307, USA. 00023 00024 #ifndef SPOT_MISC_HASH_HH 00025 # define SPOT_MISC_HASH_HH 00026 00027 # include <string> 00028 # include <functional> 00029 # include "misc/hashfunc.hh" 00030 # include "misc/_config.h" 00031 00032 #ifdef SPOT_HAVE_UNORDERED_MAP 00033 # include <unordered_map> 00034 # include <unordered_set> 00035 namespace Sgi = std; 00036 # define hash_map unordered_map 00037 # define hash_multimap unordered_multimap 00038 # define hash_set unordered_set 00039 #else 00040 #ifdef SPOT_HAVE_TR1_UNORDERED_MAP 00041 # include <tr1/unordered_map> 00042 # include <tr1/unordered_set> 00043 namespace Sgi = std::tr1; 00044 # define hash_map unordered_map 00045 # define hash_multimap unordered_multimap 00046 # define hash_set unordered_set 00047 #else 00048 #ifdef SPOT_HAVE_EXT_HASH_MAP 00049 # include <ext/hash_map> 00050 # include <ext/hash_set> 00051 # if __GNUC__ == 3 && __GNUC_MINOR__ == 0 00052 namespace Sgi = std; // GCC 3.0 00053 # else 00054 namespace Sgi = ::__gnu_cxx; // GCC 3.1 to 4.2 00055 # endif 00056 #else 00057 # if defined(__GNUC__) && (__GNUC__ < 3) 00058 # include <hash_map.h> 00059 # include <hash_set.h> 00060 namespace Sgi 00061 { // inherit globals 00062 using ::hash_map; 00063 using ::hash_multimap; 00064 using ::hash_set; 00065 using ::hash; 00066 } 00067 # else 00068 # include <hash_map> 00069 # include <hash_set> 00070 namespace Sgi = std; 00071 # endif 00072 #endif 00073 #endif 00074 #endif 00075 00076 namespace spot 00077 { 00078 00081 template <class T> 00082 struct ptr_hash : 00083 public std::unary_function<const T*, size_t> 00084 { 00085 size_t operator()(const T* p) const 00086 { 00087 return knuth32_hash(reinterpret_cast<const char*>(p) 00088 - static_cast<const char*>(0)); 00089 } 00090 }; 00091 00095 #if defined(SPOT_HAVE_UNORDERED_MAP) || defined(SPOT_HAVE_TR1_UNORDERED_MAP) 00096 typedef Sgi::hash<std::string> string_hash; 00097 #else // e.g. GCC < 4.3 00098 struct string_hash: 00099 public Sgi::hash<const char*>, 00100 public std::unary_function<const std::string&, size_t> 00101 { 00102 size_t operator()(const std::string& s) const 00103 { 00104 // We are living dangerously. Be sure to call operator() 00105 // from the super-class, not this one. 00106 return Sgi::hash<const char*>::operator()(s.c_str()); 00107 } 00108 }; 00110 #endif 00111 00114 template<typename T> 00115 struct identity_hash: 00116 public std::unary_function<const T&, size_t> 00117 { 00118 size_t operator()(const T& s) const 00119 { 00120 return s; 00121 } 00122 }; 00123 } 00124 00125 #endif // SPOT_MISC_HASH_HH