24 #ifndef PXR_BASE_TF_HASH_H
25 #define PXR_BASE_TF_HASH_H
36 #include <type_traits>
43 template <
class HashState,
class T>
59 template <
class HashState,
class Enum>
63 h.Append(
static_cast<std::underlying_type_t<Enum>
>(e));
67 template <
class HashState,
class T>
74 if (fp != static_cast<T>(0)) {
75 memcpy(&intbuf, &fp,
sizeof(
T));
81 template <
class HashState,
class T,
class U>
90 template <
class HashState,
class T>
94 h.AppendContiguous(vec.data(), vec.size());
98 template <
class HashState>
102 return h.AppendContiguous(s.c_str(), s.length());
107 template <
class HashState,
class T>
110 return h.Append(reinterpret_cast<uintptr_t>(ptr));
119 template <
class HashState>
121 template <
class HashState>
145 template <
class HashState>
148 return h.AppendContiguous(hcstr.
cstr, std::strlen(hcstr.
cstr));
173 template <
class HashState,
class T>
181 template <
class HashState,
class T>
190 template <
class Derived>
195 template <
class... Args>
197 _AppendImpl(
args...);
203 this->_AsDerived()._AppendContiguous(elems, numElems);
207 template <
class Iter>
209 this->_AsDerived()._AppendRange(f, l);
214 return this->_AsDerived()._GetCode();
218 template <
class T,
class... Args>
219 void _AppendImpl(
T &&
obj, Args &&...
rest) {
220 this->_AsDerived()._Append(std::forward<T>(
obj));
221 _AppendImpl(
rest...);
223 void _AppendImpl()
const {
227 Derived &_AsDerived() {
228 return *
static_cast<Derived *
>(
this);
231 Derived
const &_AsDerived()
const {
232 return *
static_cast<Derived
const *
>(
this);
244 std::enable_if_t<!std::is_integral<std::decay_t<T>>
::value>
258 _state = _Combine(_state, i);
265 _AppendContiguous(
T const *elems,
size_t numElems) {
266 _AppendBytes(reinterpret_cast<char const *>(elems),
267 numElems *
sizeof(
T));
273 _AppendContiguous(
T const *elems,
size_t numElems) {
280 template <
class Iter>
281 void _AppendRange(Iter
f, Iter
l) {
288 TF_API void _AppendBytes(
char const *
bytes,
size_t numBytes);
291 size_t _GetCode()
const {
299 return _SwapByteOrder(_state * 11400714819323198549ULL);
304 _SwapByteOrder(uint64_t
val)
const {
306 ((val & 0xFF00000000000000u) >> 56u) |
307 ((val & 0x00FF000000000000u) >> 40u) |
308 ((val & 0x0000FF0000000000u) >> 24u) |
309 ((val & 0x000000FF00000000u) >> 8u) |
310 ((val & 0x00000000FF000000u) << 8u) |
311 ((val & 0x0000000000FF0000u) << 24u) |
312 ((val & 0x000000000000FF00u) << 40u) |
313 ((val & 0x00000000000000FFu) << 56u);
317 size_t _Combine(
size_t x,
size_t y)
const {
349 return y + x * (x + 1) / 2;
353 bool _didOne =
false;
454 std::forward<
T>(
obj), 0),
size_t()) {
461 template <
class... Args>
464 _CombineImpl(h,
args...);
469 template <
class HashState,
class T,
class... Args>
470 static void _CombineImpl(HashState &
h,
T &&
obj, Args &&...
rest) {
472 _CombineImpl(h,
rest...);
475 template <
class HashState>
476 static void _CombineImpl(HashState &h) {
493 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)
void Append(Args &&...args)
size_t operator()(const char *ptr) const
TfCStrHashWrapper(char const *cstr)
GLsizei const GLchar *const * string
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
GLsizei const GLfloat * value
**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())