Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

hash.hh

Go to the documentation of this file.
00001 // Copyright (C) 2003, 2004, 2005  Laboratoire d'Informatique de Paris 6 (LIP6),
00002 // département Systèmes Répartis Coopératifs (SRC), Université Pierre
00003 // et Marie Curie.
00004 //
00005 // This file is part of Spot, a model checking library.
00006 //
00007 // Spot is free software; you can redistribute it and/or modify it
00008 // under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation; either version 2 of the License, or
00010 // (at your option) any later version.
00011 //
00012 // Spot is distributed in the hope that it will be useful, but WITHOUT
00013 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00014 // or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
00015 // License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Spot; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020 // 02111-1307, USA.
00021 
00022 #ifndef SPOT_MISC_HASH_HH
00023 #  define SPOT_MISC_HASH_HH
00024 
00025 #  include <string>
00026 #  include <functional>
00027 #  include "hashfunc.hh"
00028 
00029 // See the G++ FAQ for details about the following.
00030 #  ifdef __GNUC__
00031 #  if __GNUC__ < 3
00032 #    include <hash_map.h>
00033 #    include <hash_set.h>
00034     namespace Sgi
00035     { // inherit globals
00036       using ::hash_map;
00037       using ::hash_set;
00038       using ::hash;
00039     };
00040 #  else
00041 #    include <ext/hash_map>
00042 #    include <ext/hash_set>
00043 #    if __GNUC__ == 3 && __GNUC_MINOR__ == 0
00044       namespace Sgi = std;               // GCC 3.0
00045 #    else
00046       namespace Sgi = ::__gnu_cxx;       // GCC 3.1 and later
00047 #    endif
00048 #  endif
00049 #  else      // ...  there are other compilers, right?
00050 #   include <hash_map>
00051 #   include <hash_set>
00052     namespace Sgi = std;
00053 #  endif
00054 
00055 namespace spot
00056 {
00057 
00060   template <class T>
00061   struct ptr_hash :
00062     public std::unary_function<const T*, size_t>
00063   {
00064     size_t operator()(const T* p) const
00065     {
00066       return knuth32_hash(reinterpret_cast<const char*>(p)
00067                           - static_cast<const char*>(0));
00068     }
00069   };
00070 
00073   struct string_hash :
00074     public Sgi::hash<const char*>,
00075     public std::unary_function<const std::string&, size_t>
00076   {
00077     size_t operator()(const std::string& s) const
00078     {
00079       // We are living dangerously.  Be sure to call operator()
00080       // from the super-class, not this one.
00081       return Sgi::hash<const char*>::operator()(s.c_str());
00082     }
00083   };
00084 }
00085 
00086 #endif // SPOT_MISC_HASH_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Wed Jan 25 14:52:55 2006 for spot by doxygen 1.4.0