<?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>Sun, 05 Sep 2010 06:48:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Erik Kruus</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-721</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-721</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-581</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-581</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-545</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-545</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-544</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-544</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-543</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-543</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-542</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-542</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-540</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-540</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-539</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-539</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-536</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-536</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>
	<item>
		<title>By: Duffy O'Craven</title>
		<link>http://cpp-next.com/archive/2010/02/order-i-say/comment-page-1/#comment-535</link>
		<dc:creator>Duffy O'Craven</dc:creator>
		<pubDate>Tue, 02 Mar 2010 14:33:06 +0000</pubDate>
		<guid isPermaLink="false">http://cpp-next.com/?p=1023#comment-535</guid>
		<description>&lt;p&gt;The statement in the original XML Schema xsd:double and xsd:float that &quot;Not-a-number equals itself and is greater than all float values including positive infinity.&quot; (see &lt;a href=&quot;http://lists.xml.org/archives/xml-dev/200104/msg00078.html&quot; rel=&quot;nofollow&quot;&gt;2001 forum post&lt;/a&gt; for an in-depth discussion) further muddied the waters, regarding what programmers should do with IEEE floating point.&lt;/p&gt;

&lt;p&gt;More recent revisions of XML Schema &lt;a href=&quot;http://www.w3.org/TR/xmlschema-2/#double&quot; rel=&quot;nofollow&quot;&gt;xsd:double&lt;/a&gt; and &lt;a href=&quot;http://www.w3.org/TR/xmlschema-2/#float&quot; rel=&quot;nofollow&quot;&gt;xsd:float&lt;/a&gt; have come off that original stance somewhat, instead using the following phrases:&lt;/p&gt;

&lt;blockquote&gt;Positive infinity is greater than all other non-NaN values. NaN equals itself but is ·incomparable· with (neither greater than nor less than) any other value in the ·value space·.

This datatype differs from that of [IEEE 754-1985] in that there is only one NaN and only one zero. This makes the equality and ordering of values in the data space differ from that of [IEEE 754-1985] only in that for schema purposes NaN = NaN.
 &lt;/blockquote&gt;

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

&lt;p&gt;Still it does tend to require a dedicated clause in code to get sorting compatible with this, out of IEEE floating point.  One allowance that should be recognized, the XML schema governs textual representations of numbers, not the binary representations. To say that NaN = NaN, for XML means &#092;116&#092;141&#092;116 equals &#092;116&#092;141&#092;116, not that the 32bit or 64bit binary patterns which are NaN in IEEE floating point all equal each other. If you use XML in your programming domain, however, for the XML floating point to sort differently from the binary floating point, is usually undesirable.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>The statement in the original XML Schema xsd:double and xsd:float that &#8220;Not-a-number equals itself and is greater than all float values including positive infinity.&#8221; (see <a href="http://lists.xml.org/archives/xml-dev/200104/msg00078.html" rel="nofollow">2001 forum post</a> for an in-depth discussion) further muddied the waters, regarding what programmers should do with IEEE floating point.</p>

<p>More recent revisions of XML Schema <a href="http://www.w3.org/TR/xmlschema-2/#double" rel="nofollow">xsd:double</a> and <a href="http://www.w3.org/TR/xmlschema-2/#float" rel="nofollow">xsd:float</a> have come off that original stance somewhat, instead using the following phrases:</p>

<blockquote>Positive infinity is greater than all other non-NaN values. NaN equals itself but is ·incomparable· with (neither greater than nor less than) any other value in the ·value space·.

This datatype differs from that of [IEEE 754-1985] in that there is only one NaN and only one zero. This makes the equality and ordering of values in the data space differ from that of [IEEE 754-1985] only in that for schema purposes NaN = NaN.
 </blockquote>

<p></p>

<p>Still it does tend to require a dedicated clause in code to get sorting compatible with this, out of IEEE floating point.  One allowance that should be recognized, the XML schema governs textual representations of numbers, not the binary representations. To say that NaN = NaN, for XML means &#92;116&#92;141&#92;116 equals &#92;116&#92;141&#92;116, not that the 32bit or 64bit binary patterns which are NaN in IEEE floating point all equal each other. If you use XML in your programming domain, however, for the XML floating point to sort differently from the binary floating point, is usually undesirable.</p>]]></content:encoded>
	</item>
</channel>
</rss>
