[PATCH] D45831: [docs] Add a note on non-deterministic sorting order of equal elements
Mandeep Singh Grang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 19 11:54:26 PDT 2018
mgrang created this revision.
mgrang added reviewers: RKSimon, t.p.northover, dexonsmith.
Repository:
rL LLVM
https://reviews.llvm.org/D45831
Files:
docs/CodingStandards.rst
Index: docs/CodingStandards.rst
===================================================================
--- docs/CodingStandards.rst
+++ docs/CodingStandards.rst
@@ -826,6 +826,17 @@
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
============
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45831.143142.patch
Type: text/x-patch
Size: 970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180419/43964524/attachment.bin>
More information about the llvm-commits
mailing list