mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-03 01:12:53 +00:00
[docs] Add a note on non-deterministic sorting order of equal elements
Reviewers: RKSimon, t.p.northover, dexonsmith Reviewed By: RKSimon Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45831 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330773 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ebab8e7d8d
commit
727ef0e543
@ -826,6 +826,17 @@ As a rule of thumb, in case an ordered result is expected, remember to
|
||||
sort an unordered container before iteration. Or use ordered containers
|
||||
like vector/MapVector/SetVector if you want to iterate pointer keys.
|
||||
|
||||
Beware of non-deterministic sorting order of equal elements
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
std::sort uses a non-stable sorting algorithm in which the order of equal
|
||||
elements is not guaranteed to be preserved. Thus using std::sort for a
|
||||
container having equal elements may result in non-determinstic behavior.
|
||||
To uncover such instances of non-determinism, LLVM has introduced a new
|
||||
llvm::sort wrapper function. For an EXPENSIVE_CHECKS build this will randomly
|
||||
shuffle the container before sorting. As a rule of thumb, always make sure to
|
||||
use llvm::sort instead of std::sort.
|
||||
|
||||
Style Issues
|
||||
============
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user