CVC3  2.4.1
hash_fun.h
Go to the documentation of this file.
1 /*****************************************************************************/
2 /*!
3  *\file hash_fun.h
4  *\brief hash functions
5  *
6  * Author: Alexander Fuchs
7  *
8  * Created: Fri Oct 20 11:04:00 2006
9  *
10  * <hr>
11  *
12  * License to use, copy, modify, sell and/or distribute this software
13  * and its documentation for any purpose is hereby granted without
14  * royalty, subject to the terms and conditions defined in the \ref
15  * LICENSE file provided with this distribution.
16  *
17  * <hr>
18  */
19 /*****************************************************************************/
20 
21 /*
22  * Copyright (c) 1996-1998
23  * Silicon Graphics Computer Systems, Inc.
24  *
25  * Permission to use, copy, modify, distribute and sell this software
26  * and its documentation for any purpose is hereby granted without fee,
27  * provided that the above copyright notice appear in all copies and
28  * that both that copyright notice and this permission notice appear
29  * in supporting documentation. Silicon Graphics makes no
30  * representations about the suitability of this software for any
31  * purpose. It is provided "as is" without express or implied warranty.
32  *
33  *
34  * Copyright (c) 1994
35  * Hewlett-Packard Company
36  *
37  * Permission to use, copy, modify, distribute and sell this software
38  * and its documentation for any purpose is hereby granted without fee,
39  * provided that the above copyright notice appear in all copies and
40  * that both that copyright notice and this permission notice appear
41  * in supporting documentation. Hewlett-Packard Company makes no
42  * representations about the suitability of this software for any
43  * purpose. It is provided "as is" without express or implied warranty.
44  *
45  */
46 
47 // this is basically (modulo renaming and namespace) the SGI implementation:
48 // http://www.sgi.com/tech/stl/stl_hash_fun.h
49 
50 #ifndef _cvc3__hash__hash_fun_h_
51 #define _cvc3__hash__hash_fun_h_
52 
53 // to get size_t
54 #include <cstddef>
55 
56 
57 namespace Hash {
58  using std::size_t;
59 
60  template <class _Key> struct hash { };
61 
62  inline size_t __stl_hash_string(const char* __s)
63  {
64  unsigned long __h = 0;
65  for ( ; *__s; ++__s)
66  __h = 5*__h + *__s;
67 
68  return size_t(__h);
69  }
70 
71  template<> struct hash<char*> {
72  size_t operator()(const char* __s) const { return __stl_hash_string(__s); }
73  };
74 
75  template<> struct hash<const char*>
76  {
77  size_t operator()(const char* __s) const { return __stl_hash_string(__s); }
78  };
79 
80  template<> struct hash<char> {
81  size_t operator()(char __x) const { return __x; }
82  };
83 
84  template<> struct hash<unsigned char> {
85  size_t operator()(unsigned char __x) const { return __x; }
86  };
87 
88  template<> struct hash<signed char> {
89  size_t operator()(unsigned char __x) const { return __x; }
90  };
91 
92  template<> struct hash<short> {
93  size_t operator()(short __x) const { return __x; }
94  };
95 
96  template<> struct hash<unsigned short> {
97  size_t operator()(unsigned short __x) const { return __x; }
98  };
99 
100  template<> struct hash<int> {
101  size_t operator()(int __x) const { return __x; }
102  };
103 
104  template<> struct hash<unsigned int> {
105  size_t operator()(unsigned int __x) const { return __x; }
106  };
107 
108  template<> struct hash<long> {
109  size_t operator()(long __x) const { return __x; }
110  };
111 
112  template<> struct hash<unsigned long> {
113  size_t operator()(unsigned long __x) const { return __x; }
114  };
115 
116 }
117 
118 #endif