7 #ifndef PXR_BASE_TF_HASH_H
8 #define PXR_BASE_TF_HASH_H
24 #include <type_traits>
31 template <
class HashState,
class T>
47 template <
class HashState,
class Enum>
51 h.Append(
static_cast<std::underlying_type_t<Enum>
>(e));
55 template <
class HashState,
class T>
62 if (fp != static_cast<T>(0)) {
63 memcpy(&intbuf, &fp,
sizeof(
T));
69 template <
class HashState,
class T,
class U>
78 template <
class HashState,
class...
T>
85 std::apply([&h](
auto const&...
v) { h.Append(
v...); },
t);
89 template <
class HashState,
class T>
93 static_assert(!std::is_same_v<std::remove_cv_t<T>,
bool>,
94 "Unexpected usage of vector of 'bool'."
95 "Expected explicit overload.");
96 h.AppendContiguous(vec.data(), vec.size());
100 template <
class HashState>
104 h.Append(std::hash<std::vector<bool>>{}(vec));
110 template <
class HashState,
class T,
class Compare>
120 template <
class HashState,
class Key,
class Value,
class Compare>
128 template <
class HashState>
132 return h.AppendContiguous(s.c_str(), s.length());
137 template <
class HashState,
class T>
140 return h.Append(reinterpret_cast<uintptr_t>(ptr));
149 template <
class HashState>
151 template <
class HashState>
175 template <
class HashState>
178 return h.AppendContiguous(hcstr.
cstr, std::strlen(hcstr.
cstr));
188 template <
class HashState,
class T>
191 std::forward<T>(obj)),
void())
198 template <
class HashState,
class T>
200 -> decltype(
hash_value(std::forward<T>(obj)),
void())
206 template <
class HashState,
class T>
215 template <
class Derived>
220 template <
class... Args>
222 _AppendImpl(std::forward<Args>(
args)...);
228 this->_AsDerived()._AppendContiguous(elems, numElems);
232 template <
class Iter>
234 this->_AsDerived()._AppendRange(f, l);
239 return this->_AsDerived()._GetCode();
243 template <
class T,
class... Args>
244 void _AppendImpl(
T &&obj, Args &&...
rest) {
245 this->_AsDerived()._Append(std::forward<T>(obj));
246 _AppendImpl(std::forward<Args>(
rest)...);
248 void _AppendImpl()
const {
252 Derived &_AsDerived() {
253 return *
static_cast<Derived *
>(
this);
256 Derived
const &_AsDerived()
const {
257 return *
static_cast<Derived
const *
>(
this);
269 std::enable_if_t<!std::is_integral<std::decay_t<T>>
::value>
283 _state = _Combine(_state, i);
290 _AppendContiguous(
T const *elems,
size_t numElems) {
291 _AppendBytes(reinterpret_cast<char const *>(elems),
292 numElems *
sizeof(
T));
298 _AppendContiguous(
T const *elems,
size_t numElems) {
305 template <
class Iter>
306 void _AppendRange(Iter
f, Iter l) {
313 TF_API void _AppendBytes(
char const *
bytes,
size_t numBytes);
316 size_t _GetCode()
const {
324 return _SwapByteOrder(_state * 11400714819323198549ULL);
329 _SwapByteOrder(uint64_t
val)
const {
331 ((val & 0xFF00000000000000u) >> 56u) |
332 ((val & 0x00FF000000000000u) >> 40u) |
333 ((val & 0x0000FF0000000000u) >> 24u) |
334 ((val & 0x000000FF00000000u) >> 8u) |
335 ((val & 0x00000000FF000000u) << 8u) |
336 ((val & 0x0000000000FF0000u) << 24u) |
337 ((val & 0x000000000000FF00u) << 40u) |
338 ((val & 0x00000000000000FFu) << 56u);
342 size_t _Combine(
size_t x,
size_t y)
const {
374 return y + x * (x + 1) / 2;
378 bool _didOne =
false;
479 std::forward<
T>(obj), 0),
size_t()) {
486 template <
class... Args>
489 _CombineImpl(h, std::forward<Args>(
args)...);
494 template <
class HashState,
class T,
class... Args>
495 static void _CombineImpl(HashState &
h,
T &&obj, Args &&...
rest) {
497 _CombineImpl(h, std::forward<Args>(
rest)...);
500 template <
class HashState>
501 static void _CombineImpl(HashState &h) {
518 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 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.