00001 // -*- C++ -*- 00002 00003 // pl_hash_fun Hash functions for the PLearn library. 00004 // Copyright (C) 2002 Xavier Saint-Mleux 00005 // 00006 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are met: 00009 // 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 00012 // 00013 // 2. Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // 3. The name of the authors may not be used to endorse or promote 00018 // products derived from this software without specific prior written 00019 // permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 // 00032 // This file is part of the PLearn library. For more information on the PLearn 00033 // library, go to the PLearn Web site at www.plearn.org 00034 00035 #ifndef pl_hash_fun_H 00036 #define pl_hash_fun_H 00037 00038 #include "ms_hash_wrapper.h" 00039 #include <string> 00040 00041 namespace PLearn { 00042 00043 using namespace std; 00044 00045 extern const size_t PL_HASH_NOMBRES_MAGIQUES[256]; 00046 00048 00054 size_t hashbytes(const char* byte_start, size_t byte_length); 00055 00070 inline size_t hashval(const char* strng) 00071 { return hashbytes(strng, strlen(strng)); } 00072 00074 template <class T> 00075 inline size_t hashval(const T& x) { return hashbytes((char*)&x,sizeof(T)); } 00076 00077 } // end of namespace PLearn 00078 00079 00081 00082 //using namespace std; 00083 00084 // norman: Old code kept for the moment.. 00085 00086 SET_HASH_WITH_INHERITANCE(std::string, const char*, __s, __s.c_str()) 00087 //hash functions for strings 00088 //template<> 00089 //struct hash<string> 00090 //{ 00091 // size_t operator()(const string& __s) const { return hash<const char*>()(__s.c_str()); } 00092 //}; 00093 00094 // This has been deactivated because it is useless (and .NET doesn't like it): 00095 //SET_HASH_WITH_INHERITANCE(const std::string, const char*, __s, __s.c_str()) 00096 //template<> 00097 //struct hash<const string> 00098 //{ 00099 // size_t operator()(const string& __s) const { return hash<const char*>()(__s.c_str()); } 00100 // //size_t operator()(const string& __s) const { return __stl_hash_string(__s.c_str()); } 00101 //}; 00102 00103 00104 //for doubles 00105 SET_HASH_WITH_FUNCTION(double, x, PLearn::hashval(x)) 00106 //template<> 00107 //struct hash<double> 00108 //{ 00109 // size_t operator()(double x) const { return PLearn::hashval(x); } 00110 //}; 00111 00112 //for floats 00113 SET_HASH_WITH_FUNCTION(float, x, PLearn::hashval(x)) 00114 //template<> 00115 //struct hash<float> 00116 //{ 00117 // size_t operator()(float x) const { return PLearn::hashval(x); } 00118 //}; 00119 00120 00121 #if defined(WIN32) & !defined(_MINGW_) 00122 00123 using namespace stdext; 00124 00125 #if defined(__INTEL_COMPILER) 00126 // because Intel compiler (in WIN32 only!!) defines hash_map and hash_table both in stdext and std 00127 // if we set that we use both (with "using namespace") it will have an ambiguity. 00128 // To solve this, I force hash_map, hash_multimap and hash_table to be explicit. 00129 00130 #define hash_map stdext::hash_map 00131 #define hash_multimap stdext::hash_multimap 00132 #define hash_set stdext::hash_set 00133 #define hash_multiset stdext::hash_multiset 00134 00135 #endif // __INTEL_COMPILER 00136 00137 #endif // WIN32 00138 00139 00140 #endif // pl_hash_fun_H