GetHash vs Hash vs hash_value vs TfHashAppend?

GfQuatd has hash_value, SdfTimeCode has GetHash and Hash (and hash_value), and the docs say " The best way to add TfHash support … TfHashAppend".

Is this situation historical? Intentional?

What is the recommended way to add hashing (i.e., for a TfHashMap) for:

  • an external custom type
  • a PR for an internal type that currently doesn’t have one but “needs” one
    ?

Thanks!

Hi Rob. I would recommend going with what the docs say and use TfHashAppend.

OpenUSD used to use boost’s hashing methods, which uses ADL on hash_value. At some point, TfHash was introduced and for backwards compatibility, it supported both hash_value and the specific TfHashAppend. std::hash support was added when Pixar switched to C++17 (Pull Request #2781 · PixarAnimationStudios/OpenUSD).

I shy away from using hash_value since its name is generic and has led to some collisions in the past (Pull Request #2310 · PixarAnimationStudios/OpenUSD).

2 Likes

Thanks for both the history lesson and the recommendation … very much appreciated! :slight_smile: