PLearn 0.1
pl_hash_fun.h
Go to the documentation of this file.
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 <cstring>
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 #if defined(__GNUC__) && defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1000
00083 // Intel Compiler (before 10.0) on Linux: we need to define a hash function for
00084 // const char*.
00085 SET_HASH_WITH_FUNCTION_NOCONSTREF(const char*, _s, PLearn::hashval(_s))
00086 #endif
00087 
00088     SET_HASH_WITH_INHERITANCE(std::string, const char*, __s, __s.c_str())
00089 
00090 //hash functions for strings
00091 //template<>
00092 //struct hash<string>
00093 //{
00094 //      size_t operator()(const string& __s) const { return hash<const char*>()(__s.c_str()); }
00095 //};
00096 
00097 // This has been deactivated because it is useless (and .NET doesn't like it):
00098 //SET_HASH_WITH_INHERITANCE(const std::string, const char*, __s, __s.c_str())
00099 //template<>
00100 //struct hash<const string>
00101 //{
00102 //  size_t operator()(const string& __s) const { return hash<const char*>()(__s.c_str()); }
00103 //  //size_t operator()(const string& __s) const { return __stl_hash_string(__s.c_str()); }
00104 //};
00105 
00106 
00107 //for doubles 
00108     SET_HASH_WITH_FUNCTION(double, x, PLearn::hashval(x))
00109 //template<>
00110 //struct hash<double>
00111 //{
00112 //  size_t operator()(double x) const { return PLearn::hashval(x); }
00113 //};
00114 
00115 //for floats 
00116     SET_HASH_WITH_FUNCTION(float, x, PLearn::hashval(x))
00117 //template<>
00118 //struct hash<float>
00119 //{
00120 //  size_t operator()(float x) const { return PLearn::hashval(x); }
00121 //};
00122 
00123 
00124 #if defined(WIN32) && !defined(_MINGW_) && !defined(__CYGWIN__)
00125 
00126     using namespace stdext;
00127 
00128 #if defined(__INTEL_COMPILER)
00129 // Because Intel compiler (in WIN32 only!!) defines hash_map and hash_table both in stdext and std
00130 // if we set that we use both (with "using namespace") it will have an ambiguity.
00131 // To solve this, I force hash_map, hash_multimap and hash_table to be explicit.
00132 
00133 #define hash_map stdext::hash_map
00134 #define hash_multimap stdext::hash_multimap
00135 #define hash_set stdext::hash_set
00136 #define hash_multiset stdext::hash_multiset
00137 
00138 #endif // __INTEL_COMPILER
00139 
00140 #elif defined(__INTEL_COMPILER) && defined(_NAMESPACE_STLPORT)
00141 // STL port version (e.g. Ms computers). There is also a namespace conflict.
00142 // We prefer to use the STL port version because it is easier to debug.
00143 
00144 #define hash_map _NAMESPACE_STLPORT::hash_map
00145 #define hash_multimap _NAMESPACE_STLPORT::hash_multimap
00146 #define hash_set _NAMESPACE_STLPORT::hash_set
00147 #define hash_multiset _NAMESPACE_STLPORT::hash_multiset
00148 
00149 #endif // WIN32
00150 
00151 #endif // pl_hash_fun_H
00152 
00153 
00154 /*
00155   Local Variables:
00156   mode:c++
00157   c-basic-offset:4
00158   c-file-style:"stroustrup"
00159   c-file-offsets:((innamespace . 0)(inline-open . 0))
00160   indent-tabs-mode:nil
00161   fill-column:79
00162   End:
00163 */
00164 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines