Time for action – creating the concurrent move-to-front list
Follow the given steps:
- Create a new class library project. Call it
TSList
. - Change the name of the class from
Class1.cs
toConcurrentMTFList.cs
. - Change the class header as follows:
public class ConcurrentMTFList<T> where T:IComparable
- Add the following variable and the constructor:
ConcurrentDictionary<T,int> _innerDS; ///<summary> ///Initializes the internal data structure. ///</summary> public ConcurrentMTFList() { _innerDS = new ConcurrentDictionary<T, int>(); }
- Add the following method to add new items to the list:
///<summary> ///Adds an item to the concurrent list. ///</summary> ///<param name="item">item to be added.</param> public void Add(T item) { _innerDS.AddOrUpdate(item, 0, (i, ...
Get .NET 4.0 Generics now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.