lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [Lucene.Net] svn commit: r1096727 - in /incubator/lucene.net/branches/Lucene.Net_2_9_4g: src/core/ src/core/Index/ src/core/Search/ src/core/Util/Cache/ test/core/ test/core/Util/Cache/
Date Tue, 26 Apr 2011 11:13:27 GMT
Author: digy
Date: Tue Apr 26 11:13:26 2011
New Revision: 1096727

URL: http://svn.apache.org/viewvc?rev=1096727&view=rev
Log:
[LUCENENET-412] SimpleLRUCache

Modified:
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/IndexWriter.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/TermInfosReader.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Search/FilterManager.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/SupportClass.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/Cache.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/SimpleLRUCache.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/SimpleMapCache.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/TestSupportClass.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Util/Cache/TestSimpleLRUCache.cs

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/IndexWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/IndexWriter.cs?rev=1096727&r1=1096726&r2=1096727&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/IndexWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/IndexWriter.cs Tue Apr
26 11:13:26 2011
@@ -322,7 +322,7 @@ namespace Lucene.Net.Index
 		
 		// Holds all SegmentInfo instances currently involved in
 		// merges
-        private System.Collections.Hashtable mergingSegments = new System.Collections.Hashtable();
+        private SupportClass.Set<SegmentInfo> mergingSegments = new SupportClass.Set<SegmentInfo>();
 		
 		private MergePolicy mergePolicy;
 		private MergeScheduler mergeScheduler = new ConcurrentMergeScheduler();
@@ -490,8 +490,8 @@ namespace Lucene.Net.Index
 				}
 				
 			}
-			
-			private System.Collections.IDictionary readerMap = new System.Collections.Hashtable();
+
+            private SupportClass.Dictionary<SegmentInfo, SegmentReader> readerMap =
new SupportClass.Dictionary<SegmentInfo, SegmentReader>();
 			
 			/// <summary>Forcefully clear changes for the specifed segments,
 			/// and remove from the pool.   This is called on succesful merge. 
