OSDN Git Service

[docs] Add a note on non-deterministic sorting order of equal elements
authorMandeep Singh Grang <mgrang@codeaurora.org>
Tue, 24 Apr 2018 21:25:57 +0000 (21:25 +0000)
committerMandeep Singh Grang <mgrang@codeaurora.org>
Tue, 24 Apr 2018 21:25:57 +0000 (21:25 +0000)
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

docs/CodingStandards.rst

index 1d631cc..1010a4b 100644 (file)
@@ -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
 ============