Skip to content

Commit

Permalink
GH-36214: [C++] Specify FieldPath::Hash as template parameter where…
Browse files Browse the repository at this point in the history
… possible (#36222)

### Rationale for this change

Internal specializations of `std::hash<FieldPath>` have caused multiple-definition errors with unity builds.

### What changes are included in this PR?

To avoid exposing a global specialization of `std::hash` (which must be declared in the `std` namespace), this specifies the `FieldPath::Hash` helper as a template parameter to hashable containers instead.

### Are these changes tested?

Yes (covered by existing tests)

### Are there any user-facing changes?

No

* Closes: #36214

Authored-by: benibus <bpharks@gmx.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
benibus committed Jun 22, 2023
1 parent ec413b7 commit c875da8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
5 changes: 1 addition & 4 deletions cpp/src/arrow/compute/kernels/vector_sort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include "arrow/compute/kernels/vector_sort_internal.h"
#include "arrow/compute/registry.h"

template <>
struct std::hash<arrow::FieldPath> : public arrow::FieldPath::Hash {};

namespace arrow {

using internal::checked_cast;
Expand Down Expand Up @@ -1095,7 +1092,7 @@ struct SortFieldPopulator {
}

std::vector<SortField> sort_fields_;
std::unordered_set<FieldPath> seen_;
std::unordered_set<FieldPath, FieldPath::Hash> seen_;
std::vector<int> tmp_indices_;
};

Expand Down
9 changes: 1 addition & 8 deletions cpp/src/arrow/ipc/dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@
#include "arrow/util/checked_cast.h"
#include "arrow/util/logging.h"

namespace std {
template <>
struct hash<arrow::FieldPath> {
size_t operator()(const arrow::FieldPath& path) const { return path.hash(); }
};
} // namespace std

namespace arrow {

using internal::checked_cast;
Expand All @@ -54,7 +47,7 @@ using internal::FieldPosition;
// DictionaryFieldMapper implementation

struct DictionaryFieldMapper::Impl {
using FieldPathMap = std::unordered_map<FieldPath, int64_t>;
using FieldPathMap = std::unordered_map<FieldPath, int64_t, FieldPath::Hash>;

FieldPathMap field_path_to_id;

Expand Down

0 comments on commit c875da8

Please sign in to comment.