1 //------------------------------------------------------------------------
2 //  Oddball stuff
3 //------------------------------------------------------------------------
4 //
5 //  Copyright (c) 2005-2008  The EDGE Team.
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //------------------------------------------------------------------------
18 
19 #ifndef __MATH_ODDITY_H__
20 #define __MATH_ODDITY_H__
21 
22 namespace epi
23 {
24 
25 int int_sqrt(int value);
26 
27 /* Thomas Wang's 32-bit Mix function */
int_hash(u32_t key)28 inline u32_t int_hash(u32_t key)
29 {
30 	key += ~(key << 15);
31 	key ^=  (key >> 10);
32 	key +=  (key << 3);
33 	key ^=  (key >> 6);
34 	key += ~(key << 11);
35 	key ^=  (key >> 16);
36 
37 	return key;
38 }
39 
str_hash(const char * str)40 inline u32_t str_hash(const char *str)
41 {
42 	u32_t hash = 0;
43 
44 	if (str) while (*str) hash = (hash << 5) - hash + *str++;
45 
46 	return hash;
47 }
48 
49 } // namespace epi
50 
51 #endif /* __MATH_ODDITY_H__ */
52 
53 //--- editor settings ---
54 // vi:ts=4:sw=4:noexpandtab
55