Skip to content

Commit

Permalink
Fix an edge case for creating PGM index for floating point types
Browse files Browse the repository at this point in the history
  • Loading branch information
yangzq50 authored Apr 24, 2024
1 parent c423a88 commit 80bfdb6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions include/pgm/piecewise_linear_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,14 @@ size_t make_segmentation(size_t n, size_t start, size_t end, size_t epsilon, Fin
if (in(end - 1) != in(end - 2))
add_point(in(end - 1), end - 1);

if (end == n)
add_point(in(n - 1) + 1, n); // Ensure values greater than the last one are mapped to n
if (end == n) {
// Ensure values greater than the last one are mapped to n
if constexpr (std::is_floating_point_v<K>) {
add_point(std::nextafter(in(n - 1), std::numeric_limits<K>::infinity()), n);
} else {
add_point(in(n - 1) + 1, n);
}
}

out(opt.get_segment());
return ++c;
Expand Down Expand Up @@ -356,4 +362,4 @@ size_t make_segmentation_par(size_t n, size_t epsilon, Fin in, Fout out) {
return c;
}

}
}

0 comments on commit 80bfdb6

Please sign in to comment.