Skip to content

Commit

Permalink
Replace boost hash usage with TfHash in pxr/usd/usd
Browse files Browse the repository at this point in the history
  • Loading branch information
nvmkuruc committed Mar 17, 2023
1 parent 84bd5a9 commit 0154fbd
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 103 deletions.
14 changes: 7 additions & 7 deletions pxr/usd/usd/clipCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/trace/trace.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/tf/hash.h"
#include "pxr/base/tf/mallocTag.h"
#include "pxr/base/tf/ostreamMethods.h"

Expand Down Expand Up @@ -84,13 +85,12 @@ class Usd_ClipCache::Lifeboat::Data
{
inline size_t operator()(const ManifestKey& key) const
{
size_t hash = key.primPath.GetHash();
boost::hash_combine(hash, TfHash()(key.clipSetName));
boost::hash_combine(hash, key.clipPrimPath.GetHash());
for (const auto& p : key.clipAssetPaths) {
boost::hash_combine(hash, p.GetHash());
}
return hash;
return TfHash::Combine(
key.primPath,
key.clipSetName,
key.clipPrimPath,
key.clipAssetPaths
);
}
};
};
Expand Down
36 changes: 18 additions & 18 deletions pxr/usd/usd/clipSetDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "pxr/base/vt/array.h"
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/tf/declarePtrs.h"
#include "pxr/base/tf/hash.h"

#include <boost/optional.hpp>

Expand Down Expand Up @@ -76,40 +77,39 @@ class Usd_ClipSetDefinition

size_t GetHash() const
{
size_t hash = indexOfLayerWhereAssetPathsFound;
boost::hash_combine(hash, sourceLayerStack);
boost::hash_combine(hash, sourcePrimPath);
size_t hash = TfHash::Combine(
indexOfLayerWhereAssetPathsFound,
sourceLayerStack,
sourcePrimPath
);

if (clipAssetPaths) {
for (const auto& assetPath : *clipAssetPaths) {
boost::hash_combine(hash, assetPath.GetHash());
}
hash = TfHash::Combine(hash, *clipAssetPaths);
}
if (clipManifestAssetPath) {
boost::hash_combine(hash, clipManifestAssetPath->GetHash());
hash = TfHash::Combine(hash, *clipManifestAssetPath);
}
if (clipPrimPath) {
boost::hash_combine(hash, *clipPrimPath);
hash = TfHash::Combine(hash, *clipPrimPath);
}
if (clipActive) {
for (const auto& active : *clipActive) {
boost::hash_combine(hash, active[0]);
boost::hash_combine(hash, active[1]);
}
hash = TfHash::Combine(hash, *clipActive);
}
if (clipTimes) {
for (const auto& time : *clipTimes) {
boost::hash_combine(hash, time[0]);
boost::hash_combine(hash, time[1]);
}
hash = TfHash::Combine(hash, *clipTimes);
}
if (interpolateMissingClipValues) {
boost::hash_combine(hash, *interpolateMissingClipValues);
hash = TfHash::Combine(hash, *interpolateMissingClipValues);
}

return hash;
}

template <typename HashState>
friend void TfHashAppend(HashState& h,
const Usd_ClipSetDefinition& definition) {
h.Append(definition.GetHash());
}

boost::optional<VtArray<SdfAssetPath> > clipAssetPaths;
boost::optional<SdfAssetPath> clipManifestAssetPath;
boost::optional<std::string> clipPrimPath;
Expand Down
2 changes: 0 additions & 2 deletions pxr/usd/usd/collectionAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,6 @@ PXR_NAMESPACE_CLOSE_SCOPE

#include "pxr/usd/usd/primRange.h"

#include <boost/functional/hash.hpp>

#include <set>

PXR_NAMESPACE_OPEN_SCOPE
Expand Down
8 changes: 2 additions & 6 deletions pxr/usd/usd/collectionMembershipQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,10 @@ UsdCollectionMembershipQuery::Hash::operator()(
std::vector<_Entry> entries(q._pathExpansionRuleMap.begin(),
q._pathExpansionRuleMap.end());
std::sort(entries.begin(), entries.end());
size_t h = 0;
for (_Entry const& entry: entries) {
boost::hash_combine(h, entry.first);
boost::hash_combine(h, entry.second);
}

// Don't hash _hasExcludes because it is derived from
// the contents of _pathExpansionRuleMap.
return h;
return TfHash()(entries);
}

PXR_NAMESPACE_CLOSE_SCOPE
48 changes: 26 additions & 22 deletions pxr/usd/usd/crateFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "crateValueInliners.h"

#include "pxr/base/arch/fileSystem.h"
#include "pxr/base/tf/hash.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/vt/array.h"
#include "pxr/base/vt/value.h"
Expand All @@ -43,7 +44,6 @@
#include "pxr/usd/sdf/types.h"

