static result_type hash()

in fatal/math/hash.h [47:95]


  static result_type hash(
    result_type state,
    char const *begin,
    char const *end
  ) {
    using step = std::integral_constant<std::size_t, 8>;

    static_assert(
      (step::value & (step::value - 1)) == 0,
      "step must be a power of two"
    );

    assert(begin <= end);
    auto const size = unsigned_cast(std::distance(begin, end));
    assert(size >= 0);

    auto const delta = signed_cast(size - (size & (step::value - 1)));
    auto const tail = std::next(begin, delta);
    assert(begin <= tail);
    assert(tail <= end);

    auto next = [](auto it, auto i) {
      return static_cast<result_type>(*std::next(it, i));
    };

    for (; begin != tail; std::advance(begin, step::value)) {
      assert(begin < tail);

      state ^= state * prime::value + next(begin, 0);
      state ^= state * prime::value + next(begin, 1);
      state ^= state * prime::value + next(begin, 2);
      state ^= state * prime::value + next(begin, 3);
      state ^= state * prime::value + next(begin, 4);
      state ^= state * prime::value + next(begin, 5);
      state ^= state * prime::value + next(begin, 6);
      state ^= state * prime::value + next(begin, 7);
    }

    assert(begin == tail);

    for (; begin != end; std::advance(begin, 1)) {
      assert(begin < end);
      state ^= state * prime::value + next(begin, 0);
    }

    assert(begin == end);

    return state;
  }