Skip to content

Commit

Permalink
Updates: add getters, ctors and related widgets for erase
Browse files Browse the repository at this point in the history
  • Loading branch information
PointKernel committed Oct 4, 2023
1 parent f239a99 commit baf1987
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 9 deletions.
10 changes: 10 additions & 0 deletions include/cuco/detail/open_addressing/open_addressing_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,16 @@ class open_addressing_impl {
return empty_key_sentinel_;
}

/**
* @brief Gets the sentinel value used to represent an empty key slot.
*
* @return The sentinel value used to represent an empty key slot
*/
[[nodiscard]] constexpr key_type erased_key_sentinel() const noexcept
{
return erased_key_sentinel_;
}

/**
* @brief Gets the key comparator.
*
Expand Down
20 changes: 20 additions & 0 deletions include/cuco/detail/open_addressing/open_addressing_ref_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,25 @@ class open_addressing_ref_impl {
{
}

/**
* @brief Constructs open_addressing_ref_impl.
*
* @param empty_slot_sentinel Sentinel indicating an empty slot
* @param probing_scheme Probing scheme
* @param storage_ref Non-owning ref of slot storage
*/
__host__ __device__ explicit constexpr open_addressing_ref_impl(
value_type empty_slot_sentinel,
key_type erased_key_sentinel,
probing_scheme_type const& probing_scheme,
storage_ref_type storage_ref) noexcept
: empty_slot_sentinel_{empty_slot_sentinel},
erased_key_sentinel_{erased_key_sentinel},
probing_scheme_{probing_scheme},
storage_ref_{storage_ref}
{
}

