<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OXT blog &#187; C#</title>
	<atom:link href="http://blog.o-x-t.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.o-x-t.com</link>
	<description>"People say nothing is impossible, but I do nothing every day." - Whinnie The Pooh</description>
	<lastBuildDate>Wed, 25 Aug 2010 19:18:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Hierarchical clustering using C++</title>
		<link>http://blog.o-x-t.com/2009/01/23/hierarchical_clustering/</link>
		<comments>http://blog.o-x-t.com/2009/01/23/hierarchical_clustering/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 12:46:19 +0000</pubDate>
		<dc:creator>Atuk</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Hierarchical clustering]]></category>
		<category><![CDATA[STL]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/?p=155</guid>
		<description><![CDATA[Our aim is to implement hierarchical clustering algorithm with O(N*N*log(N)) complexity using STL. The idea of hierarchical clustering is merging two nearest clusters on every step starting from N one-element clusters. To find two nearest clusters on step K we need (N-K+1)x(N-K+1) matrix of distances between current clusters. We need, in worst case, N times [...]]]></description>
			<content:encoded><![CDATA[<p>Our aim is to implement hierarchical clustering algorithm with O(N*N*log(N)) complexity using STL.</p>
<p>The idea of hierarchical clustering is merging two nearest clusters on every step starting from N one-element clusters. To find two nearest clusters on step K we need (N-K+1)x(N-K+1) matrix of distances between current clusters. We need, in worst case, N times of updating and finding minimum in sequence of NxN, (N-1)x(N-1), (N-2)x(N-2), &#8230;, 1&#215;1 matrix.  So, in usual realization of HC algorithm it should cost you O(N*N*N) operations.</p>
<p>To improve algorithm complexity up to O(N*N*log(N)) we can use vector V of similar to priority queues structures. V[i] should consist of sorted by distance points P(i,j) where distance is distance between clusters i and j. Our similar to priority queues data structure should support: ability to extract minimal element with complexity O(1), ability to delete element with complexity O(log(n)), and ability to add and element with complexity O(log(n)).</p>
<p>Standard STL priority_queue allows us to extract minimum and add element with required time, but it has no ability to find quickly an element, so we can&#8217;t delete elements with complexity O(log(n)). I propose to use set or multiset STL structure instead. Set and multiset uses &#8220;red-black tree&#8221; data structure with O(log(n)) complexity of deletion and insertion. Also, in STL sets all elements stored in sorted order and we can easily access to minimum (maximum) element [using standard begin() or end() methods].</p>
<p>In my realization I used following structure to store distances and cluster&#8217;s indexes:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">struct</span> distances
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">double</span> dist<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> index<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Also I defined appropriate comparing operator so that elements in my set always sorted in right order.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">struct</span> Cmp<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">bool</span> operator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> distances d1, <span style="color: #0000ff;">const</span> distances d2<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>d1.<span style="color: #007788;">dist</span> <span style="color: #000080;">==</span> d2.<span style="color: #007788;">dist</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">return</span> d1.<span style="color: #007788;">index</span> <span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span> d2.<span style="color: #007788;">index</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0000ff;">return</span> d1.<span style="color: #007788;">dist</span> <span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span> d2.<span style="color: #007788;">dist</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Then declaration of our vector of sets should look like this one:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span> P<span style="color: #008080;">;</span></pre></div></div>

<p>Here is source codes with sample input file and some comments:</p>
<p><a href="http://blog.o-x-t.com/wp-content/uploads/2009/01/sources.zip">sources.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2009/01/23/hierarchical_clustering/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Problems with SSE2 in OpenCV</title>
		<link>http://blog.o-x-t.com/2009/01/06/problems-with-sse2-in-opencv/</link>
		<comments>http://blog.o-x-t.com/2009/01/06/problems-with-sse2-in-opencv/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 05:32:53 +0000</pubDate>
		<dc:creator>Atuk</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[SSE2]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/?p=141</guid>
		<description><![CDATA[When I tried to use some methods from OpenCV library (for example CvResize()) in my MS Visual Studio 2005 project I encountered with errors in cxtypes.h header file near #if CV_SSE2 __m128d t = _mm_load_sd&#40; &#38;value &#41;; int i = _mm_cvtsd_si32&#40;t&#41;; return i - _mm_movemask_pd&#40;_mm_cmplt_sd&#40;t,_mm_cvtsi32_sd&#40;t,i&#41;&#41;&#41;; #else .... These errors were related with SSE2. The problem [...]]]></description>
			<content:encoded><![CDATA[<p>When I tried to use some methods from OpenCV library (for example CvResize()) in my MS Visual Studio 2005 project I encountered with errors in cxtypes.h header file near</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#if CV_SSE2</span>
__m128d t <span style="color: #000080;">=</span> _mm_load_sd<span style="color: #008000;">&#40;</span> <span style="color: #000040;">&amp;</span>value <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> _mm_cvtsd_si32<span style="color: #008000;">&#40;</span>t<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">return</span> i <span style="color: #000040;">-</span> _mm_movemask_pd<span style="color: #008000;">&#40;</span>_mm_cmplt_sd<span style="color: #008000;">&#40;</span>t,_mm_cvtsi32_sd<span style="color: #008000;">&#40;</span>t,i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #339900;">#else</span>
....</pre></div></div>

<p>These errors were related with SSE2. The problem is that my AMD Sempron 2200+ family 6 (x86 family 6 model 8 ) processor do not support SSE2 instructions. SSE &#8211; Streaming SIMD Extensions 2 are extends on MMX instructions to operate on special registers to increase computational speed in some cases.</p>
<p>To fix these problems you need to set CV_SSE2 variable to 0 in cxcore&#8217;s cxtypes.h (near 65 line).<br />
For example like here:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//  #if defined WIN32 &amp;amp;&amp;amp; (!defined WIN64 || defined EM64T) &amp;&amp; </span>
<span style="color: #666666;">//      (_MSC_VER &gt;= 1400 || defined CV_ICC) </span>
<span style="color: #666666;">//      || (defined __SSE2__ &amp;&amp; defined __GNUC__ &amp;&amp; __GNUC__ &gt;= 4)</span>
<span style="color: #666666;">//    #include </span>
<span style="color: #666666;">//    #define CV_SSE2 1</span>
<span style="color: #666666;">//  #else</span>
    <span style="color: #339900;">#define CV_SSE2 0</span>
<span style="color: #666666;">//  #endif</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2009/01/06/problems-with-sse2-in-opencv/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>XML serialization for Dictionary generic</title>
		<link>http://blog.o-x-t.com/2007/07/24/xml-serialization-for-dictionary-generic/</link>
		<comments>http://blog.o-x-t.com/2007/07/24/xml-serialization-for-dictionary-generic/#comments</comments>
		<pubDate>Tue, 24 Jul 2007 13:15:32 +0000</pubDate>
		<dc:creator>masm</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Generics]]></category>
		<category><![CDATA[Serialization]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/2007/07/24/xml-serialization-for-dictionary-generic/</guid>
		<description><![CDATA[For some reasons Microsoft made their generic Dictionary&#60;TKey, TValue&#62; class not XML-serializable. But making your own Dictionary that supports XML serialization is very simple. All you have to do is to write an implementation of IXmlSerializable interface. namespace OXT.Utils &#123; &#91;XmlRoot&#40;&#34;dictionary&#34;&#41;&#93; public class SerializableDictionary&#60;TKey, TValue&#62;; : Dictionary&#60;TKey, TValue&#62;, IXmlSerializable &#123; #region IXmlSerializable Members &#160; public [...]]]></description>
			<content:encoded><![CDATA[<p>For some reasons Microsoft made their generic Dictionary&lt;TKey, TValue&gt; class not XML-serializable. But making your own Dictionary that supports XML serialization is very simple. All you have to do is to write an implementation of IXmlSerializable interface.<br />
<span id="more-7"></span></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> OXT.<span style="color: #0000FF;">Utils</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#91;</span>XmlRoot<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;dictionary&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> SerializableDictionary<span style="color: #008000;">&lt;</span>TKey, TValue<span style="color: #008000;">&gt;;</span> <span style="color: #008000;">:</span> Dictionary<span style="color: #008000;">&lt;</span>TKey, TValue<span style="color: #008000;">&gt;</span>, IXmlSerializable
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080;">#region IXmlSerializable Members</span>
&nbsp;
		<span style="color: #0600FF;">public</span> XmlSchema GetSchema<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> ReadXml<span style="color: #000000;">&#40;</span>XmlReader reader<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			XmlSerializer keySerializer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlSerializer<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>TKey<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			XmlSerializer valueSerializer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlSerializer<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>TValue<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// element is empty</span>
			<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>reader.<span style="color: #0000FF;">IsEmptyElement</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				reader.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				return<span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// reading initial element</span>
			reader.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>reader.<span style="color: #0000FF;">NodeType</span> <span style="color: #008000;">!=</span> XmlNodeType.<span style="color: #0000FF;">EndElement</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				reader.<span style="color: #0000FF;">ReadStartElement</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;item&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
				reader.<span style="color: #0000FF;">ReadStartElement</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;key&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				TKey key <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>TKey<span style="color: #000000;">&#41;</span>keySerializer.<span style="color: #0000FF;">Deserialize</span><span style="color: #000000;">&#40;</span>reader<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				reader.<span style="color: #0000FF;">ReadEndElement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
				reader.<span style="color: #0000FF;">ReadStartElement</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;value&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				TValue value <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>TValue<span style="color: #000000;">&#41;</span>valueSerializer.<span style="color: #0000FF;">Deserialize</span><span style="color: #000000;">&#40;</span>reader<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				reader.<span style="color: #0000FF;">ReadEndElement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
				Add<span style="color: #000000;">&#40;</span>key, value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
				reader.<span style="color: #0000FF;">ReadEndElement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				reader.<span style="color: #0000FF;">MoveToContent</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			reader.<span style="color: #0000FF;">ReadEndElement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> WriteXml<span style="color: #000000;">&#40;</span>XmlWriter writer<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			XmlSerializer keySerializer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlSerializer<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>TKey<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			XmlSerializer valueSerializer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlSerializer<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>TValue<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>TKey key <span style="color: #0600FF;">in</span> Keys<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				writer.<span style="color: #0000FF;">WriteStartElement</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;item&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
				writer.<span style="color: #0000FF;">WriteStartElement</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;key&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				keySerializer.<span style="color: #0000FF;">Serialize</span><span style="color: #000000;">&#40;</span>writer, key<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				writer.<span style="color: #0000FF;">WriteEndElement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
				writer.<span style="color: #0000FF;">WriteStartElement</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;value&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				valueSerializer.<span style="color: #0000FF;">Serialize</span><span style="color: #000000;">&#40;</span>writer, <span style="color: #0600FF;">this</span><span style="color: #000000;">&#91;</span>key<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				writer.<span style="color: #0000FF;">WriteEndElement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
				writer.<span style="color: #0000FF;">WriteEndElement</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #008080;">#endregion</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2007/07/24/xml-serialization-for-dictionary-generic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generic Pair .NET class</title>
		<link>http://blog.o-x-t.com/2007/07/16/generic-pair-net-class/</link>
		<comments>http://blog.o-x-t.com/2007/07/16/generic-pair-net-class/#comments</comments>
		<pubDate>Mon, 16 Jul 2007 14:04:32 +0000</pubDate>
		<dc:creator>masm</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Generics]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/2007/07/16/generic-pair-net-class/</guid>
		<description><![CDATA[If you ever worked with C++ STL library you might remember pair template, which sometimes was very useful. .NET Framework has similar generic KeyValuePair&#60;TKey, TValue&#62;. But as it is designed to work with Dictionary class KeyValuePair has one sufficient constraint: it does not have public setters for Key and Value properties. So I wrote my [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever worked with C++ STL library you might remember <strong>pair</strong> template, which sometimes was very useful. .NET Framework has similar generic <strong>KeyValuePair&lt;TKey, TValue&gt;</strong>. But as it is designed to work with Dictionary class <strong>KeyValuePair</strong> has one sufficient constraint: it does not have public setters for <strong>Key</strong> and <strong>Value</strong> properties.</p>
<p>So I wrote my own generic <strong>Pair</strong> class and extended it with some useful static routines.<br />
<span id="more-6"></span></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> OXT.<span style="color: #0000FF;">Utils</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#91;</span>Serializable<span style="color: #000000;">&#93;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">public</span> Pair<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> Pair<span style="color: #000000;">&#40;</span>TFirst first, TSecond second<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">first</span> <span style="color: #008000;">=</span> first<span style="color: #008000;">;</span>
			<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">second</span> <span style="color: #008000;">=</span> second<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">private</span> TFirst first<span style="color: #008000;">;</span>
		<span style="color: #0600FF;">public</span> TFirst First
		<span style="color: #000000;">&#123;</span>
			get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> first<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
			set <span style="color: #000000;">&#123;</span> first <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">private</span> TSecond second<span style="color: #008000;">;</span>
		<span style="color: #0600FF;">public</span> TSecond Second
		<span style="color: #000000;">&#123;</span>
			get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> second<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
			set <span style="color: #000000;">&#123;</span> second <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> Equals<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> obj<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> <span style="color: #008000;">==</span> obj<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
			Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;</span> pair <span style="color: #008000;">=</span> obj <span style="color: #0600FF;">as</span> Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;;</span>
			<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>pair <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">return</span> false<span style="color: #008000;">;</span>
			<span style="color: #0600FF;">return</span> Equals<span style="color: #000000;">&#40;</span>first, pair.<span style="color: #0000FF;">first</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> Equals<span style="color: #000000;">&#40;</span>second, pair.<span style="color: #0000FF;">second</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">int</span> GetHashCode<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>first <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">?</span> first.<span style="color: #0000FF;">GetHashCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">29</span><span style="color: #008000;">*</span><span style="color: #000000;">&#40;</span>second <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">?</span> second.<span style="color: #0000FF;">GetHashCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> List<span style="color: #008000;">&lt;</span>Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;&gt;</span> Dictionary2List<span style="color: #000000;">&#40;</span>IDictionary<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;</span> dictionary<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			List<span style="color: #008000;">&lt;</span>Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;&gt;</span> result <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>dictionary <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>KeyValuePair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;</span> pair <span style="color: #0600FF;">in</span> dictionary<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					result.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>pair.<span style="color: #0000FF;">Key</span>, pair.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0600FF;">return</span> result<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> Dictionary<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;</span> List2Dictionary<span style="color: #000000;">&#40;</span>IList<span style="color: #008000;">&lt;</span>Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;&gt;</span> list<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			Dictionary<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;</span> result <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>list <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;</span> pair <span style="color: #0600FF;">in</span> list<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					result.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>pair.<span style="color: #0000FF;">First</span>, pair.<span style="color: #0000FF;">Second</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0600FF;">return</span> result<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> Dictionary<span style="color: #008000;">&lt;</span>TFirst, List<span style="color: #008000;">&lt;</span>TSecond<span style="color: #008000;">&gt;&gt;</span> List2TwoDimentionalDictionary<span style="color: #000000;">&#40;</span>IList<span style="color: #008000;">&lt;</span>Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;&gt;</span> list<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			Dictionary<span style="color: #008000;">&lt;</span>TFirst, List<span style="color: #008000;">&lt;</span>TSecond<span style="color: #008000;">&gt;&gt;</span> result <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span>TFirst, List<span style="color: #008000;">&lt;</span>TSecond<span style="color: #008000;">&gt;&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>list <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>Pair<span style="color: #008000;">&lt;</span>TFirst, TSecond<span style="color: #008000;">&gt;</span> pair <span style="color: #0600FF;">in</span> list<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					List<span style="color: #008000;">&lt;</span>TSecond<span style="color: #008000;">&gt;</span> dimentionList<span style="color: #008000;">;</span>
					<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>result.<span style="color: #0000FF;">TryGetValue</span><span style="color: #000000;">&#40;</span>pair.<span style="color: #0000FF;">First</span>, <span style="color: #0600FF;">out</span> dimentionList<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
					<span style="color: #000000;">&#123;</span>
						dimentionList <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>TSecond<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
						result<span style="color: #000000;">&#91;</span>pair.<span style="color: #0000FF;">First</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> dimentionList<span style="color: #008000;">;</span>
					<span style="color: #000000;">&#125;</span>
&nbsp;
					dimentionList.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>pair.<span style="color: #0000FF;">Second</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0600FF;">return</span> result<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2007/07/16/generic-pair-net-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