#include <boost/container/flat_map.hpp>
#include <boost/functional/hash.hpp>
#include <boost/intrusive_ptr.hpp>

#include <tbb/concurrent_unordered_set.h>
Expand Down Expand Up @@ -198,12 +198,12 @@ struct TimeSamples {
}

friend size_t hash_value(TimeSamples const &ts) {
size_t h = 0;
boost::hash_combine(h, ts.valueRep);
boost::hash_combine(h, ts.times);
boost::hash_combine(h, ts.values);
boost::hash_combine(h, ts.valuesFileOffset);
return h;
return TfHash::Combine(
ts.valueRep,
ts.times,
ts.values,
ts.valuesFileOffset
);
}

friend std::ostream &
Expand Down Expand Up @@ -271,7 +271,7 @@ struct _SectionName {
struct _Hasher {
template <class T>
inline size_t operator()(const T &val) const {
return boost::hash<T>()(val);
return TfHash()(val);
}
};

Expand Down Expand Up @@ -350,9 +350,10 @@ class CrateFile
return !(*this == other);
}
friend size_t tbb_hasher(ZeroCopySource const &z) {
size_t seed = reinterpret_cast<uintptr_t>(z._addr);
boost::hash_combine(seed, z._numBytes);
return seed;
return TfHash::Combine(
reinterpret_cast<uintptr_t>(z._addr),
z._numBytes
);
}

// Return true if the refcount is nonzero.
Expand Down Expand Up @@ -590,9 +591,10 @@ class CrateFile
}
friend size_t hash_value(const Field &f) {
_Hasher h;
size_t result = h(f.tokenIndex);
boost::hash_combine(result, f.valueRep);
return result;
return TfHash::Combine(
h(f.tokenIndex),
f.valueRep
);
}
TokenIndex tokenIndex;
ValueRep valueRep;
Expand All @@ -615,10 +617,11 @@ class CrateFile
}
friend size_t hash_value(Spec const &s) {
_Hasher h;
size_t result = h(s.pathIndex);
boost::hash_combine(result, s.fieldSetIndex);
boost::hash_combine(result, s.specType);
return result;
return TfHash::Combine(
h(s.pathIndex),
s.fieldSetIndex,
s.specType
);
}
PathIndex pathIndex;
FieldSetIndex fieldSetIndex;
Expand Down Expand Up @@ -652,10 +655,11 @@ class CrateFile
}
friend size_t hash_value(Spec_0_0_1 const &s) {
_Hasher h;
size_t result = h(s.pathIndex);
boost::hash_combine(result, s.fieldSetIndex);
boost::hash_combine(result, s.specType);
return result;
return TfHash::Combine(
h(s.pathIndex),
s.fieldSetIndex,
s.specType
);
}
PathIndex pathIndex;
FieldSetIndex fieldSetIndex;
Expand Down
4 changes: 2 additions & 2 deletions pxr/usd/usd/instanceCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class Usd_InstanceCache
// Mapping from instance key <-> prototype prim path.
// This stores the path of the prototype prim that should be used
// for all instanceable prim indexes with the given instance key.
typedef TfHashMap<Usd_InstanceKey, SdfPath, boost::hash<Usd_InstanceKey> >
typedef TfHashMap<Usd_InstanceKey, SdfPath, TfHash>
_InstanceKeyToPrototypeMap;
typedef TfHashMap<SdfPath, Usd_InstanceKey, SdfPath::Hash>
_PrototypeToInstanceKeyMap;
Expand All @@ -288,7 +288,7 @@ class Usd_InstanceCache
// These maps contain lists of pending changes and are the only containers
// that should be modified during registration and unregistration.
typedef TfHashMap<
Usd_InstanceKey, _PrimIndexPaths, boost::hash<Usd_InstanceKey> >
Usd_InstanceKey, _PrimIndexPaths, TfHash>
_InstanceKeyToPrimIndexesMap;
_InstanceKeyToPrimIndexesMap _pendingAddedPrimIndexes;
_InstanceKeyToPrimIndexesMap _pendingRemovedPrimIndexes;
Expand Down
16 changes: 7 additions & 9 deletions pxr/usd/usd/instanceKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
#include "pxr/usd/usd/instanceKey.h"
#include "pxr/usd/usd/resolver.h"
#include "pxr/usd/pcp/primIndex.h"

#include <boost/functional/hash.hpp>
#include "pxr/base/tf/hash.h"

#include <iostream>

