home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _hash_fun.h < prev    next >
C/C++ Source or Header  |  2001-01-26  |  3KB  |  108 lines

  1. /*
  2.  * Copyright (c) 1996-1998
  3.  * Silicon Graphics Computer Systems, Inc.
  4.  *
  5.  * Permission to use, copy, modify, distribute and sell this software
  6.  * and its documentation for any purpose is hereby granted without fee,
  7.  * provided that the above copyright notice appear in all copies and
  8.  * that both that copyright notice and this permission notice appear
  9.  * in supporting documentation.  Silicon Graphics makes no
  10.  * representations about the suitability of this software for any
  11.  * purpose.  It is provided "as is" without express or implied warranty.
  12.  *
  13.  *
  14.  * Copyright (c) 1994
  15.  * Hewlett-Packard Company
  16.  *
  17.  * Permission to use, copy, modify, distribute and sell this software
  18.  * and its documentation for any purpose is hereby granted without fee,
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both that copyright notice and this permission notice appear
  21.  * in supporting documentation.  Hewlett-Packard Company makes no
  22.  * representations about the suitability of this software for any
  23.  * purpose.  It is provided "as is" without express or implied warranty.
  24.  *
  25.  */
  26.  
  27. /* NOTE: This is an internal header file, included by other STL headers.
  28.  *   You should not attempt to use it directly.
  29.  */
  30.  
  31. #ifndef _STLP_HASH_FUN_H
  32. #define _STLP_HASH_FUN_H
  33.  
  34. # ifndef _STLP_CSTDDEF
  35. #  include <cstddef>
  36. # endif
  37.  
  38. _STLP_BEGIN_NAMESPACE
  39.  
  40. template <class _Key> struct hash { };
  41.  
  42. inline size_t __stl_hash_string(const char* __s)
  43. {
  44.   _STLP_FIX_LITERAL_BUG(__s)
  45.   unsigned long __h = 0; 
  46.   for ( ; *__s; ++__s)
  47.     __h = 5*__h + *__s;
  48.   
  49.   return size_t(__h);
  50. }
  51.  
  52. _STLP_TEMPLATE_NULL struct hash<char*>
  53. {
  54.   size_t operator()(const char* __s) const { _STLP_FIX_LITERAL_BUG(__s) return __stl_hash_string(__s); }
  55. };
  56.  
  57. _STLP_TEMPLATE_NULL struct hash<const char*>
  58. {
  59.   size_t operator()(const char* __s) const { _STLP_FIX_LITERAL_BUG(__s) return __stl_hash_string(__s); }
  60. };
  61.  
  62. _STLP_TEMPLATE_NULL struct hash<char> {
  63.   size_t operator()(char __x) const { return __x; }
  64. };
  65. _STLP_TEMPLATE_NULL struct hash<unsigned char> {
  66.   size_t operator()(unsigned char __x) const { return __x; }
  67. };
  68. #ifndef _STLP_NO_SIGNED_BUILTINS
  69. _STLP_TEMPLATE_NULL struct hash<signed char> {
  70.   size_t operator()(unsigned char __x) const { return __x; }
  71. };
  72. #endif
  73. _STLP_TEMPLATE_NULL struct hash<short> {
  74.   size_t operator()(short __x) const { return __x; }
  75. };
  76. _STLP_TEMPLATE_NULL struct hash<unsigned short> {
  77.   size_t operator()(unsigned short __x) const { return __x; }
  78. };
  79. _STLP_TEMPLATE_NULL struct hash<int> {
  80.   size_t operator()(int __x) const { return __x; }
  81. };
  82. _STLP_TEMPLATE_NULL struct hash<unsigned int> {
  83.   size_t operator()(unsigned int __x) const { return __x; }
  84. };
  85. _STLP_TEMPLATE_NULL struct hash<long> {
  86.   size_t operator()(long __x) const { return __x; }
  87. };
  88. _STLP_TEMPLATE_NULL struct hash<unsigned long> {
  89.   size_t operator()(unsigned long __x) const { return __x; }
  90. };
  91.  
  92. # if defined (_STLP_LONG_LONG)
  93. _STLP_TEMPLATE_NULL struct hash<_STLP_LONG_LONG> {
  94.   size_t operator()(long x) const { return x; }
  95. };
  96. _STLP_TEMPLATE_NULL struct hash<unsigned _STLP_LONG_LONG> {
  97.   size_t operator()(unsigned long x) const { return x; }
  98. };
  99. # endif
  100.  
  101. _STLP_END_NAMESPACE
  102.  
  103. #endif /* _STLP_HASH_FUN_H */
  104.  
  105. // Local Variables:
  106. // mode:C++
  107. // End:
  108.