<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Order I&#160;Say!</title>
	<atom:link href="http://cpp-next.com/archive/2010/02/order-i-say/feed/" rel="self" type="application/rss+xml" />
	<link>http://cpp-next.com/archive/2010/02/order-i-say/</link>
	<description>The next generation of C++</description>
	<lastBuildDate>Mon, 30 Apr 2012 15:07:48 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Bernard</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-585</link>
		<dc:creator>Bernard</dc:creator>
		<pubDate>Fri, 24 Sep 2010 08:06:53 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-585</guid>
		<description>&lt;blockquote cite=&quot;comment-521&quot;&gt;

«1. Nobody has a use for sorting on a partial but not strict-weak order, and we only generalize from real-world solutions. »
&lt;/blockquote&gt;

&lt;p&gt;Just to mention that it is used in some genetic algorithms (Non dominated Sorting Genetic Algorithm)  to select potentially useful solutions:
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.4257&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote cite="comment-521">

«1. Nobody has a use for sorting on a partial but not strict-weak order, and we only generalize from real-world solutions. »
</blockquote>

<p>Just to mention that it is used in some genetic algorithms (Non dominated Sorting Genetic Algorithm)  to select potentially useful solutions:
<a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.4257" rel="nofollow">http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.4257</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik Kruus</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-584</link>
		<dc:creator>Erik Kruus</dc:creator>
		<pubDate>Wed, 28 Jul 2010 17:53:03 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-584</guid>
		<description>&lt;p&gt;For MyCmp( a, b ), do you have a way to get from &quot;a&quot; to &quot;position of a&quot;
in any fashion compatible with STL containers?  I don&#039;t know of one.&lt;/p&gt;

&lt;p&gt;There&#039;s a reason why most folks use a combination of list + map to do
an LRU queue --- because you just can&#039;t write an STL-compatible comparator
that &quot;just works right&quot; in the manner you suggest.&lt;/p&gt;

&lt;p&gt;For a &quot;stable multiset&quot;, I&#039;ve rolled out some code that works but
is nowhere near as polished as the boost/intrusive stuff -- but it
handles stability-under-equality (finally).&lt;/p&gt;

&lt;p&gt;Dealing with equality is a pain in the butt: it basically means you need
to handle extra cases at the binary-tree node-level operations.  I&#039;ll
probably go back and see if I can hack something more boost-like.&lt;/p&gt;

&lt;p&gt;Erik.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>For MyCmp( a, b ), do you have a way to get from &#8220;a&#8221; to &#8220;position of a&#8221;
in any fashion compatible with STL containers?  I don&#8217;t know of one.</p>

<p>There&#8217;s a reason why most folks use a combination of list + map to do
an LRU queue &#8212; because you just can&#8217;t write an STL-compatible comparator
that &#8220;just works right&#8221; in the manner you suggest.</p>

<p>For a &#8220;stable multiset&#8221;, I&#8217;ve rolled out some code that works but
is nowhere near as polished as the boost/intrusive stuff &#8212; but it
handles stability-under-equality (finally).</p>

<p>Dealing with equality is a pain in the butt: it basically means you need
to handle extra cases at the binary-tree node-level operations.  I&#8217;ll
probably go back and see if I can hack something more boost-like.</p>

<p>Erik.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerry Coffin</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-583</link>
		<dc:creator>Jerry Coffin</dc:creator>
		<pubDate>Fri, 26 Mar 2010 08:01:32 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-583</guid>
		<description>&lt;p&gt;For what little it might be worth, the term &quot;stable&quot; for order-preservation in a sort goes back at least a little further than that. The second edition of Knuth V3 (copyright 1973) uses it on a regular basis. On the other hand, he usually puts quotation marks around it, giving the impression that the usage was (at least fairly) new at the time.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>For what little it might be worth, the term &#8220;stable&#8221; for order-preservation in a sort goes back at least a little further than that. The second edition of Knuth V3 (copyright 1973) uses it on a regular basis. On the other hand, he usually puts quotation marks around it, giving the impression that the usage was (at least fairly) new at the time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher Dearlove</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-582</link>
		<dc:creator>Christopher Dearlove</dc:creator>
		<pubDate>Wed, 03 Mar 2010 17:34:46 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-582</guid>
		<description>&lt;p&gt;Except normally the information needed by the more sophisticated predicate isn&#039;t available for free. stable_sort doesn&#039;t need the items to be tagged with their original index, the more sophisticated predicate will. I&#039;m also not at all sure that the index would be something I&#039;d want to add to a class just to avoid using stable_sort. However as I can&#039;t recall actually needing a stable_sort (except possibly when sorting a std::list where it&#039;s the only type of sort available) that is not clear to me.&lt;/p&gt;

