You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ar...@apache.org on 2009/11/12 04:13:27 UTC

svn commit: r835207 - in /incubator/lucene.net/trunk/C#/src/Lucene.Net/Util: AverageGuessMemoryModel.cs FieldCacheSanityChecker.cs MapOfSets.cs

Author: aroush
Date: Thu Nov 12 03:13:25 2009
New Revision: 835207

URL: http://svn.apache.org/viewvc?rev=835207&view=rev
Log: (empty)

Modified:
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/AverageGuessMemoryModel.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/FieldCacheSanityChecker.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/MapOfSets.cs

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/AverageGuessMemoryModel.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/AverageGuessMemoryModel.cs?rev=835207&r1=835206&r2=835207&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/AverageGuessMemoryModel.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/AverageGuessMemoryModel.cs Thu Nov 12 03:13:25 2009
@@ -39,7 +39,7 @@
 			{
 				this.enclosingInstance = enclosingInstance;
 				Add(typeof(bool), 1);
-				Add(typeof(sbyte), 1);
+				Add(typeof(byte), 1);
 				Add(typeof(char), 2);
 				Add(typeof(short), 2);
 				Add(typeof(int), 4);

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/FieldCacheSanityChecker.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/FieldCacheSanityChecker.cs?rev=835207&r1=835206&r2=835207&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/FieldCacheSanityChecker.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/FieldCacheSanityChecker.cs Thu Nov 12 03:13:25 2009
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.Collections.Generic;
 
 using IndexReader = Lucene.Net.Index.IndexReader;
 using FieldCache = Lucene.Net.Search.FieldCache;
@@ -114,13 +115,14 @@
 			//
 			// maps the (valId) identityhashCode of cache values to 
 			// sets of CacheEntry instances
-			MapOfSets valIdToItems = new MapOfSets(new System.Collections.Hashtable(17));
+			MapOfSets<int,CacheEntry> valIdToItems = new MapOfSets<int,CacheEntry>(new Dictionary<int,Dictionary<CacheEntry,CacheEntry>>(17));
 			// maps ReaderField keys to Sets of ValueIds
-			MapOfSets readerFieldToValIds = new MapOfSets(new System.Collections.Hashtable(17));
+			MapOfSets<ReaderField,int> readerFieldToValIds = new MapOfSets<ReaderField,int>(new Dictionary<ReaderField,Dictionary<int,int>>(17));
 			//
 			
 			// any keys that we know result in more then one valId
-			System.Collections.Hashtable valMismatchKeys = new System.Collections.Hashtable();
+            // TODO: This will be a HashSet<T> when we start using .NET Framework 3.5
+            Dictionary<ReaderField, ReaderField> valMismatchKeys = new Dictionary<ReaderField, ReaderField>();
 			
 			// iterate over all the cacheEntries to get the mappings we'll need
 			for (int i = 0; i < cacheEntries.Length; i++)
@@ -133,22 +135,25 @@
 				
 				ReaderField rf = new ReaderField(item.GetReaderKey(), item.GetFieldName());
 				
-				System.Int32 valId = (System.Int32) val.GetHashCode();
+				System.Int32 valId = val.GetHashCode();
 				
 				// indirect mapping, so the MapOfSet will dedup identical valIds for us
-				valIdToItems.Put((System.Object) valId, item);
-				if (1 < readerFieldToValIds.Put(rf, (System.Object) valId))
+				valIdToItems.Put(valId, item);
+				if (1 < readerFieldToValIds.Put(rf, valId))
 				{
-					SupportClass.CollectionsHelper.AddIfNotContains(valMismatchKeys, rf);
+                    if (!valMismatchKeys.ContainsKey(rf))
+                    {
+                        valMismatchKeys.Add(rf, rf);
+                    }
 				}
 			}
 			
-			System.Collections.ArrayList insanity = new System.Collections.ArrayList(valMismatchKeys.Count * 3);
+			List<Insanity> insanity = new List<Insanity>(valMismatchKeys.Count * 3);
 			
 			insanity.AddRange(CheckValueMismatch(valIdToItems, readerFieldToValIds, valMismatchKeys));
 			insanity.AddRange(CheckSubreaders(valIdToItems, readerFieldToValIds));
 			
-			return (Insanity[]) insanity.ToArray(typeof(Insanity));
+			return insanity.ToArray();
 		}
 		
 		/// <summary> Internal helper method used by check that iterates over 