Expand Down Expand Up @@ -140,13 +139,12 @@ Usd_InstanceKey::operator==(const Usd_InstanceKey& rhs) const
size_t
Usd_InstanceKey::_ComputeHash() const
{
size_t hash = hash_value(_pcpInstanceKey);
for (const Usd_ClipSetDefinition& clipDefs: _clipDefs) {
boost::hash_combine(hash, clipDefs.GetHash());
}
boost::hash_combine(hash, _mask);
boost::hash_combine(hash, _loadRules);
return hash;
return TfHash::Combine(
_pcpInstanceKey,
_clipDefs,
_mask,
_loadRules
);
}

std::ostream &
Expand Down
12 changes: 7 additions & 5 deletions pxr/usd/usd/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,13 @@ size_t
hash_value(const UsdObject &obj)
{
size_t seed = 510-922-3000;
boost::hash_combine(seed, long(obj._type));
boost::hash_combine(seed, obj._prim);
boost::hash_combine(seed, obj._proxyPrimPath);
boost::hash_combine(seed, obj._propName.Hash());
return seed;
return TfHash::Combine(
seed,
long(obj._type),
obj._prim,
obj._proxyPrimPath,
obj._propName.Hash()
);
}

std::string
Expand Down
5 changes: 2 additions & 3 deletions pxr/usd/usd/prim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@

#include "pxr/base/tf/ostreamMethods.h"
#include "pxr/base/tf/pxrTslRobinMap/robin_set.h"

#include <boost/functional/hash.hpp>
#include "pxr/base/tf/hash.h"

#include <tbb/concurrent_queue.h>
#include <tbb/concurrent_unordered_set.h>
Expand Down Expand Up @@ -1670,7 +1669,7 @@ struct UsdPrim_TargetFinder
WorkSingularTask _consumerTask;
Predicate const &_predicate;
tbb::concurrent_queue<SdfPath> _workQueue;
tbb::concurrent_unordered_set<UsdPrim, boost::hash<UsdPrim> > _seenPrims;
tbb::concurrent_unordered_set<UsdPrim, TfHash> _seenPrims;
SdfPathVector _result;
bool _recurse;
};
Expand Down
5 changes: 3 additions & 2 deletions pxr/usd/usd/primDataHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

#include "pxr/pxr.h"
#include "pxr/usd/usd/api.h"
#include <boost/functional/hash.hpp>
#include "pxr/base/tf/hash.h"

#include <boost/intrusive_ptr.hpp>

PXR_NAMESPACE_OPEN_SCOPE
Expand Down Expand Up @@ -126,7 +127,7 @@ class Usd_PrimDataHandle

// Provide hash_value.
friend size_t hash_value(const Usd_PrimDataHandle &h) {
return boost::hash_value(h._p.get());
return TfHash()(h._p.get());
}

friend element_type *get_pointer(const Usd_PrimDataHandle &h) {
Expand Down
10 changes: 4 additions & 6 deletions pxr/usd/usd/primFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
#include "pxr/usd/usd/api.h"
#include "pxr/base/arch/hints.h"
#include "pxr/base/tf/bitUtils.h"

#include <boost/functional/hash.hpp>
#include "pxr/base/tf/hash.h"

#include <bitset>

Expand Down Expand Up @@ -275,10 +274,9 @@ class Usd_PrimFlagsPredicate

// hash overload.
friend size_t hash_value(const Usd_PrimFlagsPredicate &p) {
size_t hash = p._mask.to_ulong();
boost::hash_combine(hash, p._values.to_ulong());
boost::hash_combine(hash, p._negate);
return hash;
return TfHash::Combine(
p._mask.to_ulong(), p._values.to_ulong(), p._negate
);
}

// Whether or not to negate the predicate's result.
Expand Down
5 changes: 2 additions & 3 deletions pxr/usd/usd/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

#include "pxr/pxr.h"
#include "pxr/usd/usd/api.h"
#include "pxr/base/tf/hash.h"

#include <boost/functional/hash.hpp>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <atomic>

Expand Down Expand Up @@ -105,8 +105,7 @@ struct Usd_Shared

// hash_value.
friend inline size_t hash_value(Usd_Shared const &sh) {
using boost::hash_value;
return hash_value(sh._held->data);
return TfHash()(sh._held->data);
}
private:
boost::intrusive_ptr<Usd_Counted<T>> _held;
Expand Down
2 changes: 1 addition & 1 deletion pxr/usd/usd/stageCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
#include "pxr/usd/usd/stageCache.h"

#include "pxr/usd/sdf/layer.h"
#include "pxr/base/tf/hash.h"
#include "pxr/usd/usd/debugCodes.h"
#include "pxr/usd/usd/stage.h"

#include "pxr/usd/ar/resolverContext.h"

#include <boost/functional/hash.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/identity.hpp>
Expand Down
Loading

0 comments on commit 0154fbd

Please sign in to comment.