44#ifndef WPIUTIL_WPI_HASHING_H
45#define WPIUTIL_WPI_HASHING_H
59#pragma warning(disable : 26495)
63template <
typename T,
typename Enable>
struct DenseMapInfo;
89 operator size_t()
const {
return value; }
92 return lhs.value == rhs.value;
95 return lhs.value != rhs.value;
110std::enable_if_t<is_integral_or_enum<T>::value, hash_code>
hash_value(T
value);
118template <
typename T,
typename U>
122template <
typename... Ts>
180 return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
184 return val ^ (val >> 47);
189 const uint64_t kMul = 0x9ddfea08eb382d69ULL;
251 if (length >= 4 && length <= 8)
253 if (length > 8 && length <= 16)
255 if (length > 16 && length <= 32)
336 const uint64_t seed_prime = 0xff51afd7ed558ccdULL;
355 : std::integral_constant<bool, ((is_integral_or_enum<T>::value ||
356 std::is_pointer<T>::value) &&
357 64 % sizeof(T) == 0)> {};
364 : std::integral_constant<bool, (is_hashable_data<T>::value &&
365 is_hashable_data<U>::value &&
366 (sizeof(T) + sizeof(U)) ==
367 sizeof(std::pair<T, U>))> {};
372std::enable_if_t<is_hashable_data<T>::value, T>
380std::enable_if_t<!is_hashable_data<T>::value,
size_t>
396 size_t store_size =
sizeof(
value) - offset;
397 if (buffer_ptr + store_size > buffer_end)
399 const char *value_data =
reinterpret_cast<const char *
>(&
value);
400 memcpy(buffer_ptr, value_data + offset, store_size);
401 buffer_ptr += store_size;
410template <
typename InputIteratorT>
420 assert(buffer_ptr == buffer_end);
439 length += buffer_ptr -
buffer;
453template <
typename ValueT>
454std::enable_if_t<is_hashable_data<ValueT>::value,
hash_code>
457 const char *s_begin =
reinterpret_cast<const char *
>(
first);
458 const char *s_end =
reinterpret_cast<const char *
>(
last);
459 const size_t length = std::distance(s_begin, s_end);
463 const char *s_aligned_end = s_begin + (length & ~63);
466 while (s_begin != s_aligned_end) {
471 state.mix(s_end - 64);
473 return state.finalize(length);
486template <
typename InputIteratorT>
522 template <
typename T>
529 size_t partial_store_size = buffer_end - buffer_ptr;
530 memcpy(buffer_ptr, &
data, partial_store_size);
561 template <
typename T,
typename ...Ts>
563 const T &
arg,
const Ts &...args) {
567 return combine(length, buffer_ptr, buffer_end, args...);
589 length += buffer_ptr -
buffer;
628 const char *s =
reinterpret_cast<const char *
>(&
value);
653template <
typename T,
typename U>
662template <
typename... Ts, std::size_t... Indices>
664 std::index_sequence<Indices...>) {
671template <
typename... Ts>
675 arg,
typename std::index_sequence_for<Ts...>());
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Definition: ArrayCwiseUnaryOps.h:66
#define wpi_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:133
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source code
Definition: ThirdPartyNotices.txt:110
\rst A contiguous memory buffer with an optional growing ability.
Definition: core.h:862
An opaque object representing a hash code.
Definition: Hashing.h:77
hash_code(size_t value)
Form a hash code directly from a numerical value.
Definition: Hashing.h:86
hash_code()=default
Default construct a hash_code.
friend size_t hash_value(const hash_code &code)
Allow a hash_code to be directly run through hash_value.
Definition: Hashing.h:99
friend bool operator==(const hash_code &lhs, const hash_code &rhs)
Definition: Hashing.h:91
friend bool operator!=(const hash_code &lhs, const hash_code &rhs)
Definition: Hashing.h:94
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
Can be used as a parameter to Eigen::seq and Eigen::seqN functions to symbolically reference the last...
Definition: IndexedViewHelper.h:38
const Scalar & y
Definition: MathFunctions.h:821
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
Definition: IndexedViewHelper.h:81
::uint64_t uint64_t
Definition: Meta.h:58
::uint32_t uint32_t
Definition: Meta.h:56
::uint8_t uint8_t
Definition: Meta.h:52
static EIGEN_DEPRECATED const end_t end
Definition: IndexedViewHelper.h:181
Definition: format-inl.h:32
uint128_t uintptr_t
Definition: format.h:432
result
Definition: format.h:2564
Definition: BFloat16.h:88
void swap(wpi::SmallPtrSet< T, N > &LHS, wpi::SmallPtrSet< T, N > &RHS)
Implement std::swap in terms of SmallPtrSet swap.
Definition: SmallPtrSet.h:512
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
uint32_t fetch32(const char *p)
Definition: Hashing.h:161
static constexpr uint64_t k1
Definition: Hashing.h:171
uint64_t hash_4to8_bytes(const char *s, size_t len, uint64_t seed)
Definition: Hashing.h:207
hash_code hash_integer_value(uint64_t value)
Helper to hash the value of a single integer.
Definition: Hashing.h:625
std::enable_if_t< is_hashable_data< ValueT >::value, hash_code > hash_combine_range_impl(ValueT *first, ValueT *last)
Implement the combining of integral values into a hash_code.
Definition: Hashing.h:455
hash_code hash_value_tuple_helper(const std::tuple< Ts... > &arg, std::index_sequence< Indices... >)
Definition: Hashing.h:663
uint64_t hash_1to3_bytes(const char *s, size_t len, uint64_t seed)
Definition: Hashing.h:198
uint64_t rotate(uint64_t val, size_t shift)
Bitwise right rotate.
Definition: Hashing.h:178
hash_code hash_combine_range_impl(InputIteratorT first, InputIteratorT last)
Implement the combining of integral values into a hash_code.
Definition: Hashing.h:411
static constexpr uint64_t k3
Definition: Hashing.h:173
static constexpr uint64_t k2
Definition: Hashing.h:172
uint64_t fixed_seed_override
A global, fixed seed-override variable.
static constexpr uint64_t k0
Some primes between 2^63 and 2^64 for various uses.
Definition: Hashing.h:170
std::enable_if_t< is_hashable_data< T >::value, T > get_hashable_data(const T &value)
Helper to get the hashable data representation for a type.
Definition: Hashing.h:373
uint64_t hash_16_bytes(uint64_t low, uint64_t high)
Definition: Hashing.h:187
uint64_t hash_9to16_bytes(const char *s, size_t len, uint64_t seed)
Definition: Hashing.h:212
uint64_t hash_33to64_bytes(const char *s, size_t len, uint64_t seed)
Definition: Hashing.h:227
uint64_t fetch64(const char *p)
Definition: Hashing.h:153
uint64_t hash_17to32_bytes(const char *s, size_t len, uint64_t seed)
Definition: Hashing.h:218
uint64_t get_execution_seed()
Definition: Hashing.h:329
bool store_and_advance(char *&buffer_ptr, char *buffer_end, const T &value, size_t offset=0)
Helper to store data from a value into a buffer and advance the pointer into that buffer.
Definition: Hashing.h:394
uint64_t shift_mix(uint64_t val)
Definition: Hashing.h:183
uint64_t hash_short(const char *s, size_t length, uint64_t seed)
Definition: Hashing.h:250
void swapByteOrder(T &Value)
Definition: SwapByteOrder.h:158
constexpr bool IsBigEndianHost
Definition: SwapByteOrder.h:98
Definition: AprilTagFieldLayout.h:18
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:487
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:609
hash_code hash_value(const std::basic_string< T > &arg)
Compute a hash_code for a standard string.
Definition: Hashing.h:681
std::enable_if_t< is_integral_or_enum< T >::value, hash_code > hash_value(T value)
Compute a hash_code for any integer value.
Definition: Hashing.h:639
void set_fixed_execution_hash_seed(uint64_t fixed_value)
Override the execution seed with a fixed value.
Definition: format.h:1552
static unsigned getHashValue(hash_code val)
Definition: Hashing.h:688
static hash_code getTombstoneKey()
Definition: Hashing.h:687
static bool isEqual(hash_code LHS, hash_code RHS)
Definition: Hashing.h:689
static hash_code getEmptyKey()
Definition: Hashing.h:686
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:49
Helper class to manage the recursive combining of hash_combine arguments.
Definition: Hashing.h:503
char * combine_data(size_t &length, char *buffer_ptr, char *buffer_end, T data)
Combine one chunk of data into the current in-flight hash.
Definition: Hashing.h:523
const uint64_t seed
Definition: Hashing.h:506
hash_state state
Definition: Hashing.h:505
hash_code combine(size_t length, char *buffer_ptr, char *buffer_end, const T &arg, const Ts &...args)
Recursive, variadic combining method.
Definition: Hashing.h:562
hash_code combine(size_t length, char *buffer_ptr, char *buffer_end)
Base case for recursive, variadic combining.
Definition: Hashing.h:575
char buffer[64]
Definition: Hashing.h:504
hash_combine_recursive_helper()
Construct a recursive hash combining helper.
Definition: Hashing.h:513
The intermediate state used during hashing.
Definition: Hashing.h:268
static hash_state create(const char *s, uint64_t seed)
Create a new hash_state structure and initialize it based on the seed and the first 64-byte chunk.
Definition: Hashing.h:274
uint64_t h2
Definition: Hashing.h:269
uint64_t h3
Definition: Hashing.h:269
uint64_t h6
Definition: Hashing.h:269
uint64_t h5
Definition: Hashing.h:269
uint64_t finalize(size_t length)
Compute the final 64-bit hash code value based on the current state and the length of bytes hashed.
Definition: Hashing.h:315
uint64_t h4
Definition: Hashing.h:269
uint64_t h1
Definition: Hashing.h:269
void mix(const char *s)
Mix in a 64-byte buffer of data.
Definition: Hashing.h:298
uint64_t h0
Definition: Hashing.h:269
static void mix_32_bytes(const char *s, uint64_t &a, uint64_t &b)
Mix 32-bytes from the input sequence into the 16-bytes of 'a' and 'b', including whatever is already ...
Definition: Hashing.h:285
Trait to indicate whether a type's bits can be hashed directly.
Definition: Hashing.h:357