acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
_u32hash.h
1#pragma once
2
3
4//#include "acme/prototype/prototype/_u32hash.h"
5
6
7template < >
8inline ::hash32 as_hash32 < const_char_pointer >(const_char_pointer const & p)
9{
10
11 auto psz = p;
12
13 if (::is_null(psz) || *psz == 0)
14 {
15
16 return { 0 };
17
18 }
19
20 ::u32 uHash = 0;
21
22 character_count i = 1;
23
24 for(; psz[i]; i++)
25 {
26
27 if (i % 4 == 3)
28 {
29
30 uHash = (uHash << 5) + ((::u32*)psz)[i>>2];
31
32 }
33
34 }
35
36 psz += i;
37
38 i %= 4;
39
40 if (i > 0)
41 {
42
43 while (i-- >= 0) uHash = (uHash << 5) + *(--psz);
44
45 }
46
47 return { uHash };
48
49}
50
51
52template < >
53inline ::hash32 as_hash32 < const ::wd16_character * >(const ::wd16_character * const & p)
54{
55
56 auto psz = p;
57
58 if (::is_null(psz) || *psz == 0)
59 {
60
61 return { 0 };
62
63 }
64
65 ::u32 uHash = 0;
66
67 character_count i = 1;
68
69 for (; psz[i]; i++)
70 {
71
72 if (i % 2 == 1)
73 {
74
75 uHash = (uHash << 5) + ((::u32*)psz)[i >> 1];
76
77 }
78
79 }
80
81 psz += i;
82
83 i %= 2;
84
85 if (i > 0)
86 {
87
88 while (i-- >= 0) uHash = (uHash << 5) + *(--psz);
89
90 }
91
92 return { uHash };
93
94}
95
96
97template < >
98inline ::hash32 as_hash32 < const ::wd32_character * >(const ::wd32_character * const & p)
99{
100
101 auto psz = p;
102
103 if (::is_null(psz) || *psz == 0)
104 {
105
106 return { 0 };
107
108 }
109
110 ::u32 uHash = 0;
111
112 for (; *psz; psz++)
113 {
114
115 uHash = (uHash << 5) + *psz;
116
117 }
118
119 return { uHash };
120
121}
122
123
124