Skip to content
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

perf(Algorithm): increase allowed parameter types #875

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions include/geode/basic/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ namespace geode
{
/*!
* Delete some elements from a given vector.
* @tparam T Type of the vector elements.
* @param[in] to_delete Vector of the same size than values. If to_delete[i]
* is true the i-th element is deleted, else the element is kept.
* @param[in/out] values Vector in which perform deletions.
* @pre T should have default constructor (needed for call resize method on
* vector).
* @return The number of deleted elements
*/
template < typename T >
template < typename DeleteContainer, typename ValueContainer >
index_t delete_vector_elements(
const std::vector< bool >& to_delete, std::vector< T >& values )
const DeleteContainer& to_delete, ValueContainer& values )
{
OPENGEODE_ASSERT( to_delete.size() == values.size(),
"[delete_vector_elements] Number of elements in the two vectors "
Expand Down Expand Up @@ -73,15 +70,14 @@ namespace geode

/*!
* Create a new vector containing only some elements from a given vector.
* @tparam T Type of the vector elements.
* @param[in] to_keep Vector of the same size than in_values. If to_keep[i]
* is true the i-th element is kept.
* @param[in] in_values Vector in which perform deletions.
* @return A vector containing only kept elements of in_values
*/
template < typename T >
std::vector< T > extract_vector_elements(
const std::vector< bool >& to_keep, const std::vector< T >& in_values )
template < typename DeleteContainer, typename ValueContainer >
ValueContainer extract_vector_elements(
const DeleteContainer& to_keep, const ValueContainer& in_values )
{
OPENGEODE_ASSERT( to_keep.size() == in_values.size(),
"[extract_vector_elements] Number of elements in the two vectors "
Expand All @@ -92,7 +88,7 @@ namespace geode
{
return in_values;
}
std::vector< T > out_values;
ValueContainer out_values;
out_values.reserve( nb );
for( const auto i : Indices{ to_keep } )
{
Expand Down