&lt;p&gt;Also note that the gain is at best a factor, as both are O(n log n), some of which will be lost in using the new predicate. Is this (requiring to use sort rather than stable_sort) premature optimisation (or even pessimisation if adding the index costs)?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Except normally the information needed by the more sophisticated predicate isn&#8217;t available for free. stable_sort doesn&#8217;t need the items to be tagged with their original index, the more sophisticated predicate will. I&#8217;m also not at all sure that the index would be something I&#8217;d want to add to a class just to avoid using stable_sort. However as I can&#8217;t recall actually needing a stable_sort (except possibly when sorting a std::list where it&#8217;s the only type of sort available) that is not clear to me.</p>

<p>Also note that the gain is at best a factor, as both are O(n log n), some of which will be lost in using the new predicate. Is this (requiring to use sort rather than stable_sort) premature optimisation (or even pessimisation if adding the index costs)?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duffy O'Craven</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-581</link>
		<dc:creator>Duffy O'Craven</dc:creator>
		<pubDate>Wed, 03 Mar 2010 15:46:45 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-581</guid>
		<description>&lt;blockquote&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/z02ba27t(VS.80).aspx&quot; rel=&quot;nofollow&quot;&gt;Usually, the sort algorithm is significantly faster than stable_sort.&lt;/a&gt;
 &lt;/blockquote&gt;

&lt;p&gt;which makes me disinclined to use a library &lt;code&gt;stable_sort&lt;/code&gt; if I can achieve the same effect with a faster sort algorithm just by providing a slightly more sophisticated predicate.&lt;/p&gt;

&lt;p&gt;By providing a more sophisticated predicate, thus making me &quot;total ordered&quot;, the same result will be produced whether using library &lt;code&gt;sort&lt;/code&gt; or &lt;code&gt;stable_sort&lt;/code&gt;.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote><a href="http://msdn.microsoft.com/en-us/library/z02ba27t(VS.80).aspx" rel="nofollow">Usually, the sort algorithm is significantly faster than stable_sort.</a>
 </blockquote>

<p>which makes me disinclined to use a library <code>stable_sort</code> if I can achieve the same effect with a faster sort algorithm just by providing a slightly more sophisticated predicate.</p>

<p>By providing a more sophisticated predicate, thus making me &#8220;total ordered&#8221;, the same result will be produced whether using library <code>sort</code> or <code>stable_sort</code>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duffy O'Craven</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-580</link>
		<dc:creator>Duffy O'Craven</dc:creator>
		<pubDate>Wed, 03 Mar 2010 03:51:41 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-580</guid>
		<description>&lt;p&gt;Another way I&#039;ve thought of to phrase it, that might have explanatory value: &quot;My identity comprises my baggage and where I am in line.&quot; If you are going to compare me to another, you have to consider both:  what I hold and where I was when you started.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Another way I&#8217;ve thought of to phrase it, that might have explanatory value: &#8220;My identity comprises my baggage and where I am in line.&#8221; If you are going to compare me to another, you have to consider both:  what I hold and where I was when you started.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duffy O'Craven</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-579</link>
		<dc:creator>Duffy O'Craven</dc:creator>
		<pubDate>Wed, 03 Mar 2010 03:45:19 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-579</guid>
		<description>&lt;p&gt;Because the original index of each element is a unique numeric value that is trivial to order. Either the elements don&#039;t compare as equivalent, in which case they are ordered, or the elements compare as equivalent and so are differentiated as to order by the unique original index of each element.&lt;/p&gt;

&lt;p&gt;P.S. &quot;stable&quot; may have been in the vernacular, but when I took 6.036, The term C++ hadn&#039;t even been coined yet, let alone stable_sort.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Because the original index of each element is a unique numeric value that is trivial to order. Either the elements don&#8217;t compare as equivalent, in which case they are ordered, or the elements compare as equivalent and so are differentiated as to order by the unique original index of each element.</p>

<p>P.S. &#8220;stable&#8221; may have been in the vernacular, but when I took 6.036, The term C++ hadn&#8217;t even been coined yet, let alone stable_sort.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Abrahams</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-578</link>
		<dc:creator>Dave Abrahams</dc:creator>
		<pubDate>Wed, 03 Mar 2010 02:53:48 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-578</guid>
		<description>&lt;p&gt;…and it takes O(N) additional storage.  The term &quot;stable&quot; for order-preserving sort seems to date back to at least 1977 from what I can tell. But I don&#039;t see how any of this relates to your statement that stable sorts are always total orders.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>…and it takes O(N) additional storage.  The term &#8220;stable&#8221; for order-preserving sort seems to date back to at least 1977 from what I can tell. But I don&#8217;t see how any of this relates to your statement that stable sorts are always total orders.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duffy O'Craven</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-577</link>
		<dc:creator>Duffy O'Craven</dc:creator>
		<pubDate>Wed, 03 Mar 2010 01:01:47 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-577</guid>
		<description>&lt;p&gt;I didn&#039;t know it by that name: stable_sort, but I guess it is what &quot;order preserving sort&quot; back in my days in 6.036 has evolved into.&lt;/p&gt;

