Skip to content

Commit d39d59a

Browse files
authored
Add retrieve_all for multiset and multimap (#635)
This PR adds `retrieve_all` for multiset and multimap
1 parent 5b8d055 commit d39d59a

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

include/cuco/detail/static_multimap/static_multimap.inl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,26 @@ static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Stora
398398
return impl_->count(first, last, ref(op::count), stream);
399399
}
400400

401+
template <class Key,
402+
class T,
403+
class Extent,
404+
cuda::thread_scope Scope,
405+
class KeyEqual,
406+
class ProbingScheme,
407+
class Allocator,
408+
class Storage>
409+
template <typename KeyOut, typename ValueOut>
410+
std::pair<KeyOut, ValueOut>
411+
static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::retrieve_all(
412+
KeyOut keys_out, ValueOut values_out, cuda::stream_ref stream) const
413+
{
414+
auto const zipped_out_begin = thrust::make_zip_iterator(thrust::make_tuple(keys_out, values_out));
415+
auto const zipped_out_end = impl_->retrieve_all(zipped_out_begin, stream);
416+
auto const num = std::distance(zipped_out_begin, zipped_out_end);
417+
418+
return std::make_pair(keys_out + num, values_out + num);
419+
}
420+
401421
template <class Key,
402422
class T,
403423
class Extent,

include/cuco/detail/static_multiset/static_multiset.inl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,21 @@ static_multiset<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>
474474
return impl_->retrieve_outer(first, last, output_probe, output_match, probe_ref, stream);
475475
}
476476

477+
template <class Key,
478+
class Extent,
479+
cuda::thread_scope Scope,
480+
class KeyEqual,
481+
class ProbingScheme,
482+
class Allocator,
483+
class Storage>
484+
template <typename OutputIt>
485+
OutputIt
486+
static_multiset<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::retrieve_all(
487+
OutputIt output_begin, cuda::stream_ref stream) const
488+
{
489+
return impl_->retrieve_all(output_begin, stream);
490+
}
491+
477492
template <class Key,
478493
class Extent,
479494
cuda::thread_scope Scope,

include/cuco/static_map.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ class static_map {
852852
size_type count(InputIt first, InputIt last, cuda::stream_ref stream = {}) const;
853853

854854
/**
855-
* @brief Retrieves all of the keys and their associated values.
855+
* @brief Retrieves all of the keys and their associated values contained in the map
856856
*
857857
* @note This API synchronizes the given stream.
858858
* @note The order in which keys are returned is implementation defined and not guaranteed to be

include/cuco/static_multimap.cuh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,31 @@ class static_multimap {
602602
template <typename InputIt>
603603
size_type count(InputIt first, InputIt last, cuda::stream_ref stream = {}) const;
604604

605+
/**
606+
* @brief Retrieves all of the keys and their associated values contained in the multimap
607+
*
608+
* @note This API synchronizes the given stream.
609+
* @note The order in which keys are returned is implementation defined and not guaranteed to be
610+
* consistent between subsequent calls to `retrieve_all`.
611+
* @note Behavior is undefined if the range beginning at `keys_out` or `values_out` is smaller
612+
* than the return value of `size()`.
613+
*
614+
* @tparam KeyOut Device accessible random access output iterator whose `value_type` is
615+
* convertible from `key_type`.
616+
* @tparam ValueOut Device accesible random access output iterator whose `value_type` is
617+
* convertible from `mapped_type`.
618+
*
619+
* @param keys_out Beginning output iterator for keys
620+
* @param values_out Beginning output iterator for associated values
621+
* @param stream CUDA stream used for this operation
622+
*
623+
* @return Pair of iterators indicating the last elements in the output
624+
*/
625+
template <typename KeyOut, typename ValueOut>
626+
std::pair<KeyOut, ValueOut> retrieve_all(KeyOut keys_out,
627+
ValueOut values_out,
628+
cuda::stream_ref stream = {}) const;
629+
605630
/**
606631
* @brief Regenerates the container.
607632
*

include/cuco/static_multiset.cuh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,26 @@ class static_multiset {
738738
OutputMatchIt output_match,
739739
cuda::stream_ref stream = {}) const;
740740

741+
/**
742+
* @brief Retrieves all keys contained in the multiset
743+
*
744+
* @note This API synchronizes the given stream.
745+
* @note The order in which keys are returned is implementation defined and not guaranteed to be
746+
* consistent between subsequent calls to `retrieve_all`.
747+
* @note Behavior is undefined if the range beginning at `output_begin` is smaller than the return
748+
* value of `size()`.
749+
*
750+
* @tparam OutputIt Device accessible random access output iterator whose `value_type` is
751+
* convertible from the container's `key_type`.
752+
*
753+
* @param output_begin Beginning output iterator for keys
754+
* @param stream CUDA stream used for this operation
755+
*
756+
* @return Iterator indicating the end of the output
757+
*/
758+
template <typename OutputIt>
759+
OutputIt retrieve_all(OutputIt output_begin, cuda::stream_ref stream = {}) const;
760+
741761
/**
742762
* @brief Regenerates the container.
743763
*

0 commit comments

Comments
 (0)