Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Conversation

kazutakahirata
Copy link
Contributor

The new function will allow us to replace:

hash_combine_range(Ops.begin(), Ops.end())

with:

hash_combine_range(Ops)

The new function will allow us to replace:

  hash_combine_range(Ops.begin(), Ops.end())

with:

  hash_combine_range(Ops)
@llvmbot
Copy link
Member

llvmbot commented Apr 19, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

The 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:

  • (modified) llvm/include/llvm/ADT/Hashing.h (+5)
  • (modified) llvm/unittests/ADT/HashingTest.cpp (+4)
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));

@kazutakahirata kazutakahirata merged commit f0cc50c into llvm:main Apr 20, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_hash_combine_range branch April 20, 2025 18:20
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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.