On 2014/07/03, at 2:06, Bram Moolenaar <b...@moolenaar.net> wrote: > + static int item_compare_keep_zero;
This variable is set to FALSE for the sort() function, and only set to TRUE for uniq(). Is this intentional? Even if I set this variable to TRUE for sort(), the sort is still not stable and test55 fails on my Mac: --- test55.ok 2014-07-03 12:22:11.000000000 +0900 +++ test55.failed 2014-07-03 14:56:53.000000000 +0900 @@ -101,9 +101,9 @@ [[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0'] ['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]] ['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]] -[-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255] -['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] -['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] +[-1, 'four', 'two', 'three', 'one', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255] +['bar', 'Bar', 'BAR', 'FOO', 'foo', 'Foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] +['bar', 'Bar', 'BAR', 'FOO', 'foo', 'Foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] ['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] ['aa', 'bb'] ['aa', 'bb'] > + /* When the result would be zero, compare the pointers themselves. > Makes > + * the sort stable. */ > + if (res == 0 && !item_compare_keep_zero) > + res = s1 > s2 ? 1 : -1; > + This doesn't work, it seems. During the sort process the qsort() function swaps the data in the array ptrs[]. Comparing s1 and s2 is to compare the current position in the array, which may have been already modified (swapped) by qsort(). I think we need to save the original position along with the data. See the patch in my previous post (26 June, Re: Patch 7.4.341, the 4th post in https://groups.google.com/forum/#!topic/vim_dev/RUByys6B3Yk). In this patch, the original position is saved in the member 'i' of the struct sdata_T. I think my patch works, but I guess it will make the sort somewhat slower, because there are now two function calls per comparison. If this is a problem, then we could modify item_compare() itself instead of using a wrapper function item_compare_stable(). PS. What is the best way of referring to a previous post in this mailing list? -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.