Skip to content

Commit

Permalink
Use stable_sort in PDFTane::CalculatePFDError
Browse files Browse the repository at this point in the history
Use stable_sort instead of sort to avoid relying on
unspecified behaviour (wheter sort preserves order of equal elements)
  • Loading branch information
p-senichenkov committed Dec 18, 2024
1 parent 84fb781 commit d4d9b5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/core/algorithms/fd/tane/pfdtane.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "pfdtane.h"

#include <algorithm>

#include "config/error/option.h"
#include "config/error_measure/option.h"
#include "enums.h"
Expand Down Expand Up @@ -48,10 +50,10 @@ config::ErrorType PFDTane::CalculatePFDError(model::PositionListIndex const* x_p
std::deque<Cluster> xa_index = xa_pli->GetIndex();
std::shared_ptr<Cluster const> probing_table_ptr = x_pli->CalculateAndGetProbingTable();
auto const& probing_table = *probing_table_ptr;
std::sort(xa_index.begin(), xa_index.end(),
[&probing_table](Cluster const& a, Cluster const& b) {
return probing_table[a.front()] < probing_table[b.front()];
});
std::stable_sort(xa_index.begin(), xa_index.end(),
[&probing_table](Cluster const& a, Cluster const& b) {
return probing_table[a.front()] < probing_table[b.front()];
});
double sum = 0.0;
std::size_t cluster_rows_count = 0;
std::deque<Cluster> const& x_index = x_pli->GetIndex();
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_pfdtane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ INSTANTIATE_TEST_SUITE_P(
PFDTaneTestMiningSuite, TestPFDTaneMining,
::testing::Values(
PFDTaneMiningParams(44381, 0.3, +algos::PfdErrorMeasure::per_value, kTestFD),
PFDTaneMiningParams(39491, 0.1, +algos::PfdErrorMeasure::per_value, kIris),
PFDTaneMiningParams(19266, 0.1, +algos::PfdErrorMeasure::per_value, kIris),
PFDTaneMiningParams(10695, 0.01, +algos::PfdErrorMeasure::per_value, kIris),
PFDTaneMiningParams(7893, 0.1, +algos::PfdErrorMeasure::per_value, kNeighbors10k),
PFDTaneMiningParams(44088, 0.1, +algos::PfdErrorMeasure::per_value, kNeighbors10k),
PFDTaneMiningParams(41837, 0.01, +algos::PfdErrorMeasure::per_value, kNeighbors10k)
));

Expand Down

0 comments on commit d4d9b5c

Please sign in to comment.