williamr@2: /* williamr@2: * Copyright (c) 1996-1998 williamr@2: * Silicon Graphics Computer Systems, Inc. williamr@2: * williamr@2: * Permission to use, copy, modify, distribute and sell this software williamr@2: * and its documentation for any purpose is hereby granted without fee, williamr@2: * provided that the above copyright notice appear in all copies and williamr@2: * that both that copyright notice and this permission notice appear williamr@2: * in supporting documentation. Silicon Graphics makes no williamr@2: * representations about the suitability of this software for any williamr@2: * purpose. It is provided "as is" without express or implied warranty. williamr@2: * williamr@2: * williamr@2: * Copyright (c) 1994 williamr@2: * Hewlett-Packard Company williamr@2: * williamr@2: * Permission to use, copy, modify, distribute and sell this software williamr@2: * and its documentation for any purpose is hereby granted without fee, williamr@2: * provided that the above copyright notice appear in all copies and williamr@2: * that both that copyright notice and this permission notice appear williamr@2: * in supporting documentation. Hewlett-Packard Company makes no williamr@2: * representations about the suitability of this software for any williamr@2: * purpose. It is provided "as is" without express or implied warranty. williamr@2: * williamr@2: */ williamr@2: williamr@2: /* NOTE: This is an internal header file, included by other STL headers. williamr@2: * You should not attempt to use it directly. williamr@2: */ williamr@2: williamr@2: #ifndef _STLP_HASH_FUN_H williamr@2: #define _STLP_HASH_FUN_H williamr@2: williamr@4: #ifndef _STLP_INTERNAL_CSTDDEF williamr@4: # include williamr@4: #endif williamr@2: williamr@2: _STLP_BEGIN_NAMESPACE williamr@2: williamr@2: template struct hash { }; williamr@2: williamr@4: _STLP_MOVE_TO_PRIV_NAMESPACE williamr@4: williamr@4: inline size_t __stl_hash_string(const char* __s) { williamr@2: _STLP_FIX_LITERAL_BUG(__s) williamr@4: unsigned long __h = 0; williamr@2: for ( ; *__s; ++__s) williamr@2: __h = 5*__h + *__s; williamr@4: williamr@2: return size_t(__h); williamr@2: } williamr@2: williamr@4: _STLP_MOVE_TO_STD_NAMESPACE williamr@4: williamr@4: _STLP_TEMPLATE_NULL williamr@4: struct hash { williamr@4: size_t operator()(const char* __s) const { williamr@4: _STLP_FIX_LITERAL_BUG(__s) williamr@4: return _STLP_PRIV __stl_hash_string(__s); williamr@4: } williamr@2: }; williamr@2: williamr@4: _STLP_TEMPLATE_NULL williamr@4: struct hash { williamr@4: size_t operator()(const char* __s) const { williamr@4: _STLP_FIX_LITERAL_BUG(__s) williamr@4: return _STLP_PRIV __stl_hash_string(__s); williamr@4: } williamr@2: }; williamr@2: williamr@2: _STLP_TEMPLATE_NULL struct hash { williamr@2: size_t operator()(char __x) const { return __x; } williamr@2: }; williamr@2: _STLP_TEMPLATE_NULL struct hash { williamr@2: size_t operator()(unsigned char __x) const { return __x; } williamr@2: }; williamr@4: #if !defined (_STLP_NO_SIGNED_BUILTINS) williamr@2: _STLP_TEMPLATE_NULL struct hash { williamr@2: size_t operator()(unsigned char __x) const { return __x; } williamr@2: }; williamr@2: #endif williamr@2: _STLP_TEMPLATE_NULL struct hash { williamr@2: size_t operator()(short __x) const { return __x; } williamr@2: }; williamr@2: _STLP_TEMPLATE_NULL struct hash { williamr@2: size_t operator()(unsigned short __x) const { return __x; } williamr@2: }; williamr@2: _STLP_TEMPLATE_NULL struct hash { williamr@2: size_t operator()(int __x) const { return __x; } williamr@2: }; williamr@4: williamr@4: #if defined (_WIN64) || !defined (_STLP_MSVC) || (_STLP_MSVC < 1300) williamr@2: _STLP_TEMPLATE_NULL struct hash { williamr@2: size_t operator()(unsigned int __x) const { return __x; } williamr@2: }; williamr@4: #else williamr@4: /* MSVC .Net since 2002 has a 64 bits portability warning feature. typedef williamr@4: * like size_t are tagged as potential 64 bits variables making them different from williamr@4: * unsigned int. To avoid the warning when a hash container is instanciated with williamr@4: * the size_t key we prefer to grant the size_t specialization rather than the williamr@4: * unsigned int one. williamr@4: */ williamr@4: _STLP_TEMPLATE_NULL struct hash { williamr@4: size_t operator()(size_t __x) const { return __x; } williamr@4: }; williamr@4: #endif williamr@4: williamr@2: _STLP_TEMPLATE_NULL struct hash { williamr@2: size_t operator()(long __x) const { return __x; } williamr@2: }; williamr@2: _STLP_TEMPLATE_NULL struct hash { williamr@2: size_t operator()(unsigned long __x) const { return __x; } williamr@2: }; williamr@2: williamr@4: #if defined (_STLP_LONG_LONG) williamr@2: _STLP_TEMPLATE_NULL struct hash<_STLP_LONG_LONG> { williamr@4: size_t operator()(_STLP_LONG_LONG x) const { return (size_t)x; } williamr@2: }; williamr@2: _STLP_TEMPLATE_NULL struct hash { williamr@4: size_t operator()(unsigned _STLP_LONG_LONG x) const { return (size_t)x; } williamr@2: }; williamr@4: #endif williamr@4: williamr@4: _STLP_TEMPLATE_NULL williamr@4: struct hash williamr@4: { williamr@4: union __vp { williamr@4: size_t s; williamr@4: void *p; williamr@4: }; williamr@4: williamr@4: size_t operator()(void *__x) const williamr@4: { williamr@4: __vp vp; williamr@4: vp.p = __x; williamr@4: return vp.s; williamr@4: } williamr@4: }; williamr@2: williamr@2: _STLP_END_NAMESPACE williamr@2: williamr@2: #endif /* _STLP_HASH_FUN_H */ williamr@2: williamr@2: // Local Variables: williamr@2: // mode:C++ williamr@2: // End: