... | ... |
@@ -111,15 +111,24 @@ int new_hash( str call_id, str cseq_nr ) |
111 | 111 |
//hash_code+=crc_32_tab[(cseq_nr.s[i]+hash_code)%243]; |
112 | 112 |
hash_code+=ccitt_tab[*(cs+i)+123]; |
113 | 113 |
|
114 |
+ /* hash_code conditioning */ |
|
114 | 115 |
#ifdef _BUG |
116 |
+ /* not flat ... % 111b has shorter period than |
|
117 |
+ & 111b by one and results in different distribution; |
|
118 |
+ ( 7 % 7 == 0, 7 %7 == 1 ) |
|
119 |
+ % is used as a part of the hash function too, not only |
|
120 |
+ for rounding; & is not flat; whoever comes up with |
|
121 |
+ a nicer flat hash function which does not take |
|
122 |
+ costly division is welcome; feel free to verify |
|
123 |
+ distribution using hashtest() |
|
124 |
+ */ |
|
115 | 125 |
hash_code &= (TABLE_ENTRIES-1); /* TABLE_ENTRIES = 2^k */ |
116 | 126 |
#endif |
117 |
- /* hash_code conditioning */ |
|
118 | 127 |
hash_code=hash_code%(TABLE_ENTRIES-1)+1; |
119 | 128 |
return hash_code; |
120 | 129 |
} |
121 | 130 |
|
122 |
-void hashtest_cycle( int hits[TABLE_ENTRIES], char *ip ) |
|
131 |
+void hashtest_cycle( int hits[TABLE_ENTRIES+5], char *ip ) |
|
123 | 132 |
{ |
124 | 133 |
long int i,j,k, l; |
125 | 134 |
int hashv; |
... | ... |
@@ -151,20 +160,23 @@ int init_hash() |
151 | 160 |
1<<10); |
152 | 161 |
LOG(L_WARN, "WARNING: use of %d entries may lead " |
153 | 162 |
"to unflat distribution\n", TABLE_ENTRIES ); |
163 |
+ } else { |
|
164 |
+ DBG("DEBUG: hash function initialized with optimum table size\n"); |
|
154 | 165 |
} |
155 | 166 |
return 1; |
156 | 167 |
} |
157 | 168 |
|
158 | 169 |
void hashtest() |
159 | 170 |
{ |
160 |
- int hits[TABLE_ENTRIES]; |
|
171 |
+ int hits[TABLE_ENTRIES+5]; |
|
161 | 172 |
int i; |
162 |
- |
|
173 |
+ |
|
174 |
+ init_hash(); |
|
163 | 175 |
memset( hits, 0, sizeof hits ); |
164 | 176 |
hashtest_cycle( hits, "192.168.99.100" ); |
165 | 177 |
hashtest_cycle( hits, "172.168.99.100" ); |
166 | 178 |
hashtest_cycle( hits, "142.168.99.100" ); |
167 |
- for (i=0; i<TABLE_ENTRIES; i++) |
|
179 |
+ for (i=0; i<TABLE_ENTRIES+5; i++) |
|
168 | 180 |
printf("[%d. %d]\n", i, hits[i] ); |
169 | 181 |
exit(0); |
170 | 182 |
} |