Go to the documentation of this file.
19 #ifndef ABSL_HASH_INTERNAL_HASH_H_
20 #define ABSL_HASH_INTERNAL_HASH_H_
27 #include <forward_list>
37 #include <type_traits>
41 #include "absl/base/config.h"
42 #include "absl/base/internal/unaligned_access.h"
43 #include "absl/base/port.h"
44 #include "absl/container/fixed_array.h"
46 #include "absl/meta/type_traits.h"
47 #include "absl/numeric/int128.h"
48 #include "absl/strings/string_view.h"
49 #include "absl/types/optional.h"
50 #include "absl/types/variant.h"
51 #include "absl/utility/utility.h"
52 #include "absl/hash/internal/city.h"
56 namespace hash_internal {
82 class PiecewiseCombiner {
97 reinterpret_cast<const unsigned char*
>(
data),
size);
109 template <
typename H>
144 template <
typename H>
145 class HashStateBase {
164 template <
typename T,
typename... Ts>
180 template <
typename T>
219 template <
typename T,
typename Enable =
void>
227 struct is_uniquely_represented<unsigned char> :
std::true_type {};
233 template <
typename Integral>
234 struct is_uniquely_represented<
235 Integral, typename
std::enable_if<std::is_integral<Integral>::value>
::type>
248 template <
typename H,
typename T>
250 const unsigned char*
start =
reinterpret_cast<const unsigned char*
>(&
value);
267 template <
typename H,
typename B>
271 static_cast<unsigned char>(
value ? 1 : 0));
275 template <
typename H,
typename Enum>
277 H hash_state,
Enum e) {
287 template <
typename H,
typename Float>
300 template <
typename H,
typename LongDouble>
303 const int category = std::fpclassify(
value);
307 hash_state = H::combine(
std::move(hash_state), std::signbit(
value));
324 auto mantissa =
static_cast<double>(std::frexp(
value, &exp));
328 return H::combine(
std::move(hash_state), category);
332 template <
typename H,
typename T>
343 template <
typename H>
345 return H::combine(
std::move(hash_state),
static_cast<void*
>(
nullptr));
356 template <
typename T>
360 template <
typename H,
typename T1,
typename T2>
364 return H::combine(
std::move(hash_state),
p.first,
p.second);
371 template <
typename H,
typename Tuple,
size_t... Is>
373 return H::combine(
std::move(hash_state), std::get<Is>(t)...);
377 template <
typename H,
typename... Ts>
378 #if defined(_MSC_VER)
383 typename std::enable_if<absl::conjunction<is_hashable<Ts>...>
::value,
H>
::type
395 template <
typename H,
typename T,
typename D>
401 template <
typename H,
typename T>
424 template <
typename H>
432 template <
typename Char,
typename Alloc,
typename H,
438 const std::basic_string<
Char, std::char_traits<Char>,
Alloc>&
str) {
449 template <
typename H,
typename T,
size_t N>
451 H hash_state,
const std::array<T, N>&
array) {
457 template <
typename H,
typename T,
typename Allocator>
459 H hash_state,
const std::deque<T, Allocator>& deque) {
462 for (
const auto& t : deque) {
463 hash_state = H::combine(
std::move(hash_state), t);
465 return H::combine(
std::move(hash_state), deque.size());
469 template <
typename H,
typename T,
typename Allocator>
471 H hash_state,
const std::forward_list<T, Allocator>& list) {
473 for (
const T& t : list) {
474 hash_state = H::combine(
std::move(hash_state), t);
481 template <
typename H,
typename T,
typename Allocator>
483 H hash_state,
const std::list<T, Allocator>& list) {
484 for (
const auto& t : list) {
485 hash_state = H::combine(
std::move(hash_state), t);
487 return H::combine(
std::move(hash_state), list.size());
494 template <
typename H,
typename T,
typename Allocator>
497 AbslHashValue(
H hash_state,
const std::vector<T, Allocator>& vector) {
498 return H::combine(H::combine_contiguous(
std::move(hash_state), vector.data(),
508 template <
typename H,
typename Key,
typename T,
typename Compare,
513 for (
const auto& t :
map) {
514 hash_state = H::combine(
std::move(hash_state), t);
520 template <
typename H,
typename Key,
typename T,
typename Compare,
525 const std::multimap<Key, T, Compare, Allocator>&
map) {
526 for (
const auto& t :
map) {
527 hash_state = H::combine(
std::move(hash_state), t);
533 template <
typename H,
typename Key,
typename Compare,
typename Allocator>
535 H hash_state,
const std::set<Key, Compare, Allocator>&
set) {
536 for (
const auto& t :
set) {
537 hash_state = H::combine(
std::move(hash_state), t);
543 template <
typename H,
typename Key,
typename Compare,
typename Allocator>
545 H hash_state,
const std::multiset<Key, Compare, Allocator>&
set) {
546 for (
const auto& t :
set) {
547 hash_state = H::combine(
std::move(hash_state), t);
557 template <
typename H,
typename T>
559 H hash_state, std::reference_wrapper<T> opt) {
560 return H::combine(
std::move(hash_state), opt.get());
564 template <
typename H,
typename T>
567 if (opt) hash_state = H::combine(
std::move(hash_state), *opt);
572 template <
typename H>
573 struct VariantVisitor {
575 template <
typename T>
582 template <
typename H,
typename...
T>
583 typename std::enable_if<conjunction<is_hashable<T>...>
::value,
H>
::type
585 if (!
v.valueless_by_exception()) {
588 return H::combine(
std::move(hash_state),
v.index());
606 template <
typename H,
typename T>
609 const auto*
bytes =
reinterpret_cast<const unsigned char*
>(
data);
614 template <
typename H,
typename T>
623 #if defined(ABSL_INTERNAL_LEGACY_HASH_NAMESPACE) && \
624 ABSL_META_INTERNAL_STD_HASH_SFINAE_FRIENDLY_
625 #define ABSL_HASH_INTERNAL_SUPPORT_LEGACY_HASH_ 1
627 #define ABSL_HASH_INTERNAL_SUPPORT_LEGACY_HASH_ 0
641 struct State : HashStateBase<State> {
644 using State::HashStateBase::combine_contiguous;
647 struct UniquelyRepresentedProbe {
648 template <
typename H,
typename T>
655 struct HashValueProbe {
656 template <
typename H,
typename T>
665 struct LegacyHashProbe {
666 #if ABSL_HASH_INTERNAL_SUPPORT_LEGACY_HASH_
667 template <
typename H,
typename T>
670 decltype(ABSL_INTERNAL_LEGACY_HASH_NAMESPACE::hash<T>()(
value)),
675 ABSL_INTERNAL_LEGACY_HASH_NAMESPACE::hash<T>{}(
value));
677 #endif // ABSL_HASH_INTERNAL_SUPPORT_LEGACY_HASH_
680 struct StdHashProbe {
681 template <
typename H,
typename T>
688 template <
typename Hash,
typename T>
689 struct Probe :
Hash {
691 template <
typename H,
typename = decltype(
H::Invoke(
692 std::declval<State>(), std::declval<const T&>()))>
694 template <
typename U>
704 template <
typename T>
706 Probe<UniquelyRepresentedProbe, T>,
707 Probe<HashValueProbe, T>,
708 Probe<LegacyHashProbe, T>,
709 Probe<StdHashProbe, T>,
713 template <
typename T>
715 : std::integral_constant<bool, HashSelect::template Apply<T>::value> {};
721 #ifdef ABSL_HAVE_INTRINSIC_INT128
723 #else // ABSL_HAVE_INTRINSIC_INT128
725 #endif // ABSL_HAVE_INTRINSIC_INT128
728 sizeof(size_t) == 4 ?
uint64_t{0xcc9e2d51}
731 template <
typename T>
732 using IntegralFastPath =
745 const unsigned char*
first,
size_t size) {
748 std::integral_constant<
int,
sizeof(
size_t)>{}));
750 using HashState::HashStateBase::combine_contiguous;
788 const unsigned char*
first,
size_t len,
789 std::integral_constant<int, 4>
792 const unsigned char*
first,
size_t len,
793 std::integral_constant<int, 8>
801 const unsigned char*
first,
804 const unsigned char*
first,
810 static std::pair<uint64_t, uint64_t>
Read9To16(
const unsigned char* p,
814 #ifdef ABSL_IS_LITTLE_ENDIAN
815 uint64_t most_significant = high_mem;
816 uint64_t least_significant = low_mem;
818 uint64_t most_significant = low_mem;
819 uint64_t least_significant = high_mem;
821 return {least_significant, most_significant >> (128 -
len * 8)};
828 #ifdef ABSL_IS_LITTLE_ENDIAN
829 uint32_t most_significant = high_mem;
830 uint32_t least_significant = low_mem;
832 uint32_t most_significant = low_mem;
833 uint32_t least_significant = high_mem;
835 return (
static_cast<uint64_t>(most_significant) << (
len - 4) * 8) |
841 unsigned char mem0 = p[0];
842 unsigned char mem1 = p[
len / 2];
843 unsigned char mem2 = p[
len - 1];
844 #ifdef ABSL_IS_LITTLE_ENDIAN
845 unsigned char significant2 = mem2;
846 unsigned char significant1 = mem1;
847 unsigned char significant0 = mem0;
849 unsigned char significant2 = mem0;
850 unsigned char significant1 = mem1;
851 unsigned char significant0 = mem2;
853 return static_cast<uint32_t>(significant0 |
854 (significant1 << (
len / 2 * 8)) |
855 (significant2 << ((
len - 1) * 8)));
867 return static_cast<uint64_t>(
m ^ (
m >> (
sizeof(
m) * 8 / 2)));
876 #ifdef ABSL_HAVE_INTRINSIC_INT128
900 #if (!defined(__clang__) || __clang_major__ > 11) && \
901 !defined(__apple_build_version__)
917 std::integral_constant<int, 4> ) {
926 }
else if (
len >= 4) {
928 }
else if (
len > 0) {
940 std::integral_constant<int, 8> ) {
949 }
else if (
len > 8) {
953 }
else if (
len >= 4) {
955 }
else if (
len > 0) {
971 struct PoisonedHash :
private AggregateBarrier {
977 template <
typename T>
982 template <
typename T>
986 template <
typename H>
987 template <
typename T,
typename... Ts>
995 template <
typename H>
996 template <
typename T>
1002 template <
typename H>
1018 data += bytes_needed;
1019 size -= bytes_needed;
1035 template <
typename H>
1045 #endif // ABSL_HASH_INTERNAL_HASH_H_
static constexpr bool value
#define ABSL_PREDICT_FALSE(x)
#define ABSL_ATTRIBUTE_ALWAYS_INLINE
static std::true_type Test(int)
PiecewiseCombiner & operator=(const PiecewiseCombiner &)=delete
static uint32_t Read1To3(const unsigned char *p, size_t len)
static size_t hash(T value)
static H combine(H state)
integral_constant< bool, true > true_type
size_t operator()(const T &value) const
static State combine_contiguous(State hash_state, const unsigned char *, size_t)
typename std::conditional< B, T, F >::type conditional_t
integral_constant< bool, false > false_type
static auto Invoke(H state, const T &value) -> absl::enable_if_t< std::is_same< H, decltype(AbslHashValue(std::move(state), value))>::value, H >
static std::pair< uint64_t, uint64_t > Read9To16(const unsigned char *p, size_t len)
static H combine(H state, const T &value, const Ts &... values)
typename std::enable_if< B, T >::type enable_if_t
#define ABSL_NAMESPACE_END
uint64_t CityHash64(const char *s, size_t len)
#define T(upbtypeconst, upbtype, ctype, default_value)
HashState(uint64_t state)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define ABSL_NAMESPACE_BEGIN
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
H add_buffer(H state, const unsigned char *data, size_t size)
constexpr bool has_value() const noexcept
static uint32_t UnalignedLoad32(const void *p)
make_integer_sequence< size_t, N > make_index_sequence
static H combine_contiguous(H state, const T *data, size_t size)
FloatingPoint< float > Float
unsigned __int64 uint64_t
static auto Invoke(H state, const T &value) -> absl::enable_if_t< type_traits_internal::IsHashable< T >::value, H >
static uint64_t Read4To8(const unsigned char *p, size_t len)
void * Alloc(FlagOpFn op)
_W64 unsigned int uintptr_t
H operator()(const T &t) const
H hash_tuple(H hash_state, const Tuple &t, absl::index_sequence< Is... >)
std::enable_if< is_uniquely_represented< T >::value, H >::type hash_range_or_bytes(H hash_state, const T *data, size_t size)
static uint64_t Mix(uint64_t v0, uint64_t v1)
static HashState combine_contiguous(HashState hash_state, const unsigned char *first, size_t size)
std::enable_if< std::is_same< B, bool >::value, H >::type AbslHashValue(H hash_state, B value)
static char data[kDataSize]
PoisonedHash & operator=(const PoisonedHash &)=delete
constexpr size_t PiecewiseChunkSize()
static uint64_t CombineLargeContiguousImpl64(uint64_t state, const unsigned char *first, size_t len)
static const void *const kSeed
internal::KeyMatcher< M > Key(M inner_matcher)
std::array< int64_t, Size > values
H add_buffer(H state, const char *data, size_t size)
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
grpc_connectivity_state state_
unsigned char buf_[PiecewiseChunkSize()]
int Compare(const BigUnsigned< N > &lhs, const BigUnsigned< M > &rhs)
static size_t hash(const T &value)
static uint64_t UnalignedLoad64(const void *p)
variant_internal::VisitResult< Visitor, Variants... > visit(Visitor &&vis, Variants &&... vars)
static uint64_t CombineLargeContiguousImpl32(uint64_t state, const unsigned char *first, size_t len)
static auto Invoke(H state, const T &value) -> absl::enable_if_t< is_uniquely_represented< T >::value, H >
static uint64_t CombineContiguousImpl(uint64_t state, const unsigned char *first, size_t len, std::integral_constant< int, 4 >)
static ABSL_ATTRIBUTE_ALWAYS_INLINE uint64_t Seed()
uint32_t CityHash32(const char *s, size_t len)
static struct rpc_state state
absl::disjunction< Probe< UniquelyRepresentedProbe, T >, Probe< HashValueProbe, T >, Probe< LegacyHashProbe, T >, Probe< StdHashProbe, T >, std::false_type > Apply
H hash_bytes(H hash_state, const T &value)
static ABSL_ATTRIBUTE_ALWAYS_INLINE uint64_t Mix(uint64_t state, uint64_t v)
static ABSL_ATTRIBUTE_ALWAYS_INLINE uint64_t Hash64(const unsigned char *data, size_t len)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:00