mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-08-12 06:10:29 +02:00
reverted partition algorithm not needed
This commit is contained in:
@@ -125,58 +125,4 @@ inline double linear_interpolation(const std::pair<double, double> &bin_edge,
|
||||
bin_values.second * (coord - bin_edge.first) / bin_width;
|
||||
}
|
||||
|
||||
/// @brief XOR operator
|
||||
inline bool XOR(const bool a, const bool b) { return (a || b) && !(a && b); }
|
||||
|
||||
/// @brief range struct
|
||||
template <typename Iterator> struct range {
|
||||
/// @brief start of the range
|
||||
Iterator start{};
|
||||
/// @brief end of the range
|
||||
Iterator end{};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief partition range of elements into contiguous subranges for which the
|
||||
* partition criteria is the same.
|
||||
* @param start pointer to the first element of the range
|
||||
* @param end pointer to the last element of the range
|
||||
* @param partition_criteria function that returns true or false for a given
|
||||
* element
|
||||
* @return vector of ranges that are contiguous and have the same partition
|
||||
* criteria
|
||||
*/
|
||||
template <typename Iterator>
|
||||
std::vector<range<Iterator>> partition(
|
||||
Iterator start, Iterator end,
|
||||
std::function<bool(const typename std::iterator_traits<Iterator>::value_type
|
||||
&)> &partition_criteria) {
|
||||
std::vector<range<Iterator>> partitions;
|
||||
partitions.reserve(std::distance(start, end));
|
||||
|
||||
auto partition_start = start;
|
||||
auto partition_end = end;
|
||||
|
||||
bool chunk_fulfills_criteria = partition_criteria(
|
||||
*partition_start); // starts with range fulfilling criteria
|
||||
|
||||
auto chunk_criteria =
|
||||
[&partition_criteria, &chunk_fulfills_criteria](
|
||||
const typename std::iterator_traits<Iterator>::value_type &value) {
|
||||
return XOR(partition_criteria(value), chunk_fulfills_criteria);
|
||||
}; // exclusive or
|
||||
|
||||
while (partition_start < end) {
|
||||
partition_end = std::find_if(partition_start, end, chunk_criteria);
|
||||
|
||||
partitions.push_back({partition_start, partition_end});
|
||||
partition_start = partition_end;
|
||||
|
||||
chunk_fulfills_criteria =
|
||||
!chunk_fulfills_criteria; // flip criteria for next chunk
|
||||
}
|
||||
|
||||
return partitions;
|
||||
}
|
||||
|
||||
} // namespace aare
|
||||
Reference in New Issue
Block a user