&lt;blockquote&gt;stable_sort grants that the relative order of the elements with equivalent values is preserved.
 &lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;A technique to achieve stable_sort, with any sort algorithm, is that if two elements compare as equivalent through all of the provided predicate sort keys, then append a simple std::less comparison of the original index of each element. When doing a multi-field sort, the aggregation structure to represent what predicate and data field and width is primary key, what predicate and data field and width is the secondary key, what is tertiary, etc. is easy to extend by one more to refer to the fixed-width index/address of the elements.&lt;/p&gt;

&lt;p&gt;A predicate invocation that would have been:&lt;/p&gt;

&lt;pre&gt;
 if A.primary &lt; B.primary
 else if B.primary &lt; A.primary
 else if A.secondary &lt; B.secondary
 else if B.secondary &lt; A.secondary
 else if A.tertiary &lt; B.tertiary
 else if B.tertiary &lt; A.tertiary
 &lt;/pre&gt;

&lt;p&gt;gets extended one more level to&lt;/p&gt;

&lt;pre&gt;
 else if A.origIndex &lt; B.origIndex
 else if B.origIndex &lt; A.origIndex

&lt;/pre&gt;

&lt;p&gt;and there is no possibility of falling through past that.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I didn&#8217;t know it by that name: stable_sort, but I guess it is what &#8220;order preserving sort&#8221; back in my days in 6.036 has evolved into.</p>

<blockquote>stable_sort grants that the relative order of the elements with equivalent values is preserved.
 </blockquote>

<p></p>

<p>A technique to achieve stable_sort, with any sort algorithm, is that if two elements compare as equivalent through all of the provided predicate sort keys, then append a simple std::less comparison of the original index of each element. When doing a multi-field sort, the aggregation structure to represent what predicate and data field and width is primary key, what predicate and data field and width is the secondary key, what is tertiary, etc. is easy to extend by one more to refer to the fixed-width index/address of the elements.</p>

<p>A predicate invocation that would have been:</p>

<pre>
 if A.primary &lt; B.primary
 else if B.primary &lt; A.primary
 else if A.secondary &lt; B.secondary
 else if B.secondary &lt; A.secondary
 else if A.tertiary &lt; B.tertiary
 else if B.tertiary &lt; A.tertiary
 </pre>

<p>gets extended one more level to</p>

<pre>
 else if A.origIndex &lt; B.origIndex
 else if B.origIndex &lt; A.origIndex

</pre>

<p>and there is no possibility of falling through past that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Abrahams</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-576</link>
		<dc:creator>Dave Abrahams</dc:creator>
		<pubDate>Tue, 02 Mar 2010 23:17:24 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-576</guid>
		<description>&lt;blockquote cite=&quot;comment-534&quot;&gt;

&lt;strong&gt;&lt;a href=&quot;#comment-534&quot; rel=&quot;nofollow&quot;&gt;Duffy&lt;/a&gt;&lt;/strong&gt;:
you were probably more inclined towards was hearing other perspectives which might enlighten&lt;/blockquote&gt;

&lt;p&gt;Bingo&lt;/p&gt;

&lt;blockquote cite=&quot;comment-534&quot;&gt;

&lt;strong&gt;&lt;a href=&quot;#comment-534&quot; rel=&quot;nofollow&quot;&gt;Duffy&lt;/a&gt;&lt;/strong&gt;: order preserving sorts…are always total order.&lt;/blockquote&gt;

&lt;p&gt;I confess that I didn&#039;t really understand the part in the &quot;…&quot;, but: &lt;code&gt;stable_sort&lt;/code&gt; only requires a strict weak ordering, not a total order.  So I&#039;m really not sure what you&#039;re driving at here.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote cite="comment-534">

<strong><a href="#comment-534" rel="nofollow">Duffy</a></strong>:
you were probably more inclined towards was hearing other perspectives which might enlighten</blockquote>

<p>Bingo</p>

<blockquote cite="comment-534">

<strong><a href="#comment-534" rel="nofollow">Duffy</a></strong>: order preserving sorts…are always total order.</blockquote>

<p>I confess that I didn&#8217;t really understand the part in the &#8220;…&#8221;, but: <code>stable_sort</code> only requires a strict weak ordering, not a total order.  So I&#8217;m really not sure what you&#8217;re driving at here.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

