/src/kamailio/src/core/hashes.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2006 iptelorg GmbH |
3 | | * |
4 | | * Permission to use, copy, modify, and distribute this software for any |
5 | | * purpose with or without fee is hereby granted, provided that the above |
6 | | * copyright notice and this permission notice appear in all copies. |
7 | | * |
8 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
10 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
11 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
12 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
13 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
14 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | | */ |
16 | | /*! |
17 | | * \file |
18 | | * \brief Kamailio core :: hash support |
19 | | * \author Andrei |
20 | | * \ingroup core |
21 | | * Module: \ref core |
22 | | */ |
23 | | |
24 | | |
25 | | #ifndef _hashes_h |
26 | | #define _hashes_h |
27 | | |
28 | | #include "str.h" |
29 | | |
30 | | #define core_hash_idx(hid, hsize) ((hid) & (hsize - 1)) |
31 | | |
32 | | /** internal use: hash update |
33 | | * params: char* s - string start, |
34 | | * char* end - end |
35 | | * char* p, and unsigned v temporary vars (used) |
36 | | * unsigned h - result |
37 | | * h should be initialized (e.g. set it to 0), the result in h */ |
38 | | #define hash_update_str(s, end, p, v, h) \ |
39 | 0 | do { \ |
40 | 0 | for((p) = (s); (p) <= ((end)-4); (p) += 4) { \ |
41 | 0 | (v) = (*(p) << 24) + ((p)[1] << 16) + ((p)[2] << 8) + (p)[3]; \ |
42 | 0 | (h) += (v) ^ ((v) >> 3); \ |
43 | 0 | } \ |
44 | 0 | switch((end) - (p)) { \ |
45 | 0 | case 3: \ |
46 | 0 | (v) = (*(p) << 16) + ((p)[1] << 8) + (p)[2]; \ |
47 | 0 | break; \ |
48 | 0 | case 2: \ |
49 | 0 | (v) = (*(p) << 8) + p[1]; \ |
50 | 0 | break; \ |
51 | 0 | case 1: \ |
52 | 0 | (v) = *p; \ |
53 | 0 | break; \ |
54 | 0 | default: \ |
55 | 0 | (v) = 0; \ |
56 | 0 | break; \ |
57 | 0 | } \ |
58 | 0 | (h) += (v) ^ ((v) >> 3); \ |
59 | 0 | } while(0) |
60 | | |
61 | | /** like hash_update_str, but case insensitive |
62 | | * params: char* s - string start, |
63 | | * char* end - end |
64 | | * char* p, and unsigned v temporary vars (used) |
65 | | * unsigned h - result |
66 | | * h should be initialized (e.g. set it to 0), the result in h */ |
67 | | #define hash_update_case_str(s, end, p, v, h) \ |
68 | 0 | do { \ |
69 | 0 | for((p) = (s); (p) <= ((end)-4); (p) += 4) { \ |
70 | 0 | (v) = ((*(p) << 24) + ((p)[1] << 16) + ((p)[2] << 8) + (p)[3]) \ |
71 | 0 | | 0x20202020; \ |
72 | 0 | (h) += (v) ^ ((v) >> 3); \ |
73 | 0 | } \ |
74 | 0 | (v) = 0; \ |
75 | 0 | for(; (p) < (end); (p)++) { \ |
76 | 0 | (v) <<= 8; \ |
77 | 0 | (v) += *(p) | 0x20; \ |
78 | 0 | } \ |
79 | 0 | (h) += (v) ^ ((v) >> 3); \ |
80 | 0 | } while(0) |
81 | | |
82 | | |
83 | | /** internal use: call it to adjust the h from hash_update_str */ |
84 | 0 | #define hash_finish(h) (((h) + ((h) >> 11)) + (((h) >> 13) + ((h) >> 23))) |
85 | | |
86 | | |
87 | | /** "raw" 2 strings hash |
88 | | * returns an unsigned int (which you can use modulo table_size as hash value) |
89 | | */ |
90 | | inline static unsigned int get_hash2_raw(const str *key1, const str *key2) |
91 | 0 | { |
92 | 0 | char *p; |
93 | 0 | register unsigned v; |
94 | 0 | register unsigned h; |
95 | |
|
96 | 0 | h = 0; |
97 | |
|
98 | 0 | hash_update_str(key1->s, key1->s + key1->len, p, v, h); |
99 | 0 | hash_update_str(key2->s, key2->s + key2->len, p, v, h); |
100 | 0 | return hash_finish(h); |
101 | 0 | } Unexecuted instantiation: main.c:get_hash2_raw Unexecuted instantiation: modparam.c:get_hash2_raw Unexecuted instantiation: pt.c:get_hash2_raw Unexecuted instantiation: pvapi.c:get_hash2_raw Unexecuted instantiation: receive.c:get_hash2_raw Unexecuted instantiation: route.c:get_hash2_raw Unexecuted instantiation: rpc_lookup.c:get_hash2_raw Unexecuted instantiation: rvalue.c:get_hash2_raw Unexecuted instantiation: select_core.c:get_hash2_raw Unexecuted instantiation: sr_module.c:get_hash2_raw Unexecuted instantiation: switch.c:get_hash2_raw Unexecuted instantiation: tcp_main.c:get_hash2_raw Unexecuted instantiation: tcp_read.c:get_hash2_raw Unexecuted instantiation: timer_proc.c:get_hash2_raw Unexecuted instantiation: usr_avp.c:get_hash2_raw Unexecuted instantiation: xavp.c:get_hash2_raw Unexecuted instantiation: action.c:get_hash2_raw Unexecuted instantiation: async_task.c:get_hash2_raw Unexecuted instantiation: cfg.tab.c:get_hash2_raw Unexecuted instantiation: core_cmd.c:get_hash2_raw Unexecuted instantiation: counters.c:get_hash2_raw Unexecuted instantiation: dns_cache.c:get_hash2_raw Unexecuted instantiation: dset.c:get_hash2_raw Unexecuted instantiation: dst_blocklist.c:get_hash2_raw Unexecuted instantiation: events.c:get_hash2_raw Unexecuted instantiation: flags.c:get_hash2_raw Unexecuted instantiation: forward.c:get_hash2_raw Unexecuted instantiation: kemi.c:get_hash2_raw Unexecuted instantiation: lvalue.c:get_hash2_raw Unexecuted instantiation: mod_fix.c:get_hash2_raw Unexecuted instantiation: msg_translator.c:get_hash2_raw Unexecuted instantiation: onsend.c:get_hash2_raw |
102 | | |
103 | | |
104 | | /** "raw" 1 string hash |
105 | | * returns an unsigned int (which you can use modulo table_size as hash value) |
106 | | */ |
107 | | inline static unsigned int get_hash1_raw(const char *s, int len) |
108 | 0 | { |
109 | 0 | const char *p; |
110 | 0 | register unsigned v; |
111 | 0 | register unsigned h; |
112 | |
|
113 | 0 | h = 0; |
114 | |
|
115 | 0 | hash_update_str(s, s + len, p, v, h); |
116 | 0 | return hash_finish(h); |
117 | 0 | } Unexecuted instantiation: main.c:get_hash1_raw Unexecuted instantiation: modparam.c:get_hash1_raw Unexecuted instantiation: pt.c:get_hash1_raw Unexecuted instantiation: pvapi.c:get_hash1_raw Unexecuted instantiation: receive.c:get_hash1_raw Unexecuted instantiation: route.c:get_hash1_raw Unexecuted instantiation: rpc_lookup.c:get_hash1_raw Unexecuted instantiation: rvalue.c:get_hash1_raw Unexecuted instantiation: select_core.c:get_hash1_raw Unexecuted instantiation: sr_module.c:get_hash1_raw Unexecuted instantiation: switch.c:get_hash1_raw Unexecuted instantiation: tcp_main.c:get_hash1_raw Unexecuted instantiation: tcp_read.c:get_hash1_raw Unexecuted instantiation: timer_proc.c:get_hash1_raw Unexecuted instantiation: usr_avp.c:get_hash1_raw Unexecuted instantiation: xavp.c:get_hash1_raw Unexecuted instantiation: action.c:get_hash1_raw Unexecuted instantiation: async_task.c:get_hash1_raw Unexecuted instantiation: cfg.tab.c:get_hash1_raw Unexecuted instantiation: core_cmd.c:get_hash1_raw Unexecuted instantiation: counters.c:get_hash1_raw Unexecuted instantiation: dns_cache.c:get_hash1_raw Unexecuted instantiation: dset.c:get_hash1_raw Unexecuted instantiation: dst_blocklist.c:get_hash1_raw Unexecuted instantiation: events.c:get_hash1_raw Unexecuted instantiation: flags.c:get_hash1_raw Unexecuted instantiation: forward.c:get_hash1_raw Unexecuted instantiation: kemi.c:get_hash1_raw Unexecuted instantiation: lvalue.c:get_hash1_raw Unexecuted instantiation: mod_fix.c:get_hash1_raw Unexecuted instantiation: msg_translator.c:get_hash1_raw Unexecuted instantiation: onsend.c:get_hash1_raw |
118 | | |
119 | | |
120 | | /** a little slower than hash_* , but better distribution for |
121 | | * numbers and about the same for strings */ |
122 | | #define hash_update_str2(s, end, p, v, h) \ |
123 | | do { \ |
124 | | for((p) = (s); (p) <= ((end)-4); (p) += 4) { \ |
125 | | (v) = (*(p)*16777213) + ((p)[1] * 65537) + ((p)[2] * 257) \ |
126 | | + (p)[3]; \ |
127 | | (h) = 16777259 * (h) + ((v) ^ ((v) << 17)); \ |
128 | | } \ |
129 | | (v) = 0; \ |
130 | | for(; (p) < (end); (p)++) { \ |
131 | | (v) *= 251; \ |
132 | | (v) += *(p); \ |
133 | | } \ |
134 | | (h) = 16777259 * (h) + ((v) ^ ((v) << 17)); \ |
135 | | } while(0) |
136 | | |
137 | | /** like hash_update_str2 but case insensitive */ |
138 | | #define hash_update_case_str2(s, end, p, v, h) \ |
139 | | do { \ |
140 | | for((p) = (s); (p) <= ((end)-4); (p) += 4) { \ |
141 | | (v) = ((*(p) | 0x20) * 16777213) + (((p)[1] | 0x20) * 65537) \ |
142 | | + (((p)[2] | 0x20) * 257) + ((p)[3] | 0x20); \ |
143 | | (h) = 16777259 * (h) + ((v) ^ ((v) << 17)); \ |
144 | | } \ |
145 | | (v) = 0; \ |
146 | | for(; (p) < (end); (p)++) { \ |
147 | | (v) *= 251; \ |
148 | | (v) += *(p) | 0x20; \ |
149 | | } \ |
150 | | (h) = 16777259 * (h) + ((v) ^ ((v) << 17)); \ |
151 | | } while(0) |
152 | | |
153 | | /** internal use: call it to adjust the h from hash_update_str */ |
154 | | #define hash_finish2(h) (((h) + ((h) >> 7)) + (((h) >> 13) + ((h) >> 23))) |
155 | | |
156 | | |
157 | | /** a little slower than get_hash1_raw() , but better distribution for |
158 | | * numbers and about the same for strings */ |
159 | | inline static unsigned int get_hash1_raw2(const char *s, int len) |
160 | 0 | { |
161 | 0 | const char *p; |
162 | 0 | register unsigned v; |
163 | 0 | register unsigned h; |
164 | 0 |
|
165 | 0 | h = 0; |
166 | 0 |
|
167 | 0 | hash_update_str2(s, s + len, p, v, h); |
168 | 0 | return hash_finish2(h); |
169 | 0 | } Unexecuted instantiation: main.c:get_hash1_raw2 Unexecuted instantiation: modparam.c:get_hash1_raw2 Unexecuted instantiation: pt.c:get_hash1_raw2 Unexecuted instantiation: pvapi.c:get_hash1_raw2 Unexecuted instantiation: receive.c:get_hash1_raw2 Unexecuted instantiation: route.c:get_hash1_raw2 Unexecuted instantiation: rpc_lookup.c:get_hash1_raw2 Unexecuted instantiation: rvalue.c:get_hash1_raw2 Unexecuted instantiation: select_core.c:get_hash1_raw2 Unexecuted instantiation: sr_module.c:get_hash1_raw2 Unexecuted instantiation: switch.c:get_hash1_raw2 Unexecuted instantiation: tcp_main.c:get_hash1_raw2 Unexecuted instantiation: tcp_read.c:get_hash1_raw2 Unexecuted instantiation: timer_proc.c:get_hash1_raw2 Unexecuted instantiation: usr_avp.c:get_hash1_raw2 Unexecuted instantiation: xavp.c:get_hash1_raw2 Unexecuted instantiation: action.c:get_hash1_raw2 Unexecuted instantiation: async_task.c:get_hash1_raw2 Unexecuted instantiation: cfg.tab.c:get_hash1_raw2 Unexecuted instantiation: core_cmd.c:get_hash1_raw2 Unexecuted instantiation: counters.c:get_hash1_raw2 Unexecuted instantiation: dns_cache.c:get_hash1_raw2 Unexecuted instantiation: dset.c:get_hash1_raw2 Unexecuted instantiation: dst_blocklist.c:get_hash1_raw2 Unexecuted instantiation: events.c:get_hash1_raw2 Unexecuted instantiation: flags.c:get_hash1_raw2 Unexecuted instantiation: forward.c:get_hash1_raw2 Unexecuted instantiation: kemi.c:get_hash1_raw2 Unexecuted instantiation: lvalue.c:get_hash1_raw2 Unexecuted instantiation: mod_fix.c:get_hash1_raw2 Unexecuted instantiation: msg_translator.c:get_hash1_raw2 Unexecuted instantiation: onsend.c:get_hash1_raw2 |
170 | | |
171 | | |
172 | | /* "raw" 2 strings hash optimized for numeric strings (see above) |
173 | | * returns an unsigned int (which you can use modulo table_size as hash value) |
174 | | */ |
175 | | inline static unsigned int get_hash2_raw2(const str *key1, const str *key2) |
176 | 0 | { |
177 | 0 | char *p; |
178 | 0 | register unsigned v; |
179 | 0 | register unsigned h; |
180 | 0 |
|
181 | 0 | h = 0; |
182 | 0 |
|
183 | 0 | hash_update_str2(key1->s, key1->s + key1->len, p, v, h); |
184 | 0 | hash_update_str2(key2->s, key2->s + key2->len, p, v, h); |
185 | 0 | return hash_finish2(h); |
186 | 0 | } Unexecuted instantiation: main.c:get_hash2_raw2 Unexecuted instantiation: modparam.c:get_hash2_raw2 Unexecuted instantiation: pt.c:get_hash2_raw2 Unexecuted instantiation: pvapi.c:get_hash2_raw2 Unexecuted instantiation: receive.c:get_hash2_raw2 Unexecuted instantiation: route.c:get_hash2_raw2 Unexecuted instantiation: rpc_lookup.c:get_hash2_raw2 Unexecuted instantiation: rvalue.c:get_hash2_raw2 Unexecuted instantiation: select_core.c:get_hash2_raw2 Unexecuted instantiation: sr_module.c:get_hash2_raw2 Unexecuted instantiation: switch.c:get_hash2_raw2 Unexecuted instantiation: tcp_main.c:get_hash2_raw2 Unexecuted instantiation: tcp_read.c:get_hash2_raw2 Unexecuted instantiation: timer_proc.c:get_hash2_raw2 Unexecuted instantiation: usr_avp.c:get_hash2_raw2 Unexecuted instantiation: xavp.c:get_hash2_raw2 Unexecuted instantiation: action.c:get_hash2_raw2 Unexecuted instantiation: async_task.c:get_hash2_raw2 Unexecuted instantiation: cfg.tab.c:get_hash2_raw2 Unexecuted instantiation: core_cmd.c:get_hash2_raw2 Unexecuted instantiation: counters.c:get_hash2_raw2 Unexecuted instantiation: dns_cache.c:get_hash2_raw2 Unexecuted instantiation: dset.c:get_hash2_raw2 Unexecuted instantiation: dst_blocklist.c:get_hash2_raw2 Unexecuted instantiation: events.c:get_hash2_raw2 Unexecuted instantiation: flags.c:get_hash2_raw2 Unexecuted instantiation: forward.c:get_hash2_raw2 Unexecuted instantiation: kemi.c:get_hash2_raw2 Unexecuted instantiation: lvalue.c:get_hash2_raw2 Unexecuted instantiation: mod_fix.c:get_hash2_raw2 Unexecuted instantiation: msg_translator.c:get_hash2_raw2 Unexecuted instantiation: onsend.c:get_hash2_raw2 |
187 | | |
188 | | |
189 | | /* "raw" 2 strings case insensitive hash (like get_hash2_raw but case |
190 | | * insensitive) |
191 | | * returns an unsigned int (which you can use modulo table_size as hash value) |
192 | | */ |
193 | | inline static unsigned int get_hash2_case_raw(const str *key1, const str *key2) |
194 | 0 | { |
195 | 0 | char *p; |
196 | 0 | register unsigned v; |
197 | 0 | register unsigned h; |
198 | 0 |
|
199 | 0 | h = 0; |
200 | 0 |
|
201 | 0 | hash_update_case_str(key1->s, key1->s + key1->len, p, v, h); |
202 | 0 | hash_update_case_str(key2->s, key2->s + key2->len, p, v, h); |
203 | 0 | return hash_finish(h); |
204 | 0 | } Unexecuted instantiation: main.c:get_hash2_case_raw Unexecuted instantiation: modparam.c:get_hash2_case_raw Unexecuted instantiation: pt.c:get_hash2_case_raw Unexecuted instantiation: pvapi.c:get_hash2_case_raw Unexecuted instantiation: receive.c:get_hash2_case_raw Unexecuted instantiation: route.c:get_hash2_case_raw Unexecuted instantiation: rpc_lookup.c:get_hash2_case_raw Unexecuted instantiation: rvalue.c:get_hash2_case_raw Unexecuted instantiation: select_core.c:get_hash2_case_raw Unexecuted instantiation: sr_module.c:get_hash2_case_raw Unexecuted instantiation: switch.c:get_hash2_case_raw Unexecuted instantiation: tcp_main.c:get_hash2_case_raw Unexecuted instantiation: tcp_read.c:get_hash2_case_raw Unexecuted instantiation: timer_proc.c:get_hash2_case_raw Unexecuted instantiation: usr_avp.c:get_hash2_case_raw Unexecuted instantiation: xavp.c:get_hash2_case_raw Unexecuted instantiation: action.c:get_hash2_case_raw Unexecuted instantiation: async_task.c:get_hash2_case_raw Unexecuted instantiation: cfg.tab.c:get_hash2_case_raw Unexecuted instantiation: core_cmd.c:get_hash2_case_raw Unexecuted instantiation: counters.c:get_hash2_case_raw Unexecuted instantiation: dns_cache.c:get_hash2_case_raw Unexecuted instantiation: dset.c:get_hash2_case_raw Unexecuted instantiation: dst_blocklist.c:get_hash2_case_raw Unexecuted instantiation: events.c:get_hash2_case_raw Unexecuted instantiation: flags.c:get_hash2_case_raw Unexecuted instantiation: forward.c:get_hash2_case_raw Unexecuted instantiation: kemi.c:get_hash2_case_raw Unexecuted instantiation: lvalue.c:get_hash2_case_raw Unexecuted instantiation: mod_fix.c:get_hash2_case_raw Unexecuted instantiation: msg_translator.c:get_hash2_case_raw Unexecuted instantiation: onsend.c:get_hash2_case_raw |
205 | | |
206 | | |
207 | | /* "raw" 1 string case insensitive hash |
208 | | * returns an unsigned int (which you can use modulo table_size as hash value) |
209 | | */ |
210 | | inline static unsigned int get_hash1_case_raw(const char *s, int len) |
211 | 0 | { |
212 | 0 | const char *p; |
213 | 0 | register unsigned v; |
214 | 0 | register unsigned h; |
215 | |
|
216 | 0 | h = 0; |
217 | |
|
218 | 0 | hash_update_case_str(s, s + len, p, v, h); |
219 | 0 | return hash_finish(h); |
220 | 0 | } Unexecuted instantiation: main.c:get_hash1_case_raw Unexecuted instantiation: modparam.c:get_hash1_case_raw Unexecuted instantiation: pt.c:get_hash1_case_raw Unexecuted instantiation: pvapi.c:get_hash1_case_raw Unexecuted instantiation: receive.c:get_hash1_case_raw Unexecuted instantiation: route.c:get_hash1_case_raw Unexecuted instantiation: rpc_lookup.c:get_hash1_case_raw Unexecuted instantiation: rvalue.c:get_hash1_case_raw Unexecuted instantiation: select_core.c:get_hash1_case_raw Unexecuted instantiation: sr_module.c:get_hash1_case_raw Unexecuted instantiation: switch.c:get_hash1_case_raw Unexecuted instantiation: tcp_main.c:get_hash1_case_raw Unexecuted instantiation: tcp_read.c:get_hash1_case_raw Unexecuted instantiation: timer_proc.c:get_hash1_case_raw Unexecuted instantiation: usr_avp.c:get_hash1_case_raw Unexecuted instantiation: xavp.c:get_hash1_case_raw Unexecuted instantiation: action.c:get_hash1_case_raw Unexecuted instantiation: async_task.c:get_hash1_case_raw Unexecuted instantiation: cfg.tab.c:get_hash1_case_raw Unexecuted instantiation: core_cmd.c:get_hash1_case_raw Unexecuted instantiation: counters.c:get_hash1_case_raw Unexecuted instantiation: dns_cache.c:get_hash1_case_raw Unexecuted instantiation: dset.c:get_hash1_case_raw Unexecuted instantiation: dst_blocklist.c:get_hash1_case_raw Unexecuted instantiation: events.c:get_hash1_case_raw Unexecuted instantiation: flags.c:get_hash1_case_raw Unexecuted instantiation: forward.c:get_hash1_case_raw Unexecuted instantiation: kemi.c:get_hash1_case_raw Unexecuted instantiation: lvalue.c:get_hash1_case_raw Unexecuted instantiation: mod_fix.c:get_hash1_case_raw Unexecuted instantiation: msg_translator.c:get_hash1_case_raw Unexecuted instantiation: onsend.c:get_hash1_case_raw |
221 | | |
222 | | |
223 | | /* same as get_hash1_raw2, but case insensitive and slower |
224 | | * returns an unsigned int (which you can use modulo table_size as hash value) |
225 | | */ |
226 | | inline static unsigned int get_hash1_case_raw2(const char *s, int len) |
227 | 0 | { |
228 | 0 | const char *p; |
229 | 0 | register unsigned v; |
230 | 0 | register unsigned h; |
231 | 0 |
|
232 | 0 | h = 0; |
233 | 0 |
|
234 | 0 | hash_update_case_str2(s, s + len, p, v, h); |
235 | 0 | return hash_finish2(h); |
236 | 0 | } Unexecuted instantiation: main.c:get_hash1_case_raw2 Unexecuted instantiation: modparam.c:get_hash1_case_raw2 Unexecuted instantiation: pt.c:get_hash1_case_raw2 Unexecuted instantiation: pvapi.c:get_hash1_case_raw2 Unexecuted instantiation: receive.c:get_hash1_case_raw2 Unexecuted instantiation: route.c:get_hash1_case_raw2 Unexecuted instantiation: rpc_lookup.c:get_hash1_case_raw2 Unexecuted instantiation: rvalue.c:get_hash1_case_raw2 Unexecuted instantiation: select_core.c:get_hash1_case_raw2 Unexecuted instantiation: sr_module.c:get_hash1_case_raw2 Unexecuted instantiation: switch.c:get_hash1_case_raw2 Unexecuted instantiation: tcp_main.c:get_hash1_case_raw2 Unexecuted instantiation: tcp_read.c:get_hash1_case_raw2 Unexecuted instantiation: timer_proc.c:get_hash1_case_raw2 Unexecuted instantiation: usr_avp.c:get_hash1_case_raw2 Unexecuted instantiation: xavp.c:get_hash1_case_raw2 Unexecuted instantiation: action.c:get_hash1_case_raw2 Unexecuted instantiation: async_task.c:get_hash1_case_raw2 Unexecuted instantiation: cfg.tab.c:get_hash1_case_raw2 Unexecuted instantiation: core_cmd.c:get_hash1_case_raw2 Unexecuted instantiation: counters.c:get_hash1_case_raw2 Unexecuted instantiation: dns_cache.c:get_hash1_case_raw2 Unexecuted instantiation: dset.c:get_hash1_case_raw2 Unexecuted instantiation: dst_blocklist.c:get_hash1_case_raw2 Unexecuted instantiation: events.c:get_hash1_case_raw2 Unexecuted instantiation: flags.c:get_hash1_case_raw2 Unexecuted instantiation: forward.c:get_hash1_case_raw2 Unexecuted instantiation: kemi.c:get_hash1_case_raw2 Unexecuted instantiation: lvalue.c:get_hash1_case_raw2 Unexecuted instantiation: mod_fix.c:get_hash1_case_raw2 Unexecuted instantiation: msg_translator.c:get_hash1_case_raw2 Unexecuted instantiation: onsend.c:get_hash1_case_raw2 |
237 | | |
238 | | |
239 | | /* "raw" 2 strings hash optimized for numeric strings (see above) |
240 | | * same as get_hash2_raw2 but case insensitive and slower |
241 | | * returns an unsigned int (which you can use modulo table_size as hash value) |
242 | | */ |
243 | | inline static unsigned int get_hash2_case_raw2(const str *key1, const str *key2) |
244 | 0 | { |
245 | 0 | char *p; |
246 | 0 | register unsigned v; |
247 | 0 | register unsigned h; |
248 | 0 |
|
249 | 0 | h = 0; |
250 | 0 |
|
251 | 0 | hash_update_case_str2(key1->s, key1->s + key1->len, p, v, h); |
252 | 0 | hash_update_case_str2(key2->s, key2->s + key2->len, p, v, h); |
253 | 0 | return hash_finish2(h); |
254 | 0 | } Unexecuted instantiation: main.c:get_hash2_case_raw2 Unexecuted instantiation: modparam.c:get_hash2_case_raw2 Unexecuted instantiation: pt.c:get_hash2_case_raw2 Unexecuted instantiation: pvapi.c:get_hash2_case_raw2 Unexecuted instantiation: receive.c:get_hash2_case_raw2 Unexecuted instantiation: route.c:get_hash2_case_raw2 Unexecuted instantiation: rpc_lookup.c:get_hash2_case_raw2 Unexecuted instantiation: rvalue.c:get_hash2_case_raw2 Unexecuted instantiation: select_core.c:get_hash2_case_raw2 Unexecuted instantiation: sr_module.c:get_hash2_case_raw2 Unexecuted instantiation: switch.c:get_hash2_case_raw2 Unexecuted instantiation: tcp_main.c:get_hash2_case_raw2 Unexecuted instantiation: tcp_read.c:get_hash2_case_raw2 Unexecuted instantiation: timer_proc.c:get_hash2_case_raw2 Unexecuted instantiation: usr_avp.c:get_hash2_case_raw2 Unexecuted instantiation: xavp.c:get_hash2_case_raw2 Unexecuted instantiation: action.c:get_hash2_case_raw2 Unexecuted instantiation: async_task.c:get_hash2_case_raw2 Unexecuted instantiation: cfg.tab.c:get_hash2_case_raw2 Unexecuted instantiation: core_cmd.c:get_hash2_case_raw2 Unexecuted instantiation: counters.c:get_hash2_case_raw2 Unexecuted instantiation: dns_cache.c:get_hash2_case_raw2 Unexecuted instantiation: dset.c:get_hash2_case_raw2 Unexecuted instantiation: dst_blocklist.c:get_hash2_case_raw2 Unexecuted instantiation: events.c:get_hash2_case_raw2 Unexecuted instantiation: flags.c:get_hash2_case_raw2 Unexecuted instantiation: forward.c:get_hash2_case_raw2 Unexecuted instantiation: kemi.c:get_hash2_case_raw2 Unexecuted instantiation: lvalue.c:get_hash2_case_raw2 Unexecuted instantiation: mod_fix.c:get_hash2_case_raw2 Unexecuted instantiation: msg_translator.c:get_hash2_case_raw2 Unexecuted instantiation: onsend.c:get_hash2_case_raw2 |
255 | | |
256 | | |
257 | | /* |
258 | | * generic hashing - from the initial origins of ser |
259 | | */ |
260 | | #define ch_h_inc h += v ^ (v >> 3) |
261 | | #define ch_icase(_c) (((_c) >= 'A' && (_c) <= 'Z') ? ((_c) | 0x20) : (_c)) |
262 | | |
263 | | /* |
264 | | * case sensitive hashing |
265 | | * - s1 - str to hash |
266 | | * - s2 - optional - continue hashing over s2 |
267 | | * - size - optional - size of hash table (must be power of 1); if set (!=0), |
268 | | * instead of hash id, returned value is slot index |
269 | | * return computed hash id or hash table slot index |
270 | | */ |
271 | | static inline unsigned int core_hash( |
272 | | const str *s1, const str *s2, const unsigned int size) |
273 | 0 | { |
274 | 0 | char *p, *end; |
275 | 0 | register unsigned v; |
276 | 0 | register unsigned h; |
277 | 0 |
|
278 | 0 | h = 0; |
279 | 0 |
|
280 | 0 | end = s1->s + s1->len; |
281 | 0 | for(p = s1->s; p <= (end - 4); p += 4) { |
282 | 0 | v = ((unsigned int)p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3]; |
283 | 0 | ch_h_inc; |
284 | 0 | } |
285 | 0 | v = 0; |
286 | 0 | for(; p < end; p++) { |
287 | 0 | v <<= 8; |
288 | 0 | v += *p; |
289 | 0 | } |
290 | 0 | ch_h_inc; |
291 | 0 |
|
292 | 0 | if(s2) { |
293 | 0 | end = s2->s + s2->len; |
294 | 0 | for(p = s2->s; p <= (end - 4); p += 4) { |
295 | 0 | v = ((unsigned int)p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3]; |
296 | 0 | ch_h_inc; |
297 | 0 | } |
298 | 0 | v = 0; |
299 | 0 | for(; p < end; p++) { |
300 | 0 | v <<= 8; |
301 | 0 | v += p[0]; |
302 | 0 | } |
303 | 0 | ch_h_inc; |
304 | 0 | } |
305 | 0 | h = ((h) + (h >> 11)) + ((h >> 13) + (h >> 23)); |
306 | 0 | return size ? ((h) & (size - 1)) : h; |
307 | 0 | } Unexecuted instantiation: main.c:core_hash Unexecuted instantiation: modparam.c:core_hash Unexecuted instantiation: pt.c:core_hash Unexecuted instantiation: pvapi.c:core_hash Unexecuted instantiation: receive.c:core_hash Unexecuted instantiation: route.c:core_hash Unexecuted instantiation: rpc_lookup.c:core_hash Unexecuted instantiation: rvalue.c:core_hash Unexecuted instantiation: select_core.c:core_hash Unexecuted instantiation: sr_module.c:core_hash Unexecuted instantiation: switch.c:core_hash Unexecuted instantiation: tcp_main.c:core_hash Unexecuted instantiation: tcp_read.c:core_hash Unexecuted instantiation: timer_proc.c:core_hash Unexecuted instantiation: usr_avp.c:core_hash Unexecuted instantiation: xavp.c:core_hash Unexecuted instantiation: action.c:core_hash Unexecuted instantiation: async_task.c:core_hash Unexecuted instantiation: cfg.tab.c:core_hash Unexecuted instantiation: core_cmd.c:core_hash Unexecuted instantiation: counters.c:core_hash Unexecuted instantiation: dns_cache.c:core_hash Unexecuted instantiation: dset.c:core_hash Unexecuted instantiation: dst_blocklist.c:core_hash Unexecuted instantiation: events.c:core_hash Unexecuted instantiation: flags.c:core_hash Unexecuted instantiation: forward.c:core_hash Unexecuted instantiation: kemi.c:core_hash Unexecuted instantiation: lvalue.c:core_hash Unexecuted instantiation: mod_fix.c:core_hash Unexecuted instantiation: msg_translator.c:core_hash Unexecuted instantiation: onsend.c:core_hash |
308 | | |
309 | | |
310 | | /* |
311 | | * case insensitive hashing |
312 | | * - s1 - str to hash |
313 | | * - s2 - optional - continue hashing over s2 |
314 | | * - size - optional - size of hash table (must be power of 1); if set (!=0), |
315 | | * instead of hash id, returned value is slot index |
316 | | * return computed hash id or hash table slot index |
317 | | */ |
318 | | static inline unsigned int core_case_hash(str *s1, str *s2, unsigned int size) |
319 | 0 | { |
320 | 0 | char *p, *end; |
321 | 0 | register unsigned v; |
322 | 0 | register unsigned h; |
323 | 0 |
|
324 | 0 | h = 0; |
325 | 0 |
|
326 | 0 | end = s1->s + s1->len; |
327 | 0 | for(p = s1->s; p <= (end - 4); p += 4) { |
328 | 0 | v = (ch_icase(*p) << 24) + (ch_icase(p[1]) << 16) |
329 | 0 | + (ch_icase(p[2]) << 8) + ch_icase(p[3]); |
330 | 0 | ch_h_inc; |
331 | 0 | } |
332 | 0 | v = 0; |
333 | 0 | for(; p < end; p++) { |
334 | 0 | v <<= 8; |
335 | 0 | v += ch_icase(*p); |
336 | 0 | } |
337 | 0 | ch_h_inc; |
338 | 0 |
|
339 | 0 | if(s2) { |
340 | 0 | end = s2->s + s2->len; |
341 | 0 | for(p = s2->s; p <= (end - 4); p += 4) { |
342 | 0 | v = (ch_icase(*p) << 24) + (ch_icase(p[1]) << 16) |
343 | 0 | + (ch_icase(p[2]) << 8) + ch_icase(p[3]); |
344 | 0 | ch_h_inc; |
345 | 0 | } |
346 | 0 | v = 0; |
347 | 0 | for(; p < end; p++) { |
348 | 0 | v <<= 8; |
349 | 0 | v += ch_icase(*p); |
350 | 0 | } |
351 | 0 | ch_h_inc; |
352 | 0 | } |
353 | 0 | h = ((h) + (h >> 11)) + ((h >> 13) + (h >> 23)); |
354 | 0 | return size ? ((h) & (size - 1)) : h; |
355 | 0 | } Unexecuted instantiation: main.c:core_case_hash Unexecuted instantiation: modparam.c:core_case_hash Unexecuted instantiation: pt.c:core_case_hash Unexecuted instantiation: pvapi.c:core_case_hash Unexecuted instantiation: receive.c:core_case_hash Unexecuted instantiation: route.c:core_case_hash Unexecuted instantiation: rpc_lookup.c:core_case_hash Unexecuted instantiation: rvalue.c:core_case_hash Unexecuted instantiation: select_core.c:core_case_hash Unexecuted instantiation: sr_module.c:core_case_hash Unexecuted instantiation: switch.c:core_case_hash Unexecuted instantiation: tcp_main.c:core_case_hash Unexecuted instantiation: tcp_read.c:core_case_hash Unexecuted instantiation: timer_proc.c:core_case_hash Unexecuted instantiation: usr_avp.c:core_case_hash Unexecuted instantiation: xavp.c:core_case_hash Unexecuted instantiation: action.c:core_case_hash Unexecuted instantiation: async_task.c:core_case_hash Unexecuted instantiation: cfg.tab.c:core_case_hash Unexecuted instantiation: core_cmd.c:core_case_hash Unexecuted instantiation: counters.c:core_case_hash Unexecuted instantiation: dns_cache.c:core_case_hash Unexecuted instantiation: dset.c:core_case_hash Unexecuted instantiation: dst_blocklist.c:core_case_hash Unexecuted instantiation: events.c:core_case_hash Unexecuted instantiation: flags.c:core_case_hash Unexecuted instantiation: forward.c:core_case_hash Unexecuted instantiation: kemi.c:core_case_hash Unexecuted instantiation: lvalue.c:core_case_hash Unexecuted instantiation: mod_fix.c:core_case_hash Unexecuted instantiation: msg_translator.c:core_case_hash Unexecuted instantiation: onsend.c:core_case_hash |
356 | | |
357 | | |
358 | | #endif |