Comments on: Using Linq To Tell if the Elements of an IEnumerable Are Distinct http://gen5.info/q/2009/02/13/using-linq-to-tell-if-the-elements-of-an-ienumerable-are-distinct/ Towards Intelligent Systems Wed, 11 Jul 2012 12:59:08 +0000 hourly 1 http://wordpress.org/?v=3.0.3 By: Emre Aydinceren http://gen5.info/q/2009/02/13/using-linq-to-tell-if-the-elements-of-an-ienumerable-are-distinct/comment-page-1/#comment-4365 Emre Aydinceren Sat, 14 Feb 2009 06:21:00 +0000 http://gen5.info/q/?p=213#comment-4365 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=>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; } 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=>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;

}

]]>

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /hosting/sites/gen5.info/htdocs/q/wp-includes/class-snoopy.php on line 1148

Warning: fsockopen(): unable to connect to :80 (php_network_getaddresses: getaddrinfo failed: No address associated with hostname) in /hosting/sites/gen5.info/htdocs/q/wp-includes/class-snoopy.php on line 1148