TrueReality  v0.1.1912
Hash.h
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * The Base of this class has been adopted from the Delta3D engine
6 *
7 * This library is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the Free
9 * Software Foundation; either version 3.0 of the License, or (at your option)
10 * any later version.
11 *
12 * This library is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 * details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Class Inspired by the Delta3D Engine
22 * http://delta3dengine.org/
23 *
24 * @author David Guthrie
25 * @author Maxim Serebrennik
26 */
27 #pragma once
28 
29 #include <string>
30 
36 namespace trUtil
37 {
45  template<class _Key> struct hash;
46 
54  template<class _Key> struct hash<_Key*>
55  {
56  size_t operator()(const _Key* keyPtr) const
57  {
58  return size_t(keyPtr);
59  }
60  };
61 
71  inline size_t __hash_string(const char* __s)
72  {
73  unsigned long __h = 0;
74  for (; *__s; ++__s)
75  __h = 5 * __h + *__s;
76  return size_t(__h);
77  }
78 
84  template<> struct hash<const std::string>
85  {
86  size_t operator()(const std::string& string) const
87  {
88  return __hash_string(string.c_str());
89  }
90  };
91 
97  template<> struct hash<std::string>
98  {
99  size_t operator()(const std::string& string) const
100  {
101  return __hash_string(string.c_str());
102  }
103  };
104 
110  template<> struct hash<char*>
111  {
112  size_t operator()(const char* __s) const
113  {
114  return __hash_string(__s);
115  }
116  };
117 
123  template<> struct hash<const char*>
124  {
125  size_t operator()(const char* __s) const
126  {
127  return __hash_string(__s);
128  }
129  };
130 
136  template<> struct hash<char>
137  {
138  size_t operator()(char __x) const
139  {
140  return __x;
141  }
142  };
143 
149  template<> struct hash<unsigned char>
150  {
151  size_t operator()(unsigned char __x) const
152  {
153  return __x;
154  }
155  };
156 
162  template<> struct hash<signed char>
163  {
164  size_t operator()(unsigned char __x) const
165  {
166  return __x;
167  }
168  };
169 
175  template<> struct hash<short>
176  {
177  size_t operator()(short __x) const
178  {
179  return __x;
180  }
181  };
182 
188  template<> struct hash<unsigned short>
189  {
190  size_t operator()(unsigned short __x) const
191  {
192  return __x;
193  }
194  };
195 
201  template<> struct hash<int>
202  {
203  size_t operator()(int __x) const
204  {
205  return __x;
206  }
207  };
208 
214  template<> struct hash<unsigned int>
215  {
216  size_t operator()(unsigned int __x) const
217  {
218  return __x;
219  }
220  };
221 
227  template<> struct hash<long>
228  {
229  size_t operator()(long __x) const
230  {
231  return __x;
232  }
233  };
234 
240  template<> struct hash<unsigned long>
241  {
242  size_t operator()(unsigned long __x) const
243  {
244  return __x;
245  }
246  };
247 }
248 
size_t __hash_string(const char *__s)
Hash string.
Definition: Hash.h:71
size_t operator()(unsigned char __x) const
Definition: Hash.h:164
size_t operator()(unsigned long __x) const
Definition: Hash.h:242
size_t operator()(unsigned int __x) const
Definition: Hash.h:216
size_t operator()(const std::string &string) const
Definition: Hash.h:86
size_t operator()(const std::string &string) const
Definition: Hash.h:99
size_t operator()(int __x) const
Definition: Hash.h:203
This Hash class and its implementations are taken from the libstdc++ hash_fun.h.
Definition: Hash.h:45
size_t operator()(const char *__s) const
Definition: Hash.h:112
Namespace that holds various utility classes for the engine.
Definition: SmrtPtr.h:208
size_t operator()(unsigned char __x) const
Definition: Hash.h:151
size_t operator()(char __x) const
Definition: Hash.h:138
size_t operator()(unsigned short __x) const
Definition: Hash.h:190
size_t operator()(const _Key *keyPtr) const
Definition: Hash.h:56
size_t operator()(long __x) const
Definition: Hash.h:229
size_t operator()(const char *__s) const
Definition: Hash.h:125
size_t operator()(short __x) const
Definition: Hash.h:177