| 690 | } |
| 691 | |
| 692 | inline size_t hash_bytes(void const* ptr, size_t len) noexcept { |
| 693 | static constexpr uint64_t m = UINT64_C(0xc6a4a7935bd1e995); |
| 694 | static constexpr uint64_t seed = UINT64_C(0xe17a1465); |
| 695 | static constexpr unsigned int r = 47; |
| 696 | |
| 697 | auto const* const data64 = static_cast<uint64_t const*>(ptr); |
| 698 | uint64_t h = seed ^ (len * m); |
| 699 | |
| 700 | size_t const n_blocks = len / 8; |
| 701 | for (size_t i = 0; i < n_blocks; ++i) { |
| 702 | auto k = detail::unaligned_load<uint64_t>(data64 + i); |
| 703 | |
| 704 | k *= m; |
| 705 | k ^= k >> r; |
| 706 | k *= m; |
| 707 | |
| 708 | h ^= k; |
| 709 | h *= m; |
| 710 | } |
| 711 | |
| 712 | auto const* const data8 = reinterpret_cast<uint8_t const*>(data64 + n_blocks); |
| 713 | switch (len & 7U) { |
| 714 | case 7: |
| 715 | h ^= static_cast<uint64_t>(data8[6]) << 48U; |
| 716 | ROBIN_HOOD(FALLTHROUGH); // FALLTHROUGH |
| 717 | case 6: |
| 718 | h ^= static_cast<uint64_t>(data8[5]) << 40U; |
| 719 | ROBIN_HOOD(FALLTHROUGH); // FALLTHROUGH |
| 720 | case 5: |
| 721 | h ^= static_cast<uint64_t>(data8[4]) << 32U; |
| 722 | ROBIN_HOOD(FALLTHROUGH); // FALLTHROUGH |
| 723 | case 4: |
| 724 | h ^= static_cast<uint64_t>(data8[3]) << 24U; |
| 725 | ROBIN_HOOD(FALLTHROUGH); // FALLTHROUGH |
| 726 | case 3: |
| 727 | h ^= static_cast<uint64_t>(data8[2]) << 16U; |
| 728 | ROBIN_HOOD(FALLTHROUGH); // FALLTHROUGH |
| 729 | case 2: |
| 730 | h ^= static_cast<uint64_t>(data8[1]) << 8U; |
| 731 | ROBIN_HOOD(FALLTHROUGH); // FALLTHROUGH |
| 732 | case 1: |
| 733 | h ^= static_cast<uint64_t>(data8[0]); |
| 734 | h *= m; |
| 735 | ROBIN_HOOD(FALLTHROUGH); // FALLTHROUGH |
| 736 | default: |
| 737 | break; |
| 738 | } |
| 739 | |
| 740 | h ^= h >> r; |
| 741 | |
| 742 | // not doing the final step here, because this will be done by keyToIdx anyways |
| 743 | // h *= m; |
| 744 | // h ^= h >> r; |
| 745 | return static_cast<size_t>(h); |
| 746 | } |
| 747 | |
| 748 | inline size_t hash_int(uint64_t x) noexcept { |
| 749 | // tried lots of different hashes, let's stick with murmurhash3. It's simple, fast, well tested, |
no outgoing calls
no test coverage detected