Skip to content

Commit

Permalink
Replace boost hash usage with TfHash in pxr/base/gf
Browse files Browse the repository at this point in the history
  • Loading branch information
nvmkuruc committed Feb 17, 2023
1 parent a8b70f6 commit 808630e
Show file tree
Hide file tree
Showing 62 changed files with 293 additions and 285 deletions.
8 changes: 4 additions & 4 deletions pxr/base/gf/bbox3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ class GfBBox3d {

/// Hash.
friend inline size_t hash_value(const GfBBox3d &b) {
size_t h = 0;
boost::hash_combine(h, b._box);
boost::hash_combine(h, b._matrix);
return h;
return TfHash::Combine(
b._box,
b._matrix
);
}

/// Component-wise equality test. The axis-aligned boxes and
Expand Down
8 changes: 2 additions & 6 deletions pxr/base/gf/dualQuat.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
{% endif %}

#include "pxr/base/gf/quat{{ SUFFIX }}.h"

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

#include <iosfwd>

Expand Down Expand Up @@ -175,10 +174,7 @@ class {{ DUALQUAT }} final

/// Hash.
friend inline size_t hash_value(const {{ DUALQUAT }} &dq) {
size_t h = 0;
boost::hash_combine(h, dq.GetReal());
boost::hash_combine(h, dq.GetDual());
return h;
return TfHash::Combine(dq.GetReal(), dq.GetDual());
}

/// Component-wise dual quaternion equality test. The real and dual parts
Expand Down
8 changes: 2 additions & 6 deletions pxr/base/gf/dualQuatd.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
#include "pxr/base/gf/traits.h"

#include "pxr/base/gf/quatd.h"

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

#include <iosfwd>

Expand Down Expand Up @@ -173,10 +172,7 @@ class GfDualQuatd final

/// Hash.
friend inline size_t hash_value(const GfDualQuatd &dq) {
size_t h = 0;
boost::hash_combine(h, dq.GetReal());
boost::hash_combine(h, dq.GetDual());
return h;
return TfHash::Combine(dq.GetReal(), dq.GetDual());
}

/// Component-wise dual quaternion equality test. The real and dual parts
Expand Down
8 changes: 2 additions & 6 deletions pxr/base/gf/dualQuatf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
#include "pxr/base/gf/traits.h"

#include "pxr/base/gf/quatf.h"

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

#include <iosfwd>

Expand Down Expand Up @@ -173,10 +172,7 @@ class GfDualQuatf final

/// Hash.
friend inline size_t hash_value(const GfDualQuatf &dq) {
size_t h = 0;
boost::hash_combine(h, dq.GetReal());
boost::hash_combine(h, dq.GetDual());
return h;
return TfHash::Combine(dq.GetReal(), dq.GetDual());
}

/// Component-wise dual quaternion equality test. The real and dual parts
Expand Down
8 changes: 2 additions & 6 deletions pxr/base/gf/dualQuath.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
#include "pxr/base/gf/half.h"

#include "pxr/base/gf/quath.h"

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

#include <iosfwd>

Expand Down Expand Up @@ -174,10 +173,7 @@ class GfDualQuath final

/// Hash.
friend inline size_t hash_value(const GfDualQuath &dq) {
size_t h = 0;
boost::hash_combine(h, dq.GetReal());
boost::hash_combine(h, dq.GetDual());
return h;
return TfHash::Combine(dq.GetReal(), dq.GetDual());
}

/// Component-wise dual quaternion equality test. The real and dual parts
Expand Down
19 changes: 9 additions & 10 deletions pxr/base/gf/frustum.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/api.h"

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

#include <array>
#include <atomic>
Expand Down Expand Up @@ -190,14 +189,14 @@ class GfFrustum {
}

friend inline size_t hash_value(const GfFrustum &f) {
size_t h = 0;
boost::hash_combine(h, f._position);
boost::hash_combine(h, f._rotation);
boost::hash_combine(h, f._window);
boost::hash_combine(h, f._nearFar);
boost::hash_combine(h, f._viewDistance);
boost::hash_combine(h, f._projectionType);
return h;
return TfHash::Combine(
f._position,
f._rotation,
f._window,
f._nearFar,
f._viewDistance,
f._projectionType
);
}

// Equality operator. true iff all parts match.
Expand Down
15 changes: 4 additions & 11 deletions pxr/base/gf/interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

#include "pxr/pxr.h"
#include "pxr/base/gf/math.h"
#include "pxr/base/gf/api.h"

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

#include <float.h>
#include <iosfwd>
Expand Down Expand Up @@ -103,10 +102,7 @@ class GfInterval
size_t Hash() const { return hash_value(*this); }

friend inline size_t hash_value(GfInterval const &i) {
size_t h = 0;
boost::hash_combine(h, i._min);
boost::hash_combine(h, i._max);
return h;
return TfHash::Combine(i._min, i._max);
}

/// Minimum value
Expand Down Expand Up @@ -391,10 +387,7 @@ class GfInterval
return _Bound( value * rhs.value, closed & rhs.closed );
}
friend inline size_t hash_value(const _Bound &b) {
size_t h = 0;
boost::hash_combine(h, b.value);
boost::hash_combine(h, b.closed);
return h;
return TfHash::Combine(b.value, b.closed);
}
};