@@ -158,38 +163,31 @@
 		/// </summary>
 		/// <seealso cref="InsanityType.VALUEMISMATCH">
 		/// </seealso>
-		private System.Collections.ICollection CheckValueMismatch(MapOfSets valIdToItems, MapOfSets readerFieldToValIds, System.Collections.Hashtable valMismatchKeys)
+		private List<Insanity> CheckValueMismatch(MapOfSets<int,CacheEntry> valIdToItems, MapOfSets<ReaderField,int> readerFieldToValIds, Dictionary<ReaderField,ReaderField> valMismatchKeys)
 		{
 			
-			System.Collections.IList insanity = new System.Collections.ArrayList(valMismatchKeys.Count * 3);
+			List<Insanity> insanity = new List<Insanity>(valMismatchKeys.Count * 3);
 			
 			if (!(valMismatchKeys.Count == 0))
 			{
 				// we have multiple values for some ReaderFields
 				
-				System.Collections.IDictionary rfMap = readerFieldToValIds.GetMap();
-				System.Collections.IDictionary valMap = valIdToItems.GetMap();
-				System.Collections.IEnumerator mismatchIter = valMismatchKeys.GetEnumerator();
-				while (mismatchIter.MoveNext())
-				{
-					ReaderField rf = (ReaderField) mismatchIter.Current;
-					System.Collections.ArrayList badEntries = new System.Collections.ArrayList(valMismatchKeys.Count * 2);
-					System.Collections.IEnumerator valIter = ((System.Collections.Hashtable) rfMap[rf]).GetEnumerator();
-					while (valIter.MoveNext())
-					{
-						System.Collections.IEnumerator entriesIter = ((System.Collections.Hashtable) valMap[valIter.Current]).GetEnumerator();
-						while (entriesIter.MoveNext())
-						{
-							badEntries.Add(entriesIter.Current);
-						}
-					}
-					
-					CacheEntry[] badness = new CacheEntry[badEntries.Count];
-					badness = (CacheEntry[]) badEntries.ToArray(typeof(CacheEntry));
-					
-					insanity.Add(new Insanity(InsanityType.VALUEMISMATCH, "Multiple distinct value objects for " + rf.ToString(), badness));
-				}
-			}
+                IDictionary<ReaderField,Dictionary<int,int>> rfMap = readerFieldToValIds.GetMap();
+                IDictionary<int,Dictionary<CacheEntry,CacheEntry>> valMap = valIdToItems.GetMap();
+                foreach (ReaderField rf in valMismatchKeys.Keys)
+                {
+                    List<CacheEntry> badEntries = new List<CacheEntry>(valMismatchKeys.Count * 2);
+                    foreach (int val in rfMap[rf].Keys)
+                    {
+                        foreach (CacheEntry entry in valMap[val].Keys)
+                        {
+                            badEntries.Add(entry);
+                        }
+                    }
+
+                    insanity.Add(new Insanity(InsanityType.VALUEMISMATCH, "Multiple distinct value objects for " + rf.ToString(), badEntries.ToArray()));
+                }
+            }
 			return insanity;
 		}
 		
@@ -201,85 +199,78 @@
 		/// </summary>
 		/// <seealso cref="InsanityType.SUBREADER">
 		/// </seealso>
