24 #ifndef PXR_BASE_TF_HASH_H
25 #define PXR_BASE_TF_HASH_H
40 #include <type_traits>
47 template <
class HashState,
class T>
63 template <
class HashState,
class Enum>
67 h.Append(
static_cast<std::underlying_type_t<Enum>
>(e));
71 template <
class HashState,
class T>
78 if (fp != static_cast<T>(0)) {
79 memcpy(&intbuf, &fp,
sizeof(
T));
85 template <
class HashState,
class T,
class U>
94 template <
class HashState,
class T>
98 static_assert(!std::is_same_v<std::remove_cv_t<T>,
bool>,
99 "Unexpected usage of vector of 'bool'."
100 "Expected explicit overload.");
101 h.AppendContiguous(vec.data(), vec.size());
105 template <
class HashState>
109 h.Append(std::hash<std::vector<bool>>{}(vec));
115 template <
class HashState,
class T,
class Compare>
125 template <
class HashState,
class Key,
class Value,
class Compare>
133 template <
class HashState>
137 return h.AppendContiguous(s.c_str(), s.length());
142 template <
class HashState,
class T>
145 return h.Append(reinterpret_cast<uintptr_t>(ptr));
154 template <
class HashState>
156 template <
class HashState>
180 template <
class HashState>
183 return h.AppendContiguous(hcstr.
cstr, std::strlen(hcstr.
cstr));
193 template <
class HashState,
class T>
196 std::forward<T>(obj)),
void())
203 template <
class HashState,
class T>
205 -> decltype(
hash_value(std::forward<T>(obj)),
void())
211 template <
class HashState,
class T>
220 template <
class Derived>
225 template <
class... Args>
227 _AppendImpl(std::forward<Args>(
args)...);
233 this->_AsDerived()._AppendContiguous(elems, numElems);
237 template <
class Iter>
239 this->_AsDerived()._AppendRange(f, l);
244 return this->_AsDerived()._GetCode();
248 template <
class T,
class... Args>
249 void _AppendImpl(
T &&obj, Args &&...
rest) {
250 this->_AsDerived()._Append(std::forward<T>(obj));
251 _AppendImpl(std::forward<Args>(
rest)...);
253 void _AppendImpl()
const {
257 Derived &_AsDerived() {
258 return *
static_cast<Derived *
>(
this);
261 Derived
const &_AsDerived()
const {
262 return *
static_cast<Derived
const *
>(
this);
274 std::enable_if_t<!std::is_integral<std::decay_t<T>>
::value>
288 _state = _Combine(_state, i);
295 _AppendContiguous(
T const *elems,
size_t numElems) {
296 _AppendBytes(reinterpret_cast<char const *>(elems),
297 numElems *
sizeof(
T));
303 _AppendContiguous(
T const *elems,
size_t numElems) {
310 template <
class Iter>
311 void _AppendRange(Iter
f, Iter l) {
318 TF_API void _AppendBytes(
char const *
bytes,
size_t numBytes);
321 size_t _GetCode()
const {
329 return _SwapByteOrder(_state * 11400714819323198549ULL);
334 _SwapByteOrder(uint64_t
val)
const {
336 ((val & 0xFF00000000000000u) >> 56u) |
337 ((val & 0x00FF000000000000u) >> 40u) |
338 ((val & 0x0000FF0000000000u) >> 24u) |
339 ((val & 0x000000FF00000000u) >> 8u) |
340 ((val & 0x00000000FF000000u) << 8u) |
341 ((val & 0x0000000000FF0000u) << 24u) |
342 ((val & 0x000000000000FF00u) << 40u) |
343 ((val & 0x00000000000000FFu) << 56u);
347 size_t _Combine(
size_t x,
size_t y)
const {
379 return y + x * (x + 1) / 2;
383 bool _didOne =
false;
484 std::forward<
T>(obj), 0),
size_t()) {
491 template <
class... Args>
494 _CombineImpl(h, std::forward<Args>(
args)...);
499 template <
class HashState,
class T,
class... Args>
500 static void _CombineImpl(HashState &
h,
T &&obj, Args &&...
rest) {
502 _CombineImpl(h, std::forward<Args>(
rest)...);
505 template <
class HashState>
506 static void _CombineImpl(HashState &h) {
523 bool operator()(
const char* lhs,
const char* rhs)
const;
A hash function object that hashes the address of a char pointer.
TfCStrHashWrapper TfHashAsCStr(char const *cstr)
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
void Append(Args &&...args)
size_t operator()(const char *ptr) const
TfCStrHashWrapper(char const *cstr)
void AppendRange(Iter f, Iter l)
size_t operator()(const char *ptr) const
A hash function object that hashes null-terminated c-string content.
bool operator()(const char *lhs, const char *rhs) const
GLfloat GLfloat GLfloat GLfloat h
A function object that compares two c-strings for equality.
auto Tf_HashImpl(HashState &h, T &&obj, long) -> decltype(std::hash< typename std::decay< T >::type >()(std::forward< T >(obj)), void())
void AppendContiguous(T const *elems, size_t numElems)
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
**If you just want to fire and args
PXR_NAMESPACE_OPEN_SCOPE std::enable_if_t< std::is_integral< T >::value > TfHashAppend(HashState &h, T integral)
size_t hash_value(const CH_ChannelRef &ref)
GA_API const UT_StringHolder rest
auto operator()(T &&obj) const -> decltype(Tf_HashImpl(std::declval< Tf_HashState & >(), std::forward< T >(obj), 0), size_t())
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.