To distance that inserted elements were probed. Used for measuring how good hash functions are.
| 449 | // To distance that inserted elements were probed. Used for measuring how good hash functions |
| 450 | // are. |
| 451 | size_t TotalProbeDistance() const { |
| 452 | size_t total = 0; |
| 453 | for (size_t i = 0; i < NumBuckets(); ++i) { |
| 454 | const T& element = ElementForIndex(i); |
| 455 | if (!emptyfn_.IsEmpty(element)) { |
| 456 | size_t ideal_location = IndexForHash(hashfn_(element)); |
| 457 | if (ideal_location > i) { |
| 458 | total += i + NumBuckets() - ideal_location; |
| 459 | } else { |
| 460 | total += i - ideal_location; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | return total; |
| 465 | } |
| 466 | |
| 467 | // Calculate the current load factor and return it. |
| 468 | double CalculateLoadFactor() const { |