-		private System.Collections.ICollection CheckSubreaders(MapOfSets valIdToItems, MapOfSets readerFieldToValIds)
+		private List<Insanity> CheckSubreaders(MapOfSets<int,CacheEntry> valIdToItems, MapOfSets<ReaderField,int> readerFieldToValIds)
 		{
 			
-			System.Collections.IList insanity = new System.Collections.ArrayList(23);
-			
-			System.Collections.IDictionary badChildren = new System.Collections.Hashtable(17);
-			MapOfSets badKids = new MapOfSets(badChildren); // wrapper
-			
-			System.Collections.IDictionary viToItemSets = valIdToItems.GetMap();
-			System.Collections.IDictionary rfToValIdSets = readerFieldToValIds.GetMap();
-			
-			System.Collections.Hashtable seen = new System.Collections.Hashtable(17);
+            List<Insanity> insanity = new List<Insanity>(23);
 
-            System.Collections.Hashtable readerFields = new System.Collections.Hashtable(rfToValIdSets);
-			System.Collections.IEnumerator rfIter = readerFields.GetEnumerator();
-			while (rfIter.MoveNext())
-			{
-				ReaderField rf = (ReaderField) rfIter.Current;
-				
-				if (seen.Contains(rf))
-					continue;
-				
-				System.Collections.IList kids = GetAllDecendentReaderKeys(rf.readerKey);
+            Dictionary<ReaderField, Dictionary<ReaderField, ReaderField>> badChildren = new Dictionary<ReaderField, Dictionary<ReaderField, ReaderField>>(17);
+			MapOfSets<ReaderField, ReaderField> badKids = new MapOfSets<ReaderField, ReaderField>(badChildren); // wrapper
+
+            IDictionary<int, Dictionary<CacheEntry, CacheEntry>> viToItemSets = valIdToItems.GetMap();
+            IDictionary<ReaderField, Dictionary<int, int>> rfToValIdSets = readerFieldToValIds.GetMap();
+
+            Dictionary<ReaderField, ReaderField> seen = new Dictionary<ReaderField, ReaderField>(17);
+
+            foreach (ReaderField rf in rfToValIdSets.Keys)
+            {
+                if (seen.ContainsKey(rf))
+                    continue;
+
+                System.Collections.IList kids = GetAllDecendentReaderKeys(rf.readerKey);
 				for (int i = 0; i < kids.Count; i++)
 				{
 					ReaderField kid = new ReaderField(kids[i], rf.fieldName);
-					
-					if (badChildren.Contains(kid))
+
+					if (badChildren.ContainsKey(kid))
 					{
 						// we've already process this kid as RF and found other problems
 						// track those problems as our own
 						badKids.Put(rf, kid);
-						badKids.PutAll(rf, (System.Collections.ICollection) badChildren[kid]);
+						badKids.PutAll(rf, badChildren[kid]);
 						badChildren.Remove(kid);
 					}
-					else if (rfToValIdSets.Contains(kid))
+					else if (rfToValIdSets.ContainsKey(kid))
 					{
 						// we have cache entries for the kid
 						badKids.Put(rf, kid);
 					}
-					SupportClass.CollectionsHelper.AddIfNotContains(seen, kid);
+                    if (!seen.ContainsKey(kid))
+                    {
+                        seen.Add(kid, kid);
+                    }
 				}
-				SupportClass.CollectionsHelper.AddIfNotContains(seen, rf);
+                if (!seen.ContainsKey(rf))
+                {
+                    seen.Add(rf, rf);
+                }
 			}
 			
 			// every mapping in badKids represents an Insanity
-			System.Collections.IEnumerator parentsIter = new System.Collections.Hashtable(badChildren).GetEnumerator();
-			while (parentsIter.MoveNext())
+			foreach (ReaderField parent in badChildren.Keys)
 			{
-				ReaderField parent = (ReaderField) parentsIter.Current;
-				System.Collections.Hashtable kids = (System.Collections.Hashtable) badChildren[parent];
+				Dictionary<ReaderField,ReaderField> kids = badChildren[parent];
 				
-				System.Collections.ArrayList badEntries = new System.Collections.ArrayList(kids.Count * 2);
+				List<CacheEntry> badEntries = new List<CacheEntry>(kids.Count * 2);
 				
 				// put parent entr(ies) in first
 				{
-					System.Collections.IEnumerator valIter = ((System.Collections.Hashtable) rfToValIdSets[parent]).GetEnumerator();
-					while (valIter.MoveNext())
+					foreach (int val in rfToValIdSets[parent].Keys)
 					{
-						badEntries.AddRange((System.Collections.Hashtable) viToItemSets[valIter.Current]);
+						badEntries.AddRange(viToItemSets[val].Keys);
 					}
 				}
 				
 				// now the entries for the descendants
-				System.Collections.IEnumerator kidsIter = kids.GetEnumerator();
-				while (kidsIter.MoveNext())
+				foreach (ReaderField kid in kids.Keys)
 				{
-					ReaderField kid = (ReaderField) kidsIter.Current;
-					System.Collections.IEnumerator valIter = ((System.Collections.Hashtable) rfToValIdSets[kid]).GetEnumerator();
-					while (valIter.MoveNext())
+					foreach (int val in rfToValIdSets[kid].Keys)
 					{
-						badEntries.AddRange((System.Collections.Hashtable)viToItemSets[valIter.Current]);
+						badEntries.AddRange(viToItemSets[val].Keys);
 					}
 				}
 				
-				CacheEntry[] badness = new CacheEntry[badEntries.Count];
-				badness = (CacheEntry[]) badEntries.ToArray(typeof(CacheEntry));
-				
-				insanity.Add(new Insanity(InsanityType.SUBREADER, "Found caches for decendents of " + parent.ToString(), badness));
+				insanity.Add(new Insanity(InsanityType.SUBREADER, "Found caches for decendents of " + parent.ToString(), badEntries.ToArray()));
 			}
 			
 			return insanity;

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/MapOfSets.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/MapOfSets.cs?rev=835207&r1=835206&r2=835207&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/MapOfSets.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/MapOfSets.cs Thu Nov 12 03:13:25 2009
@@ -21,21 +21,22 @@
 {
 	
 	/// <summary> Helper class for keeping Listss of Objects associated with keys. <b>WARNING: THIS CLASS IS NOT THREAD SAFE</b></summary>
-	public class MapOfSets
-	{
+    public class MapOfSets<T, V>
+    {
 		
-		private System.Collections.IDictionary theMap;
+		// TODO: This will be a HashSet<T> when we start using .NET Framework 3.5
+		private System.Collections.Generic.IDictionary<T, System.Collections.Generic.Dictionary<V, V>> theMap;
 		
 		/// <param name="m">the backing store for this object
 		/// </param>
-		public MapOfSets(System.Collections.IDictionary m)
+		public MapOfSets(System.Collections.Generic.IDictionary<T, System.Collections.Generic.Dictionary<V, V>> m)
 		{
 			theMap = m;
 		}
 		
 		/// <returns> direct access to the map backing this object.
 		/// </returns>
-		public virtual System.Collections.IDictionary GetMap()
+		public virtual System.Collections.Generic.IDictionary<T, System.Collections.Generic.Dictionary<V, V>> GetMap()
 		{
 			return theMap;
 		}
@@ -45,19 +46,19 @@
 		/// </summary>
 		/// <returns> the size of the Set associated with key once val is added to it.
 		/// </returns>
-		public virtual int Put(System.Object key, System.Object val)
+		public virtual int Put(T key, V val)
 		{
-			System.Collections.Hashtable theSet;
-			if (theMap.Contains(key))
-			{
-				theSet = (System.Collections.Hashtable) theMap[key];
-			}
-			else
-			{
-				theSet = new System.Collections.Hashtable(23);
-				theMap[key] = theSet;
-			}
-			SupportClass.CollectionsHelper.AddIfNotContains(theSet, val);
+            // TODO: This will be a HashSet<T> when we start using .NET Framework 3.5
+            System.Collections.Generic.Dictionary<V, V> theSet;
+            if (!theMap.TryGetValue(key, out theSet))
+            {
+                theSet = new System.Collections.Generic.Dictionary<V, V>(23);
+                theMap[key] = theSet;
+            }
+            if (!theSet.ContainsKey(val))
+            {
+                theSet.Add(val, val);
+            }
 			return theSet.Count;
 		}
 		/// <summary> Adds multiple vals to the Set associated with key in the Map.  
@@ -66,19 +67,22 @@
 		/// </summary>
 		/// <returns> the size of the Set associated with key once val is added to it.
 		/// </returns>
-		public virtual int PutAll(System.Object key, System.Collections.ICollection vals)
+		public virtual int PutAll(T key, System.Collections.Generic.Dictionary<V, V> vals)
 		{
-			System.Collections.Hashtable theSet;
-			if (theMap.Contains(key))
-			{
-				theSet = (System.Collections.Hashtable) theMap[key];
-			}
-			else
-			{
-				theSet = new System.Collections.Hashtable(23);
-				theMap[key] = theSet;
-			}
-			SupportClass.CollectionsHelper.AddAllIfNotContains(theSet, vals);
+            // TODO: This will be a HashSet<T> when we start using .NET Framework 3.5
+            System.Collections.Generic.Dictionary<V, V> theSet;
+            if (!theMap.TryGetValue(key, out theSet))
+            {
+                theSet = new System.Collections.Generic.Dictionary<V, V>(23);
+                theMap[key] = theSet;
+            }
+            foreach(V item in vals.Keys)
+            {
+                if (!theSet.ContainsKey(item))
+                {
+                    theSet.Add(item, item);
+                }
+            }
 			return theSet.Count;
 		}
 	}