[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
Tue Apr 24 14:29:27 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL330773: [docs] Add a note on non-deterministic sorting order of equal elements (authored by mgrang, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45831?vs=143142&id=143809#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45831

Files:
  llvm/trunk/docs/CodingStandards.rst


Index: llvm/trunk/docs/CodingStandards.rst
===================================================================
--- llvm/trunk/docs/CodingStandards.rst
+++ llvm/trunk/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.143809.patch
Type: text/x-patch
Size: 1003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180424/0216e096/attachment.bin>


More information about the llvm-commits mailing list