-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[ADT] Add hash_combine_range that takes a range (NFC) #136459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_hash_combine_range
Apr 20, 2025
Merged
[ADT] Add hash_combine_range that takes a range (NFC) #136459
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_hash_combine_range
Apr 20, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The new function will allow us to replace: hash_combine_range(Ops.begin(), Ops.end()) with: hash_combine_range(Ops)
@llvm/pr-subscribers-llvm-adt Author: Kazu Hirata (kazutakahirata) ChangesThe new function will allow us to replace: hash_combine_range(Ops.begin(), Ops.end()) with: hash_combine_range(Ops) Full diff: https://github.com/llvm/llvm-project/pull/136459.diff 2 Files Affected:
diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h
index 17dcf31c616aa..9b8643b7765cf 100644
--- a/llvm/include/llvm/ADT/Hashing.h
+++ b/llvm/include/llvm/ADT/Hashing.h
@@ -44,6 +44,7 @@
#ifndef LLVM_ADT_HASHING_H
#define LLVM_ADT_HASHING_H
+#include "llvm/ADT/ADL.h"
#include "llvm/Config/abi-breaking.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/ErrorHandling.h"
@@ -469,6 +470,10 @@ hash_code hash_combine_range(InputIteratorT first, InputIteratorT last) {
return ::llvm::hashing::detail::hash_combine_range_impl(first, last);
}
+// A wrapper for hash_combine_range above.
+template <typename RangeT> hash_code hash_combine_range(RangeT &&R) {
+ return hash_combine_range(adl_begin(R), adl_end(R));
+}
// Implementation details for hash_combine.
namespace hashing {
diff --git a/llvm/unittests/ADT/HashingTest.cpp b/llvm/unittests/ADT/HashingTest.cpp
index c28356e229e66..e116ee934a0a4 100644
--- a/llvm/unittests/ADT/HashingTest.cpp
+++ b/llvm/unittests/ADT/HashingTest.cpp
@@ -166,15 +166,19 @@ TEST(HashingTest, HashCombineRangeBasicTest) {
hash_code arr1_hash = hash_combine_range(begin(arr1), end(arr1));
EXPECT_NE(dummy_hash, arr1_hash);
EXPECT_EQ(arr1_hash, hash_combine_range(begin(arr1), end(arr1)));
+ EXPECT_EQ(arr1_hash, hash_combine_range(arr1));
const std::vector<int> vec(begin(arr1), end(arr1));
EXPECT_EQ(arr1_hash, hash_combine_range(vec.begin(), vec.end()));
+ EXPECT_EQ(arr1_hash, hash_combine_range(vec));
const std::list<int> list(begin(arr1), end(arr1));
EXPECT_EQ(arr1_hash, hash_combine_range(list.begin(), list.end()));
+ EXPECT_EQ(arr1_hash, hash_combine_range(list));
const std::deque<int> deque(begin(arr1), end(arr1));
EXPECT_EQ(arr1_hash, hash_combine_range(deque.begin(), deque.end()));
+ EXPECT_EQ(arr1_hash, hash_combine_range(deque));
const int arr2[] = { 3, 2, 1 };
hash_code arr2_hash = hash_combine_range(begin(arr2), end(arr2));
|
tgymnich
approved these changes
Apr 20, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
The new function will allow us to replace: hash_combine_range(Ops.begin(), Ops.end()) with: hash_combine_range(Ops)
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
The new function will allow us to replace: hash_combine_range(Ops.begin(), Ops.end()) with: hash_combine_range(Ops)
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
The new function will allow us to replace: hash_combine_range(Ops.begin(), Ops.end()) with: hash_combine_range(Ops)
kazutakahirata
added a commit
to kazutakahirata/llvm-project
that referenced
this pull request
May 13, 2025
With llvm#136459, we can now invoke hash_combine_range with a range.
kazutakahirata
added a commit
that referenced
this pull request
May 13, 2025
With #136459, we can now invoke hash_combine_range with a range.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The new function will allow us to replace:
hash_combine_range(Ops.begin(), Ops.end())
with:
hash_combine_range(Ops)