Expand Down
12 changes: 4 additions & 8 deletions pxr/base/gf/matrix.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
#include "pxr/base/gf/traits.h"
{% block includes %}
{% endblock %}

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

#include <iosfwd>
#include <vector>
Expand Down Expand Up @@ -218,12 +217,9 @@ class {{ MAT }}

/// Hash.
friend inline size_t hash_value({{ MAT }} const &m) {
int nElems = {{ DIM }} * {{ DIM }};
size_t h = 0;
const {{ SCL }} *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
return TfHash::Combine(
{{ MATRIX("m._mtx[%(i)s][%(j)s]", sep=',\n ') }}
);
}

/// Tests for element-wise matrix equality. All elements must match
Expand Down
15 changes: 7 additions & 8 deletions pxr/base/gf/matrix2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
#include "pxr/base/gf/matrixData.h"
#include "pxr/base/gf/vec2d.h"
#include "pxr/base/gf/traits.h"

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

#include <iosfwd>
#include <vector>
Expand Down Expand Up @@ -224,12 +223,12 @@ class GfMatrix2d

/// Hash.
friend inline size_t hash_value(GfMatrix2d const &m) {
int nElems = 2 * 2;
size_t h = 0;
const double *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
return TfHash::Combine(
m._mtx[0][0],
m._mtx[0][1],
m._mtx[1][0],
m._mtx[1][1]
);
}

/// Tests for element-wise matrix equality. All elements must match
Expand Down
15 changes: 7 additions & 8 deletions pxr/base/gf/matrix2f.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
#include "pxr/base/gf/matrixData.h"
#include "pxr/base/gf/vec2f.h"
#include "pxr/base/gf/traits.h"

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

#include <iosfwd>
#include <vector>
Expand Down Expand Up @@ -224,12 +223,12 @@ class GfMatrix2f

/// Hash.
friend inline size_t hash_value(GfMatrix2f const &m) {
int nElems = 2 * 2;
size_t h = 0;
const float *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
return TfHash::Combine(
m._mtx[0][0],
m._mtx[0][1],
m._mtx[1][0],
m._mtx[1][1]
);
}

/// Tests for element-wise matrix equality. All elements must match
Expand Down
20 changes: 12 additions & 8 deletions pxr/base/gf/matrix3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
#include "pxr/base/gf/matrixData.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/traits.h"

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

#include <iosfwd>
#include <vector>
Expand Down Expand Up @@ -263,12 +262,17 @@ class GfMatrix3d

/// Hash.
friend inline size_t hash_value(GfMatrix3d const &m) {
int nElems = 3 * 3;
size_t h = 0;
const double *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
return TfHash::Combine(
m._mtx[0][0],
m._mtx[0][1],
m._mtx[0][2],
m._mtx[1][0],
m._mtx[1][1],
m._mtx[1][2],
m._mtx[2][0],
m._mtx[2][1],
m._mtx[2][2]
);
}

/// Tests for element-wise matrix equality. All elements must match
Expand Down
20 changes: 12 additions & 8 deletions pxr/base/gf/matrix3f.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
#include "pxr/base/gf/matrixData.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/traits.h"

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

#include <iosfwd>
#include <vector>
Expand Down Expand Up @@ -263,12 +262,17 @@ class GfMatrix3f

/// Hash.
friend inline size_t hash_value(GfMatrix3f const &m) {
int nElems = 3 * 3;
size_t h = 0;
const float *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
return TfHash::Combine(
m._mtx[0][0],
m._mtx[0][1],
m._mtx[0][2],
m._mtx[1][0],
m._mtx[1][1],
m._mtx[1][2],
m._mtx[2][0],
m._mtx[2][1],
m._mtx[2][2]
);
}

/// Tests for element-wise matrix equality. All elements must match
Expand Down
27 changes: 19 additions & 8 deletions pxr/base/gf/matrix4d.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
#include "pxr/base/gf/limits.h"
#include "pxr/base/gf/math.h"
#include "pxr/base/gf/vec3d.h"

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

#include <iosfwd>
#include <vector>
Expand Down Expand Up @@ -303,12 +302,24 @@ class GfMatrix4d

/// Hash.
friend inline size_t hash_value(GfMatrix4d const &m) {
int nElems = 4 * 4;
size_t h = 0;
const double *p = m.GetArray();
while (nElems--)
boost::hash_combine(h, *p++);
return h;
return TfHash::Combine(
m._mtx[0][0],
m._mtx[0][1],
m._mtx[0][2],
m._mtx[0][3],
m._mtx[1][0],
m._mtx[1][1],
m._mtx[1][2],
m._mtx[1][3],
m._mtx[2][0],
m._mtx[2][1],
m._mtx[2][2],
m._mtx[2][3],
m._mtx[3][0],
m._mtx[3][1],
m._mtx[3][2],
m._mtx[3][3]
);
}

/// Tests for element-wise matrix equality. All elements must match
Expand Down
Loading

0 comments on commit 808630e

Please sign in to comment.