Re:Safety vs. Performance. A case study of C, C++ and Rust s...
by fluoridation on Thursday October 05, 2023 @04:02PM
(#37783574)
There are still ways for a sort function to not work properly with the comparer, even if the criterion is correct. As mentioned in the article, the comparer might have internal state that the sorter duplicates during intermediate steps, thus breaking assumptions made by the caller. The example the article gives is a comparer that increments a variable each time it's called, to count the number of comparisons. Depending on how this is done and how the sorter is implemented, copying the comparer may break this behavior.
[ Parent
| on HN ]
Re:Safety vs. Performance. A case study of C, C++ and Rust s...
by prosqlinjector on Thursday October 05, 2023 @09:14PM
(#37786187)
> to not work properly with the comparer, even if the criterion is correct.
Then the algorithm is incorrect or its specification for the compare function.
> The example the article gives is a comparer that increments a variable each time it's called, to count the number of comparisons. Depending on how this is done and how the sorter is implemented, copying the comparer may break this behavior.
Yep, then that means the comparer is not valid and does not satisfy the necessary requirements.