From fb5a255755b44d80f181b58cfea1647d0d64148a Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 13 Oct 2016 02:35:34 +0000 Subject: unstable sort [ci skip] * array.c (rb_ary_sort_bang, rb_ary_sort, rb_ary_sort_by_bang): [DOC] describe that sort may not be stable. * enum.c (enum_sort, enum_sort_by): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'array.c') diff --git a/array.c b/array.c index 476b1c4d66..55cdd9d7e3 100644 --- a/array.c +++ b/array.c @@ -2436,6 +2436,9 @@ sort_2(const void *ap, const void *bp, void *dummy) * an integer less than 0 when +b+ follows +a+, +0+ when +a+ and +b+ * are equivalent, or an integer greater than 0 when +a+ follows +b+. * + * The result is not guaranteed as stable. When comparison of two + * elements returns +0+, the order of the elements is unpredictable. + * * See also Enumerable#sort_by. * * a = [ "d", "a", "e", "c", "b" ] @@ -2517,6 +2520,8 @@ rb_ary_sort_bang(VALUE ary) * an integer less than 0 when +b+ follows +a+, +0+ when +a+ and +b+ * are equivalent, or an integer greater than 0 when +a+ follows +b+. * + * The result is not guaranteed as stable. When comparison of two + * elements returns +0+, the order of the elements is unpredictable. * * See also Enumerable#sort_by. * @@ -2674,6 +2679,9 @@ sort_by_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, dummy)) * Sorts +self+ in place using a set of keys generated by mapping the * values in +self+ through the given block. * + * The result is not guaranteed as stable. When two keys are equal, + * the order of the corresponding elements is unpredictable. + * * If no block is given, an Enumerator is returned instead. * */ -- cgit v1.2.3