| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

GiGaHash.h

Go to the documentation of this file.
00001 // $Id: GiGaHash.h,v 1.3 2003/07/08 11:26:43 ranjard Exp $
00002 // ============================================================================
00003 // CVS tag $Name: v19r4 $
00004 // ============================================================================
00005 // $Log: GiGaHash.h,v $
00006 // Revision 1.3  2003/07/08 11:26:43  ranjard
00007 // v14r2 - add #if defined to distinguish between gcc3.2 and gcc2.95
00008 //
00009 // Revision 1.2  2003/07/07 16:48:09  ranjard
00010 // v14r2 - fix for gcc 3.2
00011 //
00012 // Revision 1.1  2002/05/04 20:20:11  ibelyaev
00013 //  see $GIGAROOT/doc/release.notes (4 May 2002)
00014 //
00015 // ============================================================================
00016 #ifndef GIGA_GIGAHASH_H 
00017 #define GIGA_GIGAHASH_H 1
00018 // Include files
00019 #include <string>
00020 
00033 template <class TYPE> 
00034 struct GiGaHash : public std::unary_function<TYPE,size_t>
00035 {
00036   size_t operator() ( const TYPE& key ) const 
00037   {
00038     size_t res     = 0 ;
00039     size_t len     = sizeof(TYPE) ;
00040     const  char* p = reinterpret_cast<const char*>( &key );
00041     while( len-- ) { res = ( res << 1 ) ^ *p++ ; }  
00042     return res;
00043   };
00044 };
00045 
00046 template <>
00047 struct GiGaHash<std::string>
00048   : public std::unary_function<std::string,size_t>
00049 {
00050   size_t operator() ( const std::string& key ) const
00051   {
00052     typedef std::string::const_iterator CI;
00053     size_t res  = 0 ;
00054     CI end = key.end   () ;
00055     for( CI p = key.begin(); end != p ; ++p ) { res = ( res << 1 )^*p ;}
00056     return res ;
00057   };
00058 };
00059 
00060 #ifndef WIN32
00061 #if defined (__GNUC__) && ( __GNUC__<= 2 )
00062  template<>
00063  struct std::hash<std::string>
00064    : public GiGaHash<std::string>{};
00065 #else
00066 namespace __gnu_cxx {
00067   template<>
00068   struct hash<std::string>
00069     : public GiGaHash<std::string>{};
00070 }
00071 #endif
00072 #endif 
00073 
00074 // ============================================================================
00075 // The END 
00076 // ============================================================================
00077 #endif // GIGA_GIGAHASH_H
00078 // ============================================================================
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:01:14 2011 for GiGa by doxygen 1.4.7