| 324 | |
| 325 | |
| 326 | unsigned PathNodePool::Hash( cPosition voidval ) |
| 327 | { |
| 328 | /* |
| 329 | Spent quite some time on this, and the result isn't quite satifactory. The |
| 330 | input set is the size of a cPosition*, and is generally (x,y) pairs or memory pointers. |
| 331 | |
| 332 | FNV resulting in about 45k collisions in a (large) test and some other approaches |
| 333 | about the same. |
| 334 | |
| 335 | Simple folding reduces collisions to about 38k - big improvement. However, that may |
| 336 | be an artifact of the (x,y) pairs being well distributed. And for either the x,y case |
| 337 | or the pointer case, there are probably very poor hash table sizes that cause "overlaps" |
| 338 | and grouping. (An x,y encoding with a hashShift of 8 is begging for trouble.) |
| 339 | |
| 340 | The best tested results are simple folding, but that seems to beg for a pathelogical case. |
| 341 | FNV-1a was the next best choice, without obvious pathelogical holes. |
| 342 | |
| 343 | Finally settled on h%HashMask(). Simple, but doesn't have the obvious collision cases of folding. |
| 344 | */ |
| 345 | /* |
| 346 | // Time: 567 |
| 347 | // FNV-1a |
| 348 | // http://isthe.com/chongo/tech/comp/fnv/ |
| 349 | // public domain. |
| 350 | MP_UPTR val = (MP_UPTR)(voidval); |
| 351 | const unsigned char *p = (unsigned char *)(&val); |
| 352 | unsigned int h = 2166136261; |
| 353 | |
| 354 | for( size_t i=0; i<sizeof(MP_UPTR); ++i, ++p ) { |
| 355 | h ^= *p; |
| 356 | h *= 16777619; |
| 357 | } |
| 358 | // Fold the high bits to the low bits. Doesn't (generally) use all |
| 359 | // the bits since the shift is usually < 16, but better than not |
| 360 | // using the high bits at all. |
| 361 | return ( h ^ (h>>hashShift) ^ (h>>(hashShift*2)) ^ (h>>(hashShift*3)) ) & HashMask(); |
| 362 | */ |
| 363 | /* |
| 364 | // Time: 526 |
| 365 | MP_UPTR h = (MP_UPTR)(voidval); |
| 366 | return ( h ^ (h>>hashShift) ^ (h>>(hashShift*2)) ^ (h>>(hashShift*3)) ) & HashMask(); |
| 367 | */ |
| 368 | |
| 369 | // Time: 512 |
| 370 | // The HashMask() is used as the divisor. h%1024 has lots of common |
| 371 | // repetitions, but h%1023 will move things out more. |
| 372 | MP_UPTR h = (MP_UPTR)(&voidval); |
| 373 | return (h) % HashMask(); |
| 374 | } |
| 375 | |
| 376 | |
| 377 |
nothing calls this directly
no outgoing calls
no test coverage detected