From 5b3b8554c9f851a958c03fc707bd69e6ad6c5c13 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 --- enum.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'enum.c') diff --git a/enum.c b/enum.c index 62bcfba395..b328003425 100644 --- a/enum.c +++ b/enum.c @@ -934,6 +934,9 @@ enum_first(int argc, VALUE *argv, VALUE obj) * built-in Schwartzian Transform, useful when key computation or * comparison is expensive. * + * The result is not guaranteed as stable. When comparison of two + * elements returns +0+, the order of the elements is unpredictable. + * * %w(rhea kea flea).sort #=> ["flea", "kea", "rhea"] * (1..10).sort { |a, b| b <=> a } #=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] */ @@ -1004,6 +1007,9 @@ sort_by_cmp(const void *ap, const void *bp, void *data) * Sorts enum using a set of keys generated by mapping the * values in enum 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. * * %w{apple pear fig}.sort_by { |word| word.length} -- cgit v1.2.3