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>
95 inline std::enable_if_t<!std::is_same<std::remove_const_t<T>,
bool>
::value>
98 h.AppendContiguous(vec.data(), vec.size());
102 template <
class HashState>
106 h.Append(std::hash<std::vector<bool>>{}(vec));
112 template <
class HashState,
class T,
class Compare>
122 template <
class HashState,
class Key,
class Value,
class Compare>
131 template <
class HashState>
135 return h.Append(type_index.hash_code());
139 template <
class HashState>
143 return h.AppendContiguous(s.c_str(), s.length());
148 template <
class HashState,
class T>
151 return h.Append(reinterpret_cast<uintptr_t>(ptr));
156 template <
class HashState,
class T>
159 h.Append(std::hash<std::shared_ptr<T>>{}(
ptr));
164 template <
class HashState,
class T>
167 h.Append(std::hash<std::unique_ptr<T>>{}(
ptr));
176 template <
class HashState>
178 template <
class HashState>
202 template <
class HashState>
205 return h.AppendContiguous(hcstr.
cstr, std::strlen(hcstr.
cstr));
230 template <
class HashState,
class T>
232 -> decltype(
hash_value(std::forward<T>(obj)),
void())
238 template <
class HashState,
class T>
247 template <
class Derived>
252 template <
class... Args>
254 _AppendImpl(std::forward<Args>(
args)...);
260 this->_AsDerived()._AppendContiguous(elems, numElems);
264 template <
class Iter>
266 this->_AsDerived()._AppendRange(f, l);
271 return this->_AsDerived()._GetCode();
275 template <
class T,
class... Args>
276 void _AppendImpl(
T &&obj, Args &&...
rest) {
277 this->_AsDerived()._Append(std::forward<T>(obj));
278 _AppendImpl(std::forward<Args>(
rest)...);
280 void _AppendImpl()
const {
284 Derived &_AsDerived() {
285 return *
static_cast<Derived *
>(
this);
288 Derived
const &_AsDerived()
const {
289 return *
static_cast<Derived
const *
>(
this);
301 std::enable_if_t<!std::is_integral<std::decay_t<T>>
::value>
315 _state = _Combine(_state, i);
322 _AppendContiguous(
T const *elems,
size_t numElems) {
323 _AppendBytes(reinterpret_cast<char const *>(elems),
324 numElems *
sizeof(
T));
330 _AppendContiguous(
T const *elems,
size_t numElems) {
337 template <
class Iter>
338 void _AppendRange(Iter
f, Iter l) {
345 TF_API void _AppendBytes(
char const *
bytes,
size_t numBytes);
348 size_t _GetCode()
const {
356 return _SwapByteOrder(_state * 11400714819323198549ULL);
361 _SwapByteOrder(uint64_t
val)
const {
363 ((val & 0xFF00000000000000u) >> 56u) |
364 ((val & 0x00FF000000000000u) >> 40u) |
365 ((val & 0x0000FF0000000000u) >> 24u) |
366 ((val & 0x000000FF00000000u) >> 8u) |
367 ((val & 0x00000000FF000000u) << 8u) |
368 ((val & 0x0000000000FF0000u) << 24u) |
369 ((val & 0x000000000000FF00u) << 40u) |
370 ((val & 0x00000000000000FFu) << 56u);
374 size_t _Combine(
size_t x,
size_t y)
const {
406 return y + x * (x + 1) / 2;
410 bool _didOne =
false;
511 std::forward<
T>(obj), 0),
size_t()) {
518 template <
class... Args>
521 _CombineImpl(h, std::forward<Args>(
args)...);
526 template <
class HashState,
class T,
class... Args>
527 static void _CombineImpl(HashState &
h,
T &&obj, Args &&...
rest) {
529 _CombineImpl(h, std::forward<Args>(
rest)...);
532 template <
class HashState>
533 static void _CombineImpl(HashState &h) {
550 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
auto Tf_HashImpl(HashState &h, T &&obj, long) -> decltype(hash_value(std::forward< T >(obj)), void())
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.
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.