<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Immutability in C# Part Four: An Immutable Queue</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx</link><description>An immutable queue is a bit trickier than an immutable stack, but we’re tough, we can handle it. 
 First off, the interface is straightforward; enqueuing or dequeuing results in a new queue: 
 public interface IQueue&amp;lt;T&amp;gt; : IEnumerable&amp;lt;T&amp;gt;</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Immutability in C# Part Four: An Immutable Queue</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx#10353329</link><pubDate>Wed, 26 Sep 2012 08:47:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10353329</guid><dc:creator>yy17yy</dc:creator><description>&lt;p&gt;i don&amp;#39;t think this is &amp;nbsp;O(1).&lt;/p&gt;
&lt;p&gt;assume q=1,1,1,1,1,1,...................1,1,1(10000total), then for(int i=0;i&amp;lt;10000;++i){q.enqueue(1).dequeue();}&lt;/p&gt;
&lt;p&gt;O(n)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10353329" width="1" height="1"&gt;</description></item><item><title>re: Immutability in C# Part Four: An Immutable Queue</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx#10314396</link><pubDate>Sun, 03 Jun 2012 17:10:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10314396</guid><dc:creator>Johan De Jong</dc:creator><description>&lt;p&gt;Eric &lt;/p&gt;
&lt;p&gt;Since the backward Queue doesn&amp;#39;t change, in dequeue operations, when we have say forward queue {1,2,3}, backward queue {4,3,2,1} after enqueue of 4, the dequeues would be {2,3} and {4,3,2,1} , then {3} and {4,3,2,1} and finally {} and {4,3,2,1} at which point we reverse the backward {1,2,3,4} and {} would be the state. Now when you dequeue you will get 1 instead of 4? &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10314396" width="1" height="1"&gt;</description></item><item><title>re: Immutability in C# Part Four: An Immutable Queue</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx#7855178</link><pubDate>Sat, 23 Feb 2008 09:34:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7855178</guid><dc:creator>Farhan Ali</dc:creator><description>&lt;p&gt;i know there is some mistake in making student data using linklist please solve this problem .&lt;/p&gt;
&lt;p&gt;////////////////////////////////////////////////&lt;/p&gt;
&lt;p&gt;using System;&lt;/p&gt;
&lt;p&gt;namespace ConsoleApplication10&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	/// Summary description for Class1.&lt;/p&gt;
&lt;p&gt;	class Class1&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		static void newdata()&lt;/p&gt;
&lt;p&gt;		{&lt;/p&gt;
&lt;p&gt;		 Console.WriteLine(&amp;quot;Successfull&amp;quot;);&lt;/p&gt;
&lt;p&gt;		 Console.ReadLine();&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;		static void display()&lt;/p&gt;
&lt;p&gt;		{&lt;/p&gt;
&lt;p&gt;		 Console.WriteLine(&amp;quot;There is nothing to Display.&amp;quot;);&lt;/p&gt;
&lt;p&gt;		 Console.ReadLine();&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;		//static void e_exit()&lt;/p&gt;
&lt;p&gt;		//{&lt;/p&gt;
&lt;p&gt;	//	}&lt;/p&gt;
&lt;p&gt;		[STAThread]&lt;/p&gt;
&lt;p&gt;		static void Main(string[] args)&lt;/p&gt;
&lt;p&gt;		{&lt;/p&gt;
&lt;p&gt;			string input;&lt;/p&gt;
&lt;p&gt;			Console.WriteLine (&amp;quot;Student Record&amp;quot;);&lt;/p&gt;
&lt;p&gt;			Console.WriteLine (&amp;quot;==============&amp;quot;);&lt;/p&gt;
&lt;p&gt;			Console.WriteLine (&amp;quot;a- Enter Data .&amp;quot; );&lt;/p&gt;
&lt;p&gt;			Console.WriteLine (&amp;quot;b- Display Data .&amp;quot; );&lt;/p&gt;
&lt;p&gt;			Console.WriteLine (&amp;quot;c- Exit.&amp;quot; );&lt;/p&gt;
&lt;p&gt;			input = Console.ReadLine();&lt;/p&gt;
&lt;p&gt;			switch(input)&lt;/p&gt;
&lt;p&gt;			{&lt;/p&gt;
&lt;p&gt;				case &amp;quot;a&amp;quot; : newdata();break;&lt;/p&gt;
&lt;p&gt;				case &amp;quot;b&amp;quot; : display();break;&lt;/p&gt;
&lt;p&gt;		//		case c : e_exit();&lt;/p&gt;
&lt;p&gt;			} &lt;/p&gt;
&lt;p&gt;			main();&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp; &amp;nbsp;Console.ReadLine();&lt;/p&gt;
&lt;p&gt;		}	&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7855178" width="1" height="1"&gt;</description></item><item><title>re: Immutability in C# Part Four: An Immutable Queue</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx#7198892</link><pubDate>Tue, 22 Jan 2008 17:56:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7198892</guid><dc:creator>Eric Lippert</dc:creator><description>&lt;p&gt;There are three possible cases:&lt;/p&gt;
&lt;p&gt;1) Singly linked list with links pointing back to front. &amp;nbsp;How are you going to efficiently &amp;quot;back up&amp;quot; the front pointer on dequeue?&lt;/p&gt;
&lt;p&gt;2) Singly linked list with links pointing front to back. How are you going to enqueue on the back pointer without mutating the current back link? &amp;nbsp;That link is immutable.&lt;/p&gt;
&lt;p&gt;3) Doubly linked list -- same problem as #2; you have to mutate state.&lt;/p&gt;
&lt;p&gt;Linked lists make great mutable queues. The goal of this series is to describe how to make immutable data structures.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7198892" width="1" height="1"&gt;</description></item><item><title>re: Immutability in C# Part Four: An Immutable Queue</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx#7196404</link><pubDate>Tue, 22 Jan 2008 12:58:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7196404</guid><dc:creator>D</dc:creator><description>&lt;p&gt;can someone explain why you wouldn't use a linked list with a front pointer to the next item to be dequeued and a back pointer to the last item queued?&lt;/p&gt;
&lt;p&gt;D&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7196404" width="1" height="1"&gt;</description></item><item><title>Immutability in C#</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx#7153112</link><pubDate>Sat, 19 Jan 2008 00:04:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7153112</guid><dc:creator>&lt;a href="http://weblogs.asp.net/bleroy"&gt;Tales from the Evil Empire&lt;/a&gt;</dc:creator><description>&lt;p&gt;For some reason, there's been a lot of buzz lately around immutability in C#. If you're interested in&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7153112" width="1" height="1"&gt;</description></item><item><title>re: Immutability in C# Part Four: An Immutable Queue</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx#6924018</link><pubDate>Mon, 31 Dec 2007 23:54:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6924018</guid><dc:creator>phreno</dc:creator><description>&lt;p&gt;I got thinking about immutability when I was trying to use Enums to create lists of things the IDE recognized. &amp;nbsp;As you know, &lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; public Enum fruitType &lt;/p&gt;
&lt;p&gt; &amp;nbsp; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;Apple,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;Orange,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;Pear &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;This is so much better than creating lists of things that the IDE doesn't recognize, i.e. Hashtable dictionaries. &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; public Hashtable fruitTypeHT = new Hashtable ();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; fruitTypeHT[&amp;quot;Apple&amp;quot;] = null;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; fruitTypeHT[&amp;quot;Orange&amp;quot;] = null;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; fruitTypeHT[&amp;quot;Pear&amp;quot;] = null;&lt;/p&gt;
&lt;p&gt;In the case of the Enumerated list, if you wish to change Pear to AsianPear it is simple to use the refactoring to rename all instances of Pear to AsianPear. &amp;nbsp;There is no such help for the Hashtable version, plus, it is possible to still modify the hashtable dictionary contents during run-time.&lt;/p&gt;
&lt;p&gt;It would be fantastic if we could have &amp;quot;popsicle&amp;quot; Enums then we could fill them from the database during program startup, yet still refer to concrete items in the Enum list in the code. &amp;nbsp;I know this may seem like wanting to have your cake and eat it too; maybe so. &amp;nbsp;But this is the basic difficulty with working with meta-data that is held in database tables. &amp;nbsp; Your code has to refer to specific items of meta-data, but you want a way to easily find or change all specific instances referenced. &amp;nbsp;This would be a great problem to solve, and I am convinced immutability will be a key part of the solution.&lt;/p&gt;
&lt;p&gt;One thing I tried to my hand at was creating an Immutable Hashtable and an Immutable ArrayList. &amp;nbsp;They are wrappers for standard Hashtables and ArrayLists, but there is a makeReadOnly () method in each that freezes the list from that point on. &amp;nbsp;I use this to handle some forms of meta-data from the database, where I don't want my program to ever attempt to change or add items to the list pulled from the DB.&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.codeproject.com/KB/cs/ImmutableHashtable.aspx"&gt;http://www.codeproject.com/KB/cs/ImmutableHashtable.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.codeproject.com/KB/cs/ImmutableArrayList.aspx"&gt;http://www.codeproject.com/KB/cs/ImmutableArrayList.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;What do we have to do to get MS to beef up Enums? &amp;nbsp;I'm already standing on my head!!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6924018" width="1" height="1"&gt;</description></item><item><title>re: Immutability in C# Part Four: An Immutable Queue</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx#6878793</link><pubDate>Thu, 27 Dec 2007 20:20:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6878793</guid><dc:creator>Sebastian Sylvan</dc:creator><description>&lt;p&gt;Eric,&lt;/p&gt;
&lt;p&gt;Two features that would make this sort of thing easier would be case classes a la Scala, and pattern matching. That way you could write Haskell style algebraic data types easily without all that boiler plate.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6878793" width="1" height="1"&gt;</description></item><item><title>re: Immutability in C# Part Four: An Immutable Queue</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx#6868830</link><pubDate>Wed, 26 Dec 2007 14:21:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6868830</guid><dc:creator>Serge Sitnikov</dc:creator><description>&lt;p&gt;There is a little mess with immutable and lock-free structures in comments. It is a different things. Immutable structures are thread safe utilizing the &amp;quot;don't worry about it&amp;quot; principle, but they don't provide the data coherency. Lock-free structures are thread safe by the same mean and also coherent.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6868830" width="1" height="1"&gt;</description></item><item><title>re: Immutability in C# Part Four: An Immutable Queue</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/12/10/immutability-in-c-part-four-an-immutable-queue.aspx#6854399</link><pubDate>Mon, 24 Dec 2007 21:36:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6854399</guid><dc:creator>Eric Lippert</dc:creator><description>&lt;p&gt;No, the problem is that you are narrowly defining what you mean by &amp;quot;reliable in a mulithreaded environment&amp;quot;. &amp;nbsp;You are defining 'reliable' to mean 'two threads can enqueue &amp;quot;the same&amp;quot; queue and both enqueued items are present in the resulting queue. &amp;nbsp;This is a very &amp;quot;procedural programming&amp;quot; way to think about thread safety -- thread safety is PRESERVATION OF ALL SIDE EFFECTS.&lt;/p&gt;
&lt;p&gt;If that's the kind of reliability you want then you should probably be using a mutable threadsafe queue! If you try to use an immutable queue for this purpose then essentially you will have to synchronize access not to the queue -- the queue is threadsafe -- but to the variable which contains the &amp;quot;canonical&amp;quot; version of the queue.&lt;/p&gt;
&lt;p&gt;Immutable queues provide a _different_ kind of reliability, namely &amp;quot;two threads can enqueue the same queue at the same time, and the result on each thread is NOT polluted by the result on the other.&amp;quot; &amp;nbsp;This is a very functional programming way of thinking about thread safety -- thread safety is IMMUNITY FROM SIDE EFFECTS. Enqueueing X onto queue Q1 should result in the queue which is Q1 plus X, always, independent of any nonsense happening to Q1 on another thread.&lt;/p&gt;
&lt;p&gt;Once you embrace a world where side effects are to be eliminated, not preserved, things get much easier to reason about.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6854399" width="1" height="1"&gt;</description></item></channel></rss>