@@ -502,12 +502,10 @@ namespace Lucene.Net.Index
 				{
 					if (infos == null)
 					{
-                        System.Collections.IEnumerator iter = new System.Collections.Hashtable(readerMap).GetEnumerator();
-						while (iter.MoveNext())
-						{
-							System.Collections.DictionaryEntry ent = (System.Collections.DictionaryEntry) iter.Current;
-							((SegmentReader) ent.Value).hasChanges = false;
-						}
+                        foreach (SegmentReader sr in readerMap.Values)
+                        {
+                            sr.hasChanges = false;
+                        }
 					}
 					else
 					{
@@ -515,9 +513,9 @@ namespace Lucene.Net.Index
 						for (int i = 0; i < numSegments; i++)
 						{
 							SegmentInfo info = infos.Info(i);
-							if (readerMap.Contains(info))
+							if (readerMap.ContainsKey(info))
 							{
-								((SegmentReader) readerMap[info]).hasChanges = false;
+								readerMap[info].hasChanges = false;
 							}
 						}
 					}
@@ -574,7 +572,7 @@ namespace Lucene.Net.Index
 				lock (this)
 				{
 					
-					bool pooled = readerMap.Contains(sr.GetSegmentInfo());
+					bool pooled = readerMap.ContainsKey(sr.GetSegmentInfo());
 
                     System.Diagnostics.Debug.Assert(!pooled || readerMap[sr.GetSegmentInfo()]
== sr);
 
@@ -624,30 +622,27 @@ namespace Lucene.Net.Index
 			{
 				lock (this)
 				{
-                    System.Collections.IEnumerator iter = new System.Collections.Hashtable(readerMap).GetEnumerator();
-					while (iter.MoveNext())
-					{
-						System.Collections.DictionaryEntry ent = (System.Collections.DictionaryEntry) iter.Current;
-						
-						SegmentReader sr = (SegmentReader) ent.Value;
-						if (sr.hasChanges)
-						{
-							System.Diagnostics.Debug.Assert(InfoIsLive(sr.GetSegmentInfo()));
-							sr.DoCommit(null);
+                    foreach (KeyValuePair<SegmentInfo, SegmentReader> ent in new SupportClass.Dictionary<SegmentInfo,
SegmentReader>(readerMap))
+                    {
+                        SegmentReader sr = ent.Value;
+                        if (sr.hasChanges)
+                        {
+                            System.Diagnostics.Debug.Assert(InfoIsLive(sr.GetSegmentInfo()));
+                            sr.DoCommit(null);
                             // Must checkpoint w/ deleter, because this
                             // segment reader will have created new _X_N.del
                             // file.
                             enclosingInstance.deleter.Checkpoint(enclosingInstance.segmentInfos,
false);
-						}
+                        }
 
-                        readerMap.Remove(ent.Key); 
-						
-						// NOTE: it is allowed that this decRef does not
-						// actually close the SR; this can happen when a
-						// near real-time reader is kept open after the
-						// IndexWriter instance is closed
-						sr.DecRef();
-					}
+                        readerMap.Remove(ent.Key);
+
+                        // NOTE: it is allowed that this decRef does not
+                        // actually close the SR; this can happen when a
+                        // near real-time reader is kept open after the
+                        // IndexWriter instance is closed
+                        sr.DecRef();
+                    }
 				}
 			}
 			
@@ -657,22 +652,19 @@ namespace Lucene.Net.Index
 			{
 				lock (this)
 				{
-                    System.Collections.IEnumerator iter = new System.Collections.Hashtable(readerMap).GetEnumerator();
-					while (iter.MoveNext())
-					{
-						System.Collections.DictionaryEntry ent = (System.Collections.DictionaryEntry) iter.Current;
-						
-						SegmentReader sr = (SegmentReader) ent.Value;
-						if (sr.hasChanges)
-						{
-							System.Diagnostics.Debug.Assert(InfoIsLive(sr.GetSegmentInfo()));
-							sr.DoCommit(null);
+                    foreach (KeyValuePair<SegmentInfo, SegmentReader> ent in new SupportClass.Dictionary<SegmentInfo,
SegmentReader>(readerMap))
+                    {
+                        SegmentReader sr = ent.Value;
+                        if (sr.hasChanges)
+                        {
+                            System.Diagnostics.Debug.Assert(InfoIsLive(sr.GetSegmentInfo()));
+                            sr.DoCommit(null);
                             // Must checkpoint w/ deleter, because this
                             // segment reader will have created new _X_N.del
                             // file.
                             enclosingInstance.deleter.Checkpoint(enclosingInstance.segmentInfos,
false);
-						}
-					}
+                        }
+                    }
 				}
 			}
 			
@@ -738,7 +730,7 @@ namespace Lucene.Net.Index
 						readBufferSize = BufferedIndexInput.BUFFER_SIZE;
 					}
 					
-					SegmentReader sr = (SegmentReader) readerMap[info];
+					SegmentReader sr = readerMap[info];
 					if (sr == null)
 					{
 						// TODO: we may want to avoid doing this while
@@ -784,7 +776,7 @@ namespace Lucene.Net.Index
 			{
 				lock (this)
 				{
-					SegmentReader sr = (SegmentReader) readerMap[info];
+					SegmentReader sr = readerMap[info];
 					if (sr != null)
 					{
 						sr.IncRef();
@@ -5560,7 +5552,7 @@ namespace Lucene.Net.Index
                 for (int i = 0; i < count; i++)
                 {
                     SegmentInfo si = merge.segments.Info(i);
-                    mergingSegments[si] = si;
+                    mergingSegments.Add(si);
                 }
 				
 				// Merge is now registered
@@ -5745,7 +5737,7 @@ namespace Lucene.Net.Index
 				// this prevents it from getting selected for a merge
 				// after our merge is done but while we are building the
 				// CFS:
-                mergingSegments[merge.info] = merge.info;
+                mergingSegments.Add(merge.info);
 			}
 		}
 		
@@ -5966,9 +5958,7 @@ namespace Lucene.Net.Index
 			merge.readersClone = new SegmentReader[numSegments];
 			
 			bool mergeDocStores = false;
-
-            System.Collections.Hashtable dss = new System.Collections.Hashtable();
-			
+                        			
             String currentDocStoreSegment;
             lock(this) {
                 currentDocStoreSegment = docWriter.GetDocStoreSegment();
@@ -6307,7 +6297,7 @@ namespace Lucene.Net.Index
         private Dictionary<string, string> synced = new Dictionary<string, string>();
 		
 		// Files that are now being sync'd
-        private System.Collections.Hashtable syncing = new System.Collections.Hashtable();
+        private SupportClass.Set<string> syncing = new SupportClass.Set<string>();
 		
 		private bool StartSync(System.String fileName, ICollection<System.String> pending)
 		{
@@ -6317,7 +6307,7 @@ namespace Lucene.Net.Index
 				{
 					if (!syncing.Contains(fileName))
 					{
-						syncing[fileName] = fileName;
+						syncing.Add(fileName);
 						return true;
 					}
 					else
@@ -6335,7 +6325,7 @@ namespace Lucene.Net.Index
 		{
 			lock (synced)
 			{
-				System.Diagnostics.Debug.Assert(syncing.ContainsKey(fileName));
+				System.Diagnostics.Debug.Assert(syncing.Contains(fileName));
 				syncing.Remove(fileName);
 				if (success)
                     synced[fileName] = fileName;

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/TermInfosReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/TermInfosReader.cs?rev=1096727&r1=1096726&r2=1096727&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/TermInfosReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/TermInfosReader.cs Tue
Apr 26 11:13:26 2011
@@ -19,7 +19,7 @@ using System;
 
 using Directory = Lucene.Net.Store.Directory;
 using CloseableThreadLocal = Lucene.Net.Util.CloseableThreadLocal;
-using SimpleLRUCache = Lucene.Net.Util.Cache.SimpleLRUCache;
+using SimpleLRUCache = Lucene.Net.Util.Cache.SimpleLRUCache<Lucene.Net.Index.Term,Lucene.Net.Index.TermInfo>;
 
 namespace Lucene.Net.Index
 {
@@ -53,7 +53,7 @@ namespace Lucene.Net.Index
 			internal SegmentTermEnum termEnum;
 			
 			// Used for caching the least recently looked-up Terms
-			internal Lucene.Net.Util.Cache.Cache termInfoCache;
+            internal Lucene.Net.Util.Cache.Cache<Term, TermInfo> termInfoCache;
 		}
 		
 		internal TermInfosReader(Directory dir, System.String seg, FieldInfos fis, int readBufferSize,
int indexDivisor)
@@ -208,13 +208,13 @@ namespace Lucene.Net.Index
 			
 			TermInfo ti;
 			ThreadResources resources = GetThreadResources();
-			Lucene.Net.Util.Cache.Cache cache = null;
+			Lucene.Net.Util.Cache.Cache<Term,TermInfo> cache = null;
 			
 			if (useCache)
 			{
 				cache = resources.termInfoCache;
 				// check the cache first if the term was recently looked up
-				ti = (TermInfo) cache.Get(term);
+				ti = cache.Get(term);
 				if (ti != null)
 				{
 					return ti;

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Search/FilterManager.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Search/FilterManager.cs?rev=1096727&r1=1096726&r2=1096727&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Search/FilterManager.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Search/FilterManager.cs Tue Apr
26 11:13:26 2011
@@ -43,7 +43,7 @@ namespace Lucene.Net.Search
 		protected internal const long DEFAULT_CACHE_SLEEP_TIME = 1000 * 60 * 10;
 		
 		/// <summary>The cache itself </summary>
-		protected internal System.Collections.IDictionary cache;
+		protected internal IDictionary<int,FilterItem> cache;
 		/// <summary>Maximum allowed cache size </summary>
 		protected internal int cacheCleanSize;
 		/// <summary>Cache cleaning frequency </summary>
@@ -66,7 +66,7 @@ namespace Lucene.Net.Search
 		/// <summary> Sets up the FilterManager singleton.</summary>
 		protected internal FilterManager()
 		{
-			cache = new System.Collections.Hashtable();
+			cache = new SupportClass.Dictionary<int,FilterItem>();
 			cacheCleanSize = DEFAULT_CACHE_CLEAN_SIZE; // Let the cache get to 100 items
 			cleanSleepTime = DEFAULT_CACHE_SLEEP_TIME; // 10 minutes between cleanings
 			
@@ -104,16 +104,16 @@ namespace Lucene.Net.Search
 		/// </returns>
 		public virtual Filter GetFilter(Filter filter)
 		{
-			lock (cache.SyncRoot)
+			lock (cache)
 			{
 				FilterItem fi = null;
-				fi = (FilterItem) cache[(System.Int32) filter.GetHashCode()];
+				fi = cache[filter.GetHashCode()];
 				if (fi != null)
 				{
 					fi.timestamp = System.DateTime.Now.Ticks;
 					return fi.filter;
 				}
-				cache[(System.Int32) filter.GetHashCode()] = new FilterItem(this, filter);
+				cache[filter.GetHashCode()] = new FilterItem(this, filter);
 				return filter;
 			}
 		}
@@ -197,7 +197,7 @@ namespace Lucene.Net.Search
 					{
 						// empty the temporary set
 						filterItems.Clear();
-                        lock (this.manager.cache.SyncRoot)
+                        lock (this.manager.cache)
 						{
                             foreach (FilterItem item in this.manager.cache.Values)
                             {

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/SupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/SupportClass.cs?rev=1096727&r1=1096726&r2=1096727&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/SupportClass.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/SupportClass.cs Tue Apr 26 11:13:26
2011
@@ -1567,6 +1567,12 @@ public class SupportClass
             _Set.Clear();
             base.Clear();
         }
+
+        public new void Remove(T item)
+        {
+            _Set.Remove(item);
+            base.Remove(item);
+        }
     }
 
     public class Cryptography

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/Cache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/Cache.cs?rev=1096727&r1=1096726&r2=1096727&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/Cache.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/Cache.cs Tue Apr 26
11:13:26 2011
@@ -16,36 +16,37 @@
  */
 
 using System;
+using System.Collections.Generic;
 
 namespace Lucene.Net.Util.Cache
 {
 	
 	
 	/// <summary> Base class for cache implementations.</summary>
-	public abstract class Cache
+	public abstract class Cache<K,V>
 	{
 		
 		/// <summary> Simple Cache wrapper that synchronizes all
 		/// calls that access the cache. 
 		/// </summary>
-		internal class SynchronizedCache_Renamed_Class:Cache
+		internal class SynchronizedCache_Renamed_Class<K,V>:Cache<K,V>
 		{
 			internal System.Object mutex;
-			internal Cache cache;
+			internal Cache<K,V> cache;
 			
-			internal SynchronizedCache_Renamed_Class(Cache cache)
+			internal SynchronizedCache_Renamed_Class(Cache<K,V> cache)
 			{
 				this.cache = cache;
 				this.mutex = this;
 			}
-			
-			internal SynchronizedCache_Renamed_Class(Cache cache, System.Object mutex)
+
+            internal SynchronizedCache_Renamed_Class(Cache<K, V> cache, System.Object
mutex)
 			{
 				this.cache = cache;
 				this.mutex = mutex;
 			}
 			
-			public override void  Put(System.Object key, System.Object value_Renamed)
+			public override void  Put(K key, V value_Renamed)
 			{
 				lock (mutex)
 				{
@@ -53,7 +54,7 @@ namespace Lucene.Net.Util.Cache
 				}
 			}
 			
-			public override System.Object Get(System.Object key)
+			public override V Get(K key)
 			{
 				lock (mutex)
 				{
@@ -61,7 +62,7 @@ namespace Lucene.Net.Util.Cache
 				}
 			}
 			
-			public override bool ContainsKey(System.Object key)
+			public override bool ContainsKey(K key)
 			{
 				lock (mutex)
 				{
@@ -76,8 +77,8 @@ namespace Lucene.Net.Util.Cache
 					cache.Close();
 				}
 			}
-			
-			internal override Cache GetSynchronizedCache()
+
+            internal override Cache<K, V> GetSynchronizedCache()
 			{
 				return this;
 			}
@@ -87,7 +88,7 @@ namespace Lucene.Net.Util.Cache
 		/// In order to guarantee thread-safety, all access to the backed cache must
 		/// be accomplished through the returned cache.
 		/// </summary>
-		public static Cache SynchronizedCache(Cache cache)
+        public static Cache<K, V> SynchronizedCache(Cache<K, V> cache)
 		{
 			return cache.GetSynchronizedCache();
 		}
@@ -98,19 +99,19 @@ namespace Lucene.Net.Util.Cache
 		/// e. g. subclasses of {@link SynchronizedCache} or this
 		/// in case this cache is already synchronized.
 		/// </summary>
-		internal virtual Cache GetSynchronizedCache()
+        internal virtual Cache<K, V> GetSynchronizedCache()
 		{
-			return new SynchronizedCache_Renamed_Class(this);
+			return new SynchronizedCache_Renamed_Class<K,V>(this);
 		}
 		
 		/// <summary> Puts a (key, value)-pair into the cache. </summary>
-		public abstract void  Put(System.Object key, System.Object value_Renamed);
+		public abstract void  Put(K key, V value_Renamed);
 		
 		/// <summary> Returns the value for the given key. </summary>
-		public abstract System.Object Get(System.Object key);
+		public abstract V Get(K key);
 		
 		/// <summary> Returns whether the given key is in this cache. </summary>
-		public abstract bool ContainsKey(System.Object key);
+		public abstract bool ContainsKey(K key);
 		
 		/// <summary> Closes the cache.</summary>
 		public abstract void  Close();

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/SimpleLRUCache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/SimpleLRUCache.cs?rev=1096727&r1=1096726&r2=1096727&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/SimpleLRUCache.cs
(original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/SimpleLRUCache.cs
Tue Apr 26 11:13:26 2011
@@ -20,7 +20,7 @@ using System.Collections.Generic;
 
 namespace Lucene.Net.Util.Cache
 {
-    public class SimpleLRUCache : SimpleMapCache
+    public class SimpleLRUCache<K, V> : SimpleMapCache<K, V>
     {
         /// <summary>
         /// The maximum number of items to cache.
@@ -30,27 +30,27 @@ namespace Lucene.Net.Util.Cache
         /// <summary>
         /// The list to efficiently maintain the LRU state.
         /// </summary>
-        private LinkedList<ListValueEntry> list;
+        private LinkedList<ListValueEntry<K, V>> list;
 
         /// <summary>
         /// The dictionary to hash into any location in the list.
         /// </summary>
-        private Dictionary<object, LinkedListNode<ListValueEntry>> lookup;
+        private Dictionary<K, LinkedListNode<ListValueEntry<K, V>>> lookup;
 
         /// <summary>
         /// The node instance to use/re-use when adding an item to the cache.
         /// </summary>
-        private LinkedListNode<ListValueEntry> openNode;
+        private LinkedListNode<ListValueEntry<K, V>> openNode;
 
         public SimpleLRUCache(int Capacity)
         {
             this.capacity = Capacity;
-            this.list = new LinkedList<ListValueEntry>();
-            this.lookup = new Dictionary<object, LinkedListNode<ListValueEntry>>(Capacity
+ 1);
-            this.openNode = new LinkedListNode<ListValueEntry>(new ListValueEntry(null,
null));
+            this.list = new LinkedList<ListValueEntry<K, V>>();
+            this.lookup = new Dictionary<K, LinkedListNode<ListValueEntry<K, V>>>(Capacity
+ 1);
+            this.openNode = new LinkedListNode<ListValueEntry<K, V>>(new ListValueEntry<K,
V>(default(K), default(V)));
         }
 
-        public override void Put(object Key, object Value)
+        public override void Put(K Key, V Value)
         {
             if (Get(Key) == null)
             {
@@ -71,17 +71,17 @@ namespace Lucene.Net.Util.Cache
                 else
                 {
                     // still filling the cache, create a new open node for the next time
-                    this.openNode = new LinkedListNode<ListValueEntry>(new ListValueEntry(null,
null));
+                    this.openNode = new LinkedListNode<ListValueEntry<K,V>>(new
ListValueEntry<K,V>(default(K), default(V)));
                 }
             }
         }
 
-        public override object Get(object Key)
+        public override V Get(K Key)
         {
-            LinkedListNode<ListValueEntry> node = null;
+            LinkedListNode<ListValueEntry<K,V>> node = null;
             if(!this.lookup.TryGetValue(Key, out node))
             {
-                return null;
+                return default(V);
             }
             this.list.Remove(node);
             this.list.AddFirst(node);
@@ -92,12 +92,12 @@ namespace Lucene.Net.Util.Cache
         /// Container to hold the key and value to aid in removal from 
         /// the <see cref="lookup"/> dictionary when an item is removed from cache.
         /// </summary>
-        class ListValueEntry
+        class ListValueEntry<K, V>
         {
-            internal object ItemValue;
-            internal object ItemKey;
+            internal V ItemValue;
+            internal K ItemKey;
 
-            internal ListValueEntry(object key, object value)
+            internal ListValueEntry(K key, V value)
             {
                 this.ItemKey = key;
                 this.ItemValue = value;

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/SimpleMapCache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/SimpleMapCache.cs?rev=1096727&r1=1096726&r2=1096727&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/SimpleMapCache.cs
(original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/Cache/SimpleMapCache.cs
Tue Apr 26 11:13:26 2011
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.Collections.Generic;
 
 namespace Lucene.Net.Util.Cache
 {
@@ -24,25 +25,25 @@ namespace Lucene.Net.Util.Cache
 	/// This cache is not synchronized, use {@link Cache#SynchronizedCache(Cache)}
 	/// if needed.
 	/// </summary>
-	public class SimpleMapCache:Cache
+    public class SimpleMapCache<K, V> : Cache<K, V>
 	{
-		internal System.Collections.IDictionary map;
+        internal SupportClass.Dictionary<K, V> map;
 		
-		public SimpleMapCache():this(new System.Collections.Hashtable())
+		public SimpleMapCache():this(new SupportClass.Dictionary<K,V>())
 		{
 		}
-		
-		public SimpleMapCache(System.Collections.IDictionary map)
+
+        public SimpleMapCache(SupportClass.Dictionary<K, V> map)
 		{
 			this.map = map;
 		}
 		
-		public override System.Object Get(System.Object key)
+		public override V Get(K key)
 		{
 			return map[key];
 		}
 		
-		public override void  Put(System.Object key, System.Object value_Renamed)
+		public override void  Put(K key, V value_Renamed)
 		{
 			map[key] = value_Renamed;
 		}
@@ -52,34 +53,34 @@ namespace Lucene.Net.Util.Cache
 			// NOOP
 		}
 		
-		public override bool ContainsKey(System.Object key)
+		public override bool ContainsKey(K key)
 		{
-			return map.Contains(key);
+			return map.ContainsKey(key);
 		}
 		
 		/// <summary> Returns a Set containing all keys in this cache.</summary>
-		public virtual System.Collections.ICollection KeySet()
+		public virtual ICollection<K> KeySet()
 		{
 			return map.Keys;
 		}
 		
-		internal override Cache GetSynchronizedCache()
+		internal override Cache<K,V> GetSynchronizedCache()
 		{
-			return new SynchronizedSimpleMapCache(this);
+			return new SynchronizedSimpleMapCache<K,V>(this);
 		}
 		
-		private class SynchronizedSimpleMapCache:SimpleMapCache
+		private class SynchronizedSimpleMapCache<K,V>:SimpleMapCache<K,V>
 		{
 			internal System.Object mutex;
-			internal SimpleMapCache cache;
+			internal SimpleMapCache<K,V> cache;
 			
-			internal SynchronizedSimpleMapCache(SimpleMapCache cache)
+			internal SynchronizedSimpleMapCache(SimpleMapCache<K,V> cache)
 			{
 				this.cache = cache;
 				this.mutex = this;
 			}
 			
-			public override void  Put(System.Object key, System.Object value_Renamed)
+			public override void  Put(K key, V value_Renamed)
 			{
 				lock (mutex)
 				{
@@ -87,7 +88,7 @@ namespace Lucene.Net.Util.Cache
 				}
 			}
 			
-			public override System.Object Get(System.Object key)
+			public override V Get(K key)
 			{
 				lock (mutex)
 				{
@@ -95,7 +96,7 @@ namespace Lucene.Net.Util.Cache
 				}
 			}
 			
-			public override bool ContainsKey(System.Object key)
+			public override bool ContainsKey(K key)
 			{
 				lock (mutex)
 				{
@@ -111,7 +112,7 @@ namespace Lucene.Net.Util.Cache
 				}
 			}
 			
-			public override System.Collections.ICollection KeySet()
+			public override ICollection<K> KeySet()
 			{
 				lock (mutex)
 				{
@@ -119,7 +120,7 @@ namespace Lucene.Net.Util.Cache
 				}
 			}
 			
-			internal override Cache GetSynchronizedCache()
+			internal override Cache<K,V> GetSynchronizedCache()
 			{
 				return this;
 			}

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/TestSupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/TestSupportClass.cs?rev=1096727&r1=1096726&r2=1096727&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/TestSupportClass.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/TestSupportClass.cs Tue Apr
26 11:13:26 2011
@@ -864,7 +864,7 @@ namespace Lucene.Net._SupportClass
         [Test]
         public void Test()
         {
-            Lucene.Net.Util.Cache.SimpleLRUCache cache = new Lucene.Net.Util.Cache.SimpleLRUCache(3);
+            Lucene.Net.Util.Cache.SimpleLRUCache<string,string> cache = new Lucene.Net.Util.Cache.SimpleLRUCache<string,string>(3);
             cache.Put("a", "a");
             cache.Put("b", "b");
             cache.Put("c", "c");

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Util/Cache/TestSimpleLRUCache.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Util/Cache/TestSimpleLRUCache.cs?rev=1096727&r1=1096726&r2=1096727&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Util/Cache/TestSimpleLRUCache.cs
(original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Util/Cache/TestSimpleLRUCache.cs
Tue Apr 26 11:13:26 2011
@@ -34,43 +34,43 @@ namespace Lucene.Net.Util.Cache
 			int n = 100;
 			System.Object dummy = new System.Object();
 			
-			Cache cache = new SimpleLRUCache(n);
+			Cache<int,object> cache = new SimpleLRUCache<int,object>(n);
 			
 			for (int i = 0; i < n; i++)
 			{
-				cache.Put((System.Object) i, dummy);
+				cache.Put( i, dummy);
 			}
 			
 			// access every 2nd item in cache
 			for (int i = 0; i < n; i += 2)
 			{
-				Assert.IsNotNull(cache.Get((System.Object) i));
+				Assert.IsNotNull(cache.Get(i));
 			}
 			
 			// add n/2 elements to cache, the ones that weren't
 			// touched in the previous loop should now be thrown away
 			for (int i = n; i < n + (n / 2); i++)
 			{
-				cache.Put((System.Object) i, dummy);
+				cache.Put(i, dummy);
 			}
 			
 			// access every 4th item in cache
 			for (int i = 0; i < n; i += 4)
 			{
-				Assert.IsNotNull(cache.Get((System.Object) i));
+				Assert.IsNotNull(cache.Get(i));
 			}
 			
 			// add 3/4n elements to cache, the ones that weren't
 			// touched in the previous loops should now be thrown away
 			for (int i = n; i < n + (n * 3 / 4); i++)
 			{
-				cache.Put((System.Object) i, dummy);
+				cache.Put(i, dummy);
 			}
 			
 			// access every 4th item in cache
 			for (int i = 0; i < n; i += 4)
 			{
-				Assert.IsNotNull(cache.Get((System.Object) i));
+				Assert.IsNotNull(cache.Get(i));
 			}
 		}
 	}



Mime
View raw message