<?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: Using Linq To Tell if the Elements of an IEnumerable Are Distinct</title>
	<atom:link href="http://gen5.info/q/2009/02/13/using-linq-to-tell-if-the-elements-of-an-ienumerable-are-distinct/feed/" rel="self" type="application/rss+xml" />
	<link>http://gen5.info/q/2009/02/13/using-linq-to-tell-if-the-elements-of-an-ienumerable-are-distinct/</link>
	<description>Towards Intelligent Systems</description>
	<lastBuildDate>Tue, 23 Jun 2009 19:10:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
	<item>
		<title>By: Emre Aydinceren</title>
		<link>http://gen5.info/q/2009/02/13/using-linq-to-tell-if-the-elements-of-an-ienumerable-are-distinct/comment-page-1/#comment-4365</link>
		<dc:creator>Emre Aydinceren</dc:creator>
		<pubDate>Sat, 14 Feb 2009 06:21:00 +0000</pubDate>
		<guid isPermaLink="false">http://gen5.info/q/?p=213#comment-4365</guid>
		<description>I suspect my algorithm below (Order + Iterate + Compare) could be little bit more efficient than above algorithm ( Distinct + Count + Count + Count).. Let me know if you can test it.



static bool IsDistinct(IEnumerable input)  
        {
            var ordered = input.OrderBy(item=&gt;item);

            var enumerator =ordered.GetEnumerator();

            if(enumerator.MoveNext()==false) return true;
            
            T previous=enumerator.Current;

            while(enumerator.MoveNext())
            {
                T current = enumerator.Current;
                if(previous.Equals(current)) return false;
                previous = current;
            }

            return true;
                
        }</description>
		<content:encoded><![CDATA[<p>I suspect my algorithm below (Order + Iterate + Compare) could be little bit more efficient than above algorithm ( Distinct + Count + Count + Count).. Let me know if you can test it.</p>
<p>static bool IsDistinct(IEnumerable input)<br />
        {<br />
            var ordered = input.OrderBy(item=&gt;item);</p>
<p>            var enumerator =ordered.GetEnumerator();</p>
<p>            if(enumerator.MoveNext()==false) return true;</p>
<p>            T previous=enumerator.Current;</p>
<p>            while(enumerator.MoveNext())<br />
            {<br />
                T current = enumerator.Current;<br />
                if(previous.Equals(current)) return false;<br />
                previous = current;<br />
            }</p>
<p>            return true;</p>
<p>        }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