/**
* @brief Gets the maximum number of elements the container can hold.
*
Expand Down Expand Up @@ -920,6 +939,7 @@ class open_addressing_ref_impl {
}

value_type empty_slot_sentinel_; ///< Sentinel value indicating an empty slot
key_type erased_key_sentinel_; ///< Key value that represents an erased slot
probing_scheme_type probing_scheme_; ///< Probing scheme
storage_ref_type storage_ref_; ///< Slot storage ref
};
Expand Down
31 changes: 26 additions & 5 deletions include/cuco/detail/static_map/static_map.inl
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,21 @@ constexpr static_map<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator,
return this->empty_value_sentinel_;
}

template <class Key,
class T,
class Extent,
cuda::thread_scope Scope,
class KeyEqual,
class ProbingScheme,
class Allocator,
class Storage>
constexpr static_map<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::key_type
static_map<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::
erased_key_sentinel() const noexcept
{
return impl_->erased_key_sentinel();
}

template <class Key,
class T,
class Extent,
Expand All @@ -481,11 +496,17 @@ auto static_map<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Stora
Operators...) const noexcept
{
static_assert(sizeof...(Operators), "No operators specified");
return ref_type<Operators...>{cuco::empty_key<key_type>(this->empty_key_sentinel()),
cuco::empty_value<mapped_type>(this->empty_value_sentinel()),
impl_->key_eq(),
impl_->probing_scheme(),
impl_->storage_ref()};
return this->empty_key_sentinel() == this->erased_key_sentinel()
? ref_type<Operators...>{cuco::empty_key<key_type>(this->empty_key_sentinel()),
cuco::empty_value<mapped_type>(this->empty_value_sentinel()),
impl_->key_eq(),
impl_->probing_scheme(),
impl_->storage_ref()}
: ref_type<Operators...>{cuco::empty_key<key_type>(this->empty_key_sentinel()),
cuco::empty_value<mapped_type>(this->empty_value_sentinel()),
impl_->key_eq(),
impl_->probing_scheme(),
impl_->storage_ref()};
}
} // namespace experimental
} // namespace cuco
29 changes: 29 additions & 0 deletions include/cuco/detail/static_map/static_map_ref.inl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ __host__ __device__ constexpr static_map_ref<
{
}

template <typename Key,
typename T,
cuda::thread_scope Scope,
typename KeyEqual,
typename ProbingScheme,
typename StorageRef,
typename... Operators>
__host__ __device__ constexpr static_map_ref<
Key,
T,
Scope,
KeyEqual,
ProbingScheme,
StorageRef,
Operators...>::static_map_ref(cuco::empty_key<Key> empty_key_sentinel,
cuco::empty_value<T> empty_value_sentinel,
cuco::erased_key<Key> erased_key_sentinel,
KeyEqual const& predicate,
ProbingScheme const& probing_scheme,
StorageRef storage_ref) noexcept
: impl_{cuco::pair{empty_key_sentinel, empty_value_sentinel},
erased_key_sentinel,
probing_scheme,
storage_ref},
empty_value_sentinel_{empty_value_sentinel},
predicate_{empty_key_sentinel, predicate}
{
}

template <typename Key,
typename T,
cuda::thread_scope Scope,
Expand Down
28 changes: 24 additions & 4 deletions include/cuco/detail/static_set/static_set.inl
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,20 @@ static_set<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::emp
return impl_->empty_key_sentinel();
}

template <class Key,
class Extent,
cuda::thread_scope Scope,
class KeyEqual,
class ProbingScheme,
class Allocator,
class Storage>
constexpr static_set<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::key_type
static_set<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::erased_key_sentinel()
const noexcept
{
return impl_->erased_key_sentinel();
}

template <class Key,
class Extent,
cuda::thread_scope Scope,
Expand All @@ -389,10 +403,16 @@ auto static_set<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>
Operators...) const noexcept
{
static_assert(sizeof...(Operators), "No operators specified");
return ref_type<Operators...>{cuco::empty_key<key_type>(this->empty_key_sentinel()),
impl_->key_eq(),
impl_->probing_scheme(),
impl_->storage_ref()};
return this->empty_key_sentinel() == this->erased_key_sentinel()
? ref_type<Operators...>{cuco::empty_key<key_type>(this->empty_key_sentinel()),
impl_->key_eq(),
impl_->probing_scheme(),
impl_->storage_ref()}
: ref_type<Operators...>{cuco::empty_key<key_type>(this->empty_key_sentinel()),
cuco::erased_key<key_type>(this->erased_key_sentinel()),
impl_->key_eq(),
impl_->probing_scheme(),
impl_->storage_ref()};
}
} // namespace experimental
} // namespace cuco
22 changes: 22 additions & 0 deletions include/cuco/detail/static_set/static_set_ref.inl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ __host__ __device__ constexpr static_set_ref<
{
}

template <typename Key,
cuda::thread_scope Scope,
typename KeyEqual,
typename ProbingScheme,
typename StorageRef,
typename... Operators>
__host__ __device__ constexpr static_set_ref<
Key,
Scope,
KeyEqual,
ProbingScheme,
StorageRef,
Operators...>::static_set_ref(cuco::empty_key<Key> empty_key_sentinel,
cuco::erased_key<Key> erased_key_sentinel,
KeyEqual const& predicate,
ProbingScheme const& probing_scheme,
StorageRef storage_ref) noexcept
: impl_{empty_key_sentinel, erased_key_sentinel, probing_scheme, storage_ref},
predicate_{empty_key_sentinel, predicate}
{
}

template <typename Key,
cuda::thread_scope Scope,
typename KeyEqual,
Expand Down
7 changes: 7 additions & 0 deletions include/cuco/static_map.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,13 @@ class static_map {
*/
[[nodiscard]] constexpr mapped_type empty_value_sentinel() const noexcept;

/**
* @brief Gets the sentinel value used to represent an erased key slot.
*
* @return The sentinel value used to represent an erased key slot
*/
[[nodiscard]] constexpr key_type erased_key_sentinel() const noexcept;

/**
* @brief Get device ref with operators.
*
Expand Down
7 changes: 7 additions & 0 deletions include/cuco/static_set.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,13 @@ class static_set {
*/
[[nodiscard]] constexpr key_type empty_key_sentinel() const noexcept;

/**
* @brief Gets the sentinel value used to represent an erased key slot.
*
* @return The sentinel value used to represent an erased key slot
*/
[[nodiscard]] constexpr key_type erased_key_sentinel() const noexcept;

/**
* @brief Get device ref with operators.
*
Expand Down

0 comments on commit baf1987

Please sign in to comment.