Skip to content

Commit a20460c

Browse files
Expose hash_function member function (#587)
Close #582 This PR exposes `hash_function` member function for cuco hash tables. --------- Co-authored-by: Daniel Jünger <[email protected]>
1 parent 6510352 commit a20460c

20 files changed

+259
-3
lines changed

include/cuco/detail/open_addressing/open_addressing_impl.cuh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class open_addressing_impl {
100100

101101
using storage_ref_type = typename storage_type::ref_type; ///< Non-owning window storage ref type
102102
using probing_scheme_type = ProbingScheme; ///< Probe scheme type
103+
using hasher = typename probing_scheme_type::hasher; ///< Hash function type
103104

104105
/**
105106
* @brief Constructs a statically-sized open addressing data structure with the specified initial
@@ -933,6 +934,16 @@ class open_addressing_impl {
933934
return probing_scheme_;
934935
}
935936

937+
/**
938+
* @brief Gets the function(s) used to hash keys
939+
*
940+
* @return The function(s) used to hash keys
941+
*/
942+
[[nodiscard]] constexpr hasher hash_function() const noexcept
943+
{
944+
return this->probing_scheme().hash_function();
945+
}
946+
936947
/**
937948
* @brief Gets the container allocator.
938949
*

include/cuco/detail/open_addressing/open_addressing_ref_impl.cuh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class open_addressing_ref_impl {
109109
public:
110110
using key_type = Key; ///< Key type
111111
using probing_scheme_type = ProbingScheme; ///< Type of probing scheme
112+
using hasher = typename probing_scheme_type::hasher; ///< Hash function type
112113
using storage_ref_type = StorageRef; ///< Type of storage ref
113114
using window_type = typename storage_ref_type::window_type; ///< Window type
114115
using value_type = typename storage_ref_type::value_type; ///< Storage element type
@@ -233,11 +234,22 @@ class open_addressing_ref_impl {
233234
*
234235
* @return The probing scheme used for the container
235236
*/
236-
[[nodiscard]] __device__ constexpr probing_scheme_type const& probing_scheme() const noexcept
237+
[[nodiscard]] __host__ __device__ constexpr probing_scheme_type const& probing_scheme()
238+
const noexcept
237239
{
238240
return probing_scheme_;
239241
}
240242

243+
/**
244+
* @brief Gets the function(s) used to hash keys
245+
*
246+
* @return The function(s) used to hash keys
247+
*/
248+
[[nodiscard]] __host__ __device__ constexpr hasher hash_function() const noexcept
249+
{
250+
return this->probing_scheme().hash_function();
251+
}
252+
241253
/**
242254
* @brief Gets the non-owning storage ref.
243255
*

include/cuco/detail/probing_scheme/probing_scheme_impl.inl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ __host__ __device__ constexpr auto linear_probing<CGSize, Hash>::operator()(
127127
upper_bound};
128128
}
129129

130+
template <int32_t CGSize, typename Hash>
131+
__host__ __device__ constexpr linear_probing<CGSize, Hash>::hasher
132+
linear_probing<CGSize, Hash>::hash_function() const noexcept
133+
{
134+
return hash_;
135+
}
136+
130137
template <int32_t CGSize, typename Hash1, typename Hash2>
131138
__host__ __device__ constexpr double_hashing<CGSize, Hash1, Hash2>::double_hashing(
132139
Hash1 const& hash1, Hash2 const& hash2)
@@ -192,4 +199,12 @@ __host__ __device__ constexpr auto double_hashing<CGSize, Hash1, Hash2>::operato
192199
cg_size),
193200
upper_bound}; // TODO use fast_int operator
194201
}
202+
203+
template <int32_t CGSize, typename Hash1, typename Hash2>
204+
__host__ __device__ constexpr double_hashing<CGSize, Hash1, Hash2>::hasher
205+
double_hashing<CGSize, Hash1, Hash2>::hash_function() const noexcept
206+
{
207+
return {hash1_, hash2_};
208+
}
209+
195210
} // namespace cuco

include/cuco/detail/static_map/static_map.inl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,21 @@ static_map<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::
724724
return impl_->key_eq();
725725
}
726726

727+
template <class Key,
728+
class T,
729+
class Extent,
730+
cuda::thread_scope Scope,
731+
class KeyEqual,
732+
class ProbingScheme,
733+
class Allocator,
734+
class Storage>
735+
constexpr static_map<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::hasher
736+
static_map<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::hash_function()
737+
const noexcept
738+
{
739+
return impl_->hash_function();
740+
}
741+
727742
template <class Key,
728743
class T,
729744
class Extent,

include/cuco/detail/static_map/static_map_ref.inl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ static_map_ref<Key, T, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>
125125
return this->impl_.key_eq();
126126
}
127127

128+
template <typename Key,
129+
typename T,
130+
cuda::thread_scope Scope,
131+
typename KeyEqual,
132+
typename ProbingScheme,
133+
typename StorageRef,
134+
typename... Operators>
135+
__host__ __device__ constexpr static_map_ref<Key,
136+
T,
137+
Scope,
138+
KeyEqual,
139+
ProbingScheme,
140+
StorageRef,
141+
Operators...>::hasher
142+
static_map_ref<Key, T, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>::hash_function()
143+
const noexcept
144+
{
145+
return impl_.hash_function();
146+
}
147+
128148
template <typename Key,
129149
typename T,
130150
cuda::thread_scope Scope,

include/cuco/detail/static_multimap/static_multimap.inl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,22 @@ constexpr static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Alloca
379379
return impl_->key_eq();
380380
}
381381

382+
template <class Key,
383+
class T,
384+
class Extent,
385+
cuda::thread_scope Scope,
386+
class KeyEqual,
387+
class ProbingScheme,
388+
class Allocator,
389+
class Storage>
390+
constexpr static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::
391+
hasher
392+
static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::
393+
hash_function() const noexcept
394+
{
395+
return impl_->hash_function();
396+
}
397+
382398
template <class Key,
383399
class T,
384400
class Extent,

include/cuco/detail/static_multimap/static_multimap_ref.inl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ static_multimap_ref<Key, T, Scope, KeyEqual, ProbingScheme, StorageRef, Operator
122122
return impl_.key_eq();
123123
}
124124

125+
template <typename Key,
126+
typename T,
127+
cuda::thread_scope Scope,
128+
typename KeyEqual,
129+
typename ProbingScheme,
130+
typename StorageRef,
131+
typename... Operators>
132+
__host__ __device__ constexpr static_multimap_ref<Key,
133+
T,
134+
Scope,
135+
KeyEqual,
136+
ProbingScheme,
137+
StorageRef,
138+
Operators...>::hasher
139+
static_multimap_ref<Key, T, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>::
140+
hash_function() const noexcept
141+
{
142+
return impl_.hash_function();
143+
}
144+
125145
template <typename Key,
126146
typename T,
127147
cuda::thread_scope Scope,

include/cuco/detail/static_multiset/static_multiset.inl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,20 @@ constexpr static_multiset<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator
408408
return impl_->key_eq();
409409
}
410410

411+
template <class Key,
412+
class Extent,
413+
cuda::thread_scope Scope,
414+
class KeyEqual,
415+
class ProbingScheme,
416+
class Allocator,
417+
class Storage>
418+
constexpr static_multiset<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::hasher
419+
static_multiset<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::hash_function()
420+
const noexcept
421+
{
422+
return impl_->hash_function();
423+
}
424+
411425
template <class Key,
412426
class Extent,
413427
cuda::thread_scope Scope,

include/cuco/detail/static_multiset/static_multiset_ref.inl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ static_multiset_ref<Key, Scope, KeyEqual, ProbingScheme, StorageRef, Operators..
108108
return this->impl_.key_eq();
109109
}
110110

111+
template <typename Key,
112+
cuda::thread_scope Scope,
113+
typename KeyEqual,
114+
typename ProbingScheme,
115+
typename StorageRef,
116+
typename... Operators>
117+
__host__ __device__ constexpr static_multiset_ref<Key,
118+
Scope,
119+
KeyEqual,
120+
ProbingScheme,
121+
StorageRef,
122+
Operators...>::hasher
123+
static_multiset_ref<Key, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>::hash_function()
124+
const noexcept
125+
{
126+
return impl_.hash_function();
127+
}
128+
111129
template <typename Key,
112130
cuda::thread_scope Scope,
113131
typename KeyEqual,

include/cuco/detail/static_set/static_set.inl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,20 @@ static_set<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::key
527527
return impl_->key_eq();
528528
}
529529

530+
template <class Key,
531+
class Extent,
532+
cuda::thread_scope Scope,
533+
class KeyEqual,
534+
class ProbingScheme,
535+
class Allocator,
536+
class Storage>
537+
constexpr static_set<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::hasher
538+
static_set<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::hash_function()
539+
const noexcept
540+
{
541+
return impl_->hash_function();
542+
}
543+
530544
template <class Key,
531545
class Extent,
532546
cuda::thread_scope Scope,

0 commit comments

Comments
 (0)