... | ... |
@@ -3,31 +3,23 @@ |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2006 iptelorg GmbH |
5 | 5 |
* |
6 |
- * This file is part of ser, a free SIP server. |
|
6 |
+ * Permission to use, copy, modify, and distribute this software for any |
|
7 |
+ * purpose with or without fee is hereby granted, provided that the above |
|
8 |
+ * copyright notice and this permission notice appear in all copies. |
|
7 | 9 |
* |
8 |
- * ser is free software; you can redistribute it and/or modify |
|
9 |
- * it under the terms of the GNU General Public License as published by |
|
10 |
- * the Free Software Foundation; either version 2 of the License, or |
|
11 |
- * (at your option) any later version |
|
12 |
- * |
|
13 |
- * For a license to use the ser software under conditions |
|
14 |
- * other than those described here, or to purchase support for this |
|
15 |
- * software, please contact iptel.org by e-mail at the following addresses: |
|
16 |
- * info@iptel.org |
|
17 |
- * |
|
18 |
- * ser is distributed in the hope that it will be useful, |
|
19 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 |
- * GNU General Public License for more details. |
|
22 |
- * |
|
23 |
- * You should have received a copy of the GNU General Public License |
|
24 |
- * along with this program; if not, write to the Free Software |
|
25 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
10 |
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
11 |
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
12 |
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
13 |
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
14 |
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
15 |
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
16 |
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
26 | 17 |
*/ |
27 | 18 |
/* |
28 | 19 |
* History: |
29 | 20 |
* -------- |
30 | 21 |
* 2006-02-02 created by andrei |
22 |
+ * 2006-11-24 added numeric string optimized hash function (andrei) |
|
31 | 23 |
*/ |
32 | 24 |
|
33 | 25 |
|
... | ... |
@@ -98,6 +90,58 @@ inline static unsigned int get_hash1_raw(char* s, int len) |
98 | 90 |
|
99 | 91 |
|
100 | 92 |
|
93 |
+/* a little slower than hash_* , but better distribution for |
|
94 |
+ * numbers and about the same for strings */ |
|
95 |
+#define hash_update_str2(s, end, p, v, h) \ |
|
96 |
+ do{ \ |
|
97 |
+ for ((p)=(s); (p)<=((end)-4); (p)+=4){ \ |
|
98 |
+ (v)=(*(p)*16777213)+((p)[1]*65537)+((p)[2]*257)+(p)[3]; \ |
|
99 |
+ (h)=16777259*(h)+((v)^((v)<<17)); \ |
|
100 |
+ } \ |
|
101 |
+ (v)=0; \ |
|
102 |
+ for (;(p)<(end); (p)++){ (v)*=251; (v)+=*(p);} \ |
|
103 |
+ (h)=16777259*(h)+((v)^((v)<<17)); \ |
|
104 |
+ }while(0) |
|
105 |
+ |
|
106 |
+/* internal use: call it to adjust the h from hash_update_str */ |
|
107 |
+#define hash_finish2(h) (((h)+((h)>>7))+(((h)>>13)+((h)>>23))) |
|
108 |
+ |
|
109 |
+ |
|
110 |
+ |
|
111 |
+/* a little slower than get_hash1_raw() , but better distribution for |
|
112 |
+ * numbers and about the same for strings */ |
|
113 |
+inline static unsigned int get_hash1_raw2(char* s, int len) |
|
114 |
+{ |
|
115 |
+ char* p; |
|
116 |
+ register unsigned v; |
|
117 |
+ register unsigned h; |
|
118 |
+ |
|
119 |
+ h=0; |
|
120 |
+ |
|
121 |
+ hash_update_str2(s, s+len, p, v, h); |
|
122 |
+ return hash_finish2(h); |
|
123 |
+} |
|
124 |
+ |
|
125 |
+ |
|
126 |
+ |
|
127 |
+/* "raw" 2 strings hash optimized for numeric strings (see above) |
|
128 |
+ * returns an unsigned int (which you can use modulo table_size as hash value) |
|
129 |
+ */ |
|
130 |
+inline static unsigned int get_hash2_raw2(str* key1, str* key2) |
|
131 |
+{ |
|
132 |
+ char* p; |
|
133 |
+ register unsigned v; |
|
134 |
+ register unsigned h; |
|
135 |
+ |
|
136 |
+ h=0; |
|
137 |
+ |
|
138 |
+ hash_update_str2(key1->s, key1->s+key1->len, p, v, h); |
|
139 |
+ hash_update_str2(key2->s, key2->s+key2->len, p, v, h); |
|
140 |
+ return hash_finish(h); |
|
141 |
+} |
|
142 |
+ |
|
143 |
+ |
|
144 |
+ |
|
101 | 145 |
/* generic, simple str keyed hash */ |
102 | 146 |
|
103 | 147 |
struct str_hash_entry{ |