spot 0.8
|
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 "hashfunc.hh" 00030 00031 // See the G++ FAQ for details about the following. 00032 # ifdef __GNUC__ 00033 # if __GNUC__ < 3 00034 # include <hash_map.h> 00035 # include <hash_set.h> 00036 namespace Sgi 00037 { // inherit globals 00038 using ::hash_map; 00039 using ::hash_multimap; 00040 using ::hash_set; 00041 using ::hash; 00042 } 00043 # else 00044 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 00045 # include <tr1/unordered_set> // GCC 4.3 00046 # include <tr1/unordered_map> 00047 namespace Sgi = std::tr1; 00048 # define hash_map unordered_map 00049 # define hash_multimap unordered_multimap 00050 # define hash_set unordered_set 00051 # else 00052 # include <ext/hash_map> 00053 # include <ext/hash_set> 00054 # if __GNUC__ == 3 && __GNUC_MINOR__ == 0 00055 namespace Sgi = std; // GCC 3.0 00056 # else 00057 namespace Sgi = ::__gnu_cxx; // GCC 3.1 to 4.2 00058 # endif 00059 # endif 00060 # endif 00061 # else // ... there are other compilers, right? 00062 # include <hash_map> 00063 # include <hash_set> 00064 namespace Sgi = std; 00065 # endif 00066 00067 namespace spot 00068 { 00069 00072 template <class T> 00073 struct ptr_hash : 00074 public std::unary_function<const T*, size_t> 00075 { 00076 size_t operator()(const T* p) const 00077 { 00078 return knuth32_hash(reinterpret_cast<const char*>(p) 00079 - static_cast<const char*>(0)); 00080 } 00081 }; 00082 00086 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 00087 typedef std::tr1::hash<std::string> string_hash; 00088 # else // GCC < 4.3 00089 struct string_hash: 00090 public Sgi::hash<const char*>, 00091 public std::unary_function<const std::string&, size_t> 00092 { 00093 size_t operator()(const std::string& s) const 00094 { 00095 // We are living dangerously. Be sure to call operator() 00096 // from the super-class, not this one. 00097 return Sgi::hash<const char*>::operator()(s.c_str()); 00098 } 00099 }; 00101 # endif 00102 00105 template<typename T> 00106 struct identity_hash: 00107 public std::unary_function<const T&, size_t> 00108 { 00109 size_t operator()(const T& s) const 00110 { 00111 return s; 00112 } 00113 }; 00114 } 00115 00116 #endif // SPOT_MISC_HASH_HH