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 2007/05/01 20:45:35 UTC

svn commit: r534192 [19/19] - in /incubator/lucene.net/trunk/C#: ./ src/ src/Demo/ src/Demo/DeleteFiles/ src/Demo/DemoLib/ src/Demo/DemoLib/HTML/ src/Demo/IndexFiles/ src/Demo/IndexHtml/ src/Demo/SearchFiles/ src/Lucene.Net/ src/Lucene.Net/Analysis/ sr...

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/RAMInputStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/RAMInputStream.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/RAMInputStream.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/RAMInputStream.cs Tue May  1 11:45:26 2007
@@ -20,10 +20,26 @@
 namespace Lucene.Net.Store
 {
 	
+	/// <summary> Licensed to the Apache Software Foundation (ASF) under one or more
+	/// contributor license agreements.  See the NOTICE file distributed with
+	/// this work for additional information regarding copyright ownership.
+	/// The ASF licenses this file to You under the Apache License, Version 2.0
+	/// (the "License"); you may not use this file except in compliance with
+	/// the License.  You may obtain a copy of the License at
+	/// 
+	/// http://www.apache.org/licenses/LICENSE-2.0
+	/// 
+	/// Unless required by applicable law or agreed to in writing, software
+	/// distributed under the License is distributed on an "AS IS" BASIS,
+	/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	/// See the License for the specific language governing permissions and
+	/// limitations under the License.
+	/// </summary>
+	
 	/// <summary> A memory-resident {@link IndexInput} implementation.
 	/// 
 	/// </summary>
-	/// <version>  $Id: RAMInputStream.java 150537 2004-09-28 20:45:26Z cutting $
+	/// <version>  $Id: RAMInputStream.java 478014 2006-11-22 02:47:49Z yonik $
 	/// </version>
 	
 	class RAMInputStream : BufferedIndexInput, System.ICloneable
@@ -47,7 +63,7 @@
 				int bufferNumber = (int) (start / BUFFER_SIZE);
 				int bufferOffset = (int) (start % BUFFER_SIZE);
 				int bytesInBuffer = BUFFER_SIZE - bufferOffset;
-				int bytesToCopy = bytesInBuffer >= remainder?remainder:bytesInBuffer;
+				int bytesToCopy = bytesInBuffer >= remainder ? remainder : bytesInBuffer;
 				byte[] buffer = (byte[]) file.buffers[bufferNumber];
 				Array.Copy(buffer, bufferOffset, dest, destOffset, bytesToCopy);
 				destOffset += bytesToCopy;
@@ -71,21 +87,11 @@
 			return length;
 		}
 
-        /*
-        // {{Aroush-1.9}} Do we need this Clone()?!
-		public override System.Object Clone()
-		{
-            SegmentTermEnum clone = null;
-            try
-            {
-                clone = (SegmentTermEnum) base.MemberwiseClone();
-            }
-            catch (System.Exception)
-            {
-            }
-
-            return clone;
-        }
+		// {{Aroush-1.9}} Do we need this Clone()?!
+		/* virtual public System.Object Clone()
+		{
+			return null;
+		}
         */
 	}
 }

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/RAMOutputStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/RAMOutputStream.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/RAMOutputStream.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/RAMOutputStream.cs Tue May  1 11:45:26 2007
@@ -23,7 +23,7 @@
 	/// <summary> A memory-resident {@link IndexOutput} implementation.
 	/// 
 	/// </summary>
-	/// <version>  $Id: RAMOutputStream.java 150537 2004-09-28 20:45:26Z cutting $
+	/// <version>  $Id: RAMOutputStream.java 488330 2006-12-18 16:45:29Z mikemccand $
 	/// </version>
 	
 	public class RAMOutputStream : BufferedIndexOutput
@@ -75,40 +75,35 @@
 				throw new System.SystemException(e.ToString());
 			}
 			
-			file.length = 0;
+			file.SetLength(0);
 		}
 		
 		public override void  FlushBuffer(byte[] src, int len)
 		{
-            byte[] buffer;
-            int bufferPos = 0;
-            while (bufferPos != len)
-            {
-                int bufferNumber = (int) (pointer / BUFFER_SIZE);
-                int bufferOffset = (int) (pointer % BUFFER_SIZE);
-                int bytesInBuffer = BUFFER_SIZE - bufferOffset;
-                int remainInSrcBuffer = len - bufferPos;
-                int bytesToCopy = bytesInBuffer >= remainInSrcBuffer ? remainInSrcBuffer : bytesInBuffer;
+			byte[] buffer;
+			int bufferPos = 0;
+			while (bufferPos != len)
+			{
+				int bufferNumber = (int) (pointer / BUFFER_SIZE);
+				int bufferOffset = (int) (pointer % BUFFER_SIZE);
+				int bytesInBuffer = BUFFER_SIZE - bufferOffset;
+				int remainInSrcBuffer = len - bufferPos;
+				int bytesToCopy = bytesInBuffer >= remainInSrcBuffer ? remainInSrcBuffer : bytesInBuffer;
 				
-                if (bufferNumber == file.buffers.Count)
-                {
-                    buffer = new byte[BUFFER_SIZE];
-                    file.buffers.Add(buffer);
-                }
-                else
-                {
-                    buffer = (byte[]) file.buffers[bufferNumber];
-                }
+				if (bufferNumber == file.buffers.Count)
+					buffer = file.AddBuffer(BUFFER_SIZE);
+				else
+					buffer = (byte[]) file.buffers[bufferNumber];
 				
-                Array.Copy(src, bufferPos, buffer, bufferOffset, bytesToCopy);
-                bufferPos += bytesToCopy;
-                pointer += bytesToCopy;
-            }
+				Array.Copy(src, bufferPos, buffer, bufferOffset, bytesToCopy);
+				bufferPos += bytesToCopy;
+				pointer += bytesToCopy;
+			}
 			
-            if (pointer > file.length)
-                file.length = pointer;
+			if (pointer > file.length)
+				file.SetLength(pointer);
 			
-            file.lastModified = System.DateTime.Now.Ticks;
+			file.SetLastModified(System.DateTime.Now.Ticks);
 		}
 		
 		public override void  Close()

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/SimpleFSLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/SimpleFSLockFactory.cs?view=auto&rev=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/SimpleFSLockFactory.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/SimpleFSLockFactory.cs Tue May  1 11:45:26 2007
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Lucene.Net.Store
+{
+	
+	/// <summary> Implements {@link LockFactory} using {@link File#createNewFile()}.  This is
+	/// currently the default LockFactory used for {@link FSDirectory} if no
+	/// LockFactory instance is otherwise provided.
+	/// 
+	/// Note that there are known problems with this locking implementation on NFS.
+	/// 
+	/// </summary>
+	/// <seealso cref="LockFactory">
+	/// </seealso>
+	
+	public class SimpleFSLockFactory : LockFactory
+	{
+		
+		/// <summary> Directory specified by <code>Lucene.Net.lockDir</code>
+		/// system property.  If that is not set, then <code>java.io.tmpdir</code>
+		/// system property is used.
+		/// </summary>
+		
+		private System.IO.FileInfo lockDir;
+		
+		/// <summary> Instantiate using the provided directory (as a File instance).</summary>
+		/// <param name="lockDir">where lock files should be created.
+		/// </param>
+		public SimpleFSLockFactory(System.IO.FileInfo lockDir)
+		{
+			Init(lockDir);
+		}
+		
+		/// <summary> Instantiate using the provided directory name (String).</summary>
+		/// <param name="lockDirName">where lock files should be created.
+		/// </param>
+		public SimpleFSLockFactory(System.String lockDirName)
+		{
+			lockDir = new System.IO.FileInfo(lockDirName);
+			Init(lockDir);
+		}
+		
+		protected internal virtual void  Init(System.IO.FileInfo lockDir)
+		{
+			this.lockDir = lockDir;
+		}
+		
+		public override Lock MakeLock(System.String lockName)
+		{
+			if (lockPrefix != null)
+			{
+				lockName = lockPrefix + "-" + lockName;
+			}
+			return new SimpleFSLock(lockDir, lockName);
+		}
+		
+		public override void  ClearLock(System.String lockName)
+		{
+			bool tmpBool;
+			if (System.IO.File.Exists(lockDir.FullName))
+				tmpBool = true;
+			else
+				tmpBool = System.IO.Directory.Exists(lockDir.FullName);
+			if (tmpBool)
+			{
+				if (lockPrefix != null)
+				{
+					lockName = lockPrefix + "-" + lockName;
+				}
+				System.IO.FileInfo lockFile = new System.IO.FileInfo(System.IO.Path.Combine(lockDir.FullName, lockName));
+				bool tmpBool2;
+				if (System.IO.File.Exists(lockFile.FullName))
+					tmpBool2 = true;
+				else
+					tmpBool2 = System.IO.Directory.Exists(lockFile.FullName);
+				bool tmpBool3;
+				if (System.IO.File.Exists(lockFile.FullName))
+				{
+					System.IO.File.Delete(lockFile.FullName);
+					tmpBool3 = true;
+				}
+				else if (System.IO.Directory.Exists(lockFile.FullName))
+				{
+					System.IO.Directory.Delete(lockFile.FullName);
+					tmpBool3 = true;
+				}
+				else
+					tmpBool3 = false;
+				if (tmpBool2 && !tmpBool3)
+				{
+					throw new System.IO.IOException("Cannot delete " + lockFile);
+				}
+			}
+		}
+	}
+	
+	
+	class SimpleFSLock : Lock
+	{
+		
+		internal System.IO.FileInfo lockFile;
+		internal System.IO.FileInfo lockDir;
+		
+		public SimpleFSLock(System.IO.FileInfo lockDir, System.String lockFileName)
+		{
+			this.lockDir = lockDir;
+			lockFile = new System.IO.FileInfo(System.IO.Path.Combine(lockDir.FullName, lockFileName));
+		}
+		
+		public override bool Obtain()
+		{
+			
+			// Ensure that lockDir exists and is a directory:
+			bool tmpBool;
+			if (System.IO.File.Exists(lockDir.FullName))
+				tmpBool = true;
+			else
+				tmpBool = System.IO.Directory.Exists(lockDir.FullName);
+			if (!tmpBool)
+			{
+                try
+                {
+                    System.IO.Directory.CreateDirectory(lockDir.FullName);
+                }
+                catch
+                {
+                    throw new System.IO.IOException("Cannot create directory: " + lockDir.FullName);
+                }
+			}
+			else
+			{
+                try
+                {
+                    System.IO.Directory.Exists(lockDir.FullName);
+                }
+                catch
+                {
+                    throw new System.IO.IOException("Found regular file where directory expected: " + lockDir.FullName);
+                }
+			}
+            try
+            {
+                System.IO.FileStream createdFile = lockFile.Create();
+                createdFile.Close();
+                return true;
+            }
+            catch
+            {
+                return false;
+            }
+		}
+		
+		public override void  Release()
+		{
+			bool tmpBool;
+			if (System.IO.File.Exists(lockFile.FullName))
+			{
+				System.IO.File.Delete(lockFile.FullName);
+				tmpBool = true;
+			}
+			else if (System.IO.Directory.Exists(lockFile.FullName))
+			{
+				System.IO.Directory.Delete(lockFile.FullName);
+				tmpBool = true;
+			}
+			else
+				tmpBool = false;
+			bool generatedAux = tmpBool;
+		}
+		
+		public override bool IsLocked()
+		{
+			bool tmpBool;
+			if (System.IO.File.Exists(lockFile.FullName))
+				tmpBool = true;
+			else
+				tmpBool = System.IO.Directory.Exists(lockFile.FullName);
+			return tmpBool;
+		}
+		
+		public override System.String ToString()
+		{
+			return "SimpleFSLock@" + lockFile;
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/SingleInstanceLockFactory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/SingleInstanceLockFactory.cs?view=auto&rev=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/SingleInstanceLockFactory.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/SingleInstanceLockFactory.cs Tue May  1 11:45:26 2007
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Lucene.Net.Store
+{
+	
+	/// <summary> Implements {@link LockFactory} for a single in-process instance,
+	/// meaning all locking will take place through this one instance.
+	/// Only use this {@link LockFactory} when you are certain all
+	/// IndexReaders and IndexWriters for a given index are running
+	/// against a single shared in-process Directory instance.  This is
+	/// currently the default locking for RAMDirectory.
+	/// 
+	/// </summary>
+	/// <seealso cref="LockFactory">
+	/// </seealso>
+	
+	public class SingleInstanceLockFactory:LockFactory
+	{
+		
+		private System.Collections.Hashtable locks = new System.Collections.Hashtable();
+		
+		public override Lock MakeLock(System.String lockName)
+		{
+			// We do not use the LockPrefix at all, because the private
+			// HashSet instance effectively scopes the locking to this
+			// single Directory instance.
+			return new SingleInstanceLock(locks, lockName);
+		}
+		
+		public override void  ClearLock(System.String lockName)
+		{
+			lock (locks)
+			{
+				if (locks.Contains(lockName))
+				{
+					locks.Remove(lockName);
+				}
+			}
+		}
+	}
+	
+	
+	class SingleInstanceLock:Lock
+	{
+		
+		internal System.String lockName;
+		private System.Collections.Hashtable locks;
+		
+		public SingleInstanceLock(System.Collections.Hashtable locks, System.String lockName)
+		{
+			this.locks = locks;
+			this.lockName = lockName;
+		}
+		
+		public override bool Obtain()
+		{
+			lock (locks)
+			{
+                if (locks.Contains(lockName) == false)
+                {
+                    locks.Add(lockName, lockName);
+                    return true;
+                }
+                return false;
+			}
+		}
+		
+		public override void  Release()
+		{
+			lock (locks)
+			{
+				locks.Remove(lockName);
+			}
+		}
+		
+		public override bool IsLocked()
+		{
+			lock (locks)
+			{
+				return locks.Contains(lockName);
+			}
+		}
+		
+		public override System.String ToString()
+		{
+			return "SingleInstanceLock: " + lockName;
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/SupportClass.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs Tue May  1 11:45:26 2007
@@ -417,6 +417,22 @@
                 return (number >> bits) + (2 << ~bits);
         }
 
+
+        /// <summary>
+        /// Performs an unsigned bitwise right shift with the specified number
+        /// </summary>
+        /// <param name="number">Number to operate on</param>
+        /// <param name="bits">Ammount of bits to shift</param>
+        /// <returns>The resulting number from the shift operation</returns>
+        public static long URShift(long number, int bits)
+        {
+            if (number >= 0)
+                return number >> bits;
+            else
+                return (number >> bits) + (2 << ~bits);
+        }
+
+
         /// <summary>
         /// Returns the index of the first bit that is set to true that occurs 
         /// on or after the specified starting index. If no such bit exists 
@@ -590,28 +606,16 @@
         /// <returns></returns>
         public static System.Single Parse(System.String s)
         {
-            System.Double res; 
-
-            if (s.EndsWith("f") || s.EndsWith("F"))
-            {
-                System.Double.TryParse(s.Substring(0, s.Length - 1), 
-                    (System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.AllowThousands),
-                    null, out res);
-            }
-            else
-            {
-                System.Double.TryParse(s, 
-                    (System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.AllowThousands),
-                    null, out res);
-            }
-
             try
             {
-                return System.Convert.ToSingle(res);
+                if (s.EndsWith("f") || s.EndsWith("F"))
+                    return System.Single.Parse(s.Substring(0, s.Length - 1));
+                else
+                    return System.Single.Parse(s);
             }
-            catch (System.OverflowException)
+            catch(System.FormatException fex)
             {
-                return 0;
+                throw fex;					
             }
         }
     }

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/BitVector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/BitVector.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/BitVector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/BitVector.cs Tue May  1 11:45:26 2007
@@ -16,6 +16,7 @@
  */
 
 using System;
+
 using Directory = Lucene.Net.Store.Directory;
 using IndexInput = Lucene.Net.Store.IndexInput;
 using IndexOutput = Lucene.Net.Store.IndexOutput;
@@ -29,11 +30,12 @@
 	/// <li>a count() method, which efficiently computes the number of one bits;</li>
 	/// <li>optimized read from and write to disk;</li>
 	/// <li>inlinable get() method;</li>
+	/// <li>store and load, as bit set or d-gaps, depending on sparseness;</li> 
 	/// </ul>
 	/// </summary>
 	/// <author>  Doug Cutting
 	/// </author>
-	/// <version>  $Id: BitVector.java 150536 2004-09-28 18:15:52Z cutting $
+	/// <version>  $Id: BitVector.java 494136 2007-01-08 18:11:08Z mikemccand $
 	/// </version>
 	public sealed class BitVector
 	{
@@ -52,6 +54,10 @@
 		/// <summary>Sets the value of <code>bit</code> to one. </summary>
 		public void  Set(int bit)
 		{
+			if (bit >= size)
+			{
+				throw new System.IndexOutOfRangeException("Index of bound " + bit);
+			}
 			bits[bit >> 3] |= (byte) (1 << (bit & 7));
 			count = - 1;
 		}
@@ -59,6 +65,10 @@
 		/// <summary>Sets the value of <code>bit</code> to zero. </summary>
 		public void  Clear(int bit)
 		{
+			if (bit >= size)
+			{
+				throw new System.IndexOutOfRangeException("Index of bound " + bit);
+			}
 			bits[bit >> 3] &= (byte) (~ (1 << (bit & 7)));
 			count = - 1;
 		}
@@ -68,6 +78,10 @@
 		/// </summary>
 		public bool Get(int bit)
 		{
+			if (bit >= size)
+			{
+				throw new System.IndexOutOfRangeException("Index of bound " + bit);
+			}
 			return (bits[bit >> 3] & (1 << (bit & 7))) != 0;
 		}
 		
@@ -109,9 +123,14 @@
 			IndexOutput output = d.CreateOutput(name);
 			try
 			{
-				output.WriteInt(Size()); // write size
-				output.WriteInt(Count()); // write count
-				output.WriteBytes(bits, bits.Length); // write bits
+				if (IsSparse())
+				{
+					WriteDgaps(output); // sparse bit-set more efficiently saved as d-gaps.
+				}
+				else
+				{
+					WriteBits(output);
+				}
 			}
 			finally
 			{
@@ -119,6 +138,57 @@
 			}
 		}
 		
+		/// <summary>Write as a bit set </summary>
+		private void  WriteBits(IndexOutput output)
+		{
+			output.WriteInt(Size()); // write size
+			output.WriteInt(Count()); // write count
+			output.WriteBytes(bits, bits.Length);
+		}
+		
+		/// <summary>Write as a d-gaps list </summary>
+		private void  WriteDgaps(IndexOutput output)
+		{
+			output.WriteInt(- 1); // mark using d-gaps                         
+			output.WriteInt(Size()); // write size
+			output.WriteInt(Count()); // write count
+			int last = 0;
+			int n = Count();
+			int m = bits.Length;
+			for (int i = 0; i < m && n > 0; i++)
+			{
+				if (bits[i] != 0)
+				{
+					output.WriteVInt(i - last);
+					output.WriteByte(bits[i]);
+					last = i;
+					n -= BYTE_COUNTS[bits[i] & 0xFF];
+				}
+			}
+		}
+		
+		/// <summary>Indicates if the bit vector is sparse and should be saved as a d-gaps list, or dense, and should be saved as a bit set. </summary>
+		private bool IsSparse()
+		{
+			// note: order of comparisons below set to favor smaller values (no binary range search.)
+			// note: adding 4 because we start with ((int) -1) to indicate d-gaps format.
+			// note: we write the d-gap for the byte number, and the byte (bits[i]) itself, therefore
+			//       multiplying count by (8+8) or (8+16) or (8+24) etc.:
+			//       - first 8 for writing bits[i] (1 byte vs. 1 bit), and 
+			//       - second part for writing the byte-number d-gap as vint. 
+			// note: factor is for read/write of byte-arrays being faster than vints.  
+			int factor = 10;
+			if (bits.Length < (1 << 7))
+				return factor * (4 + (8 + 8) * Count()) < Size();
+			if (bits.Length < (1 << 14))
+				return factor * (4 + (8 + 16) * Count()) < Size();
+			if (bits.Length < (1 << 21))
+				return factor * (4 + (8 + 24) * Count()) < Size();
+			if (bits.Length < (1 << 28))
+				return factor * (4 + (8 + 32) * Count()) < Size();
+			return factor * (4 + (8 + 40) * Count()) < Size();
+		}
+		
 		/// <summary>Constructs a bit vector from the file <code>name</code> in Directory
 		/// <code>d</code>, as written by the {@link #write} method.
 		/// </summary>
@@ -128,13 +198,42 @@
 			try
 			{
 				size = input.ReadInt(); // read size
-				count = input.ReadInt(); // read count
-				bits = new byte[(size >> 3) + 1]; // allocate bits
-				input.ReadBytes(bits, 0, bits.Length); // read bits
+				if (size == - 1)
+				{
+					ReadDgaps(input);
+				}
+				else
+				{
+					ReadBits(input);
+				}
 			}
 			finally
 			{
 				input.Close();
+			}
+		}
+		
+		/// <summary>Read as a bit set </summary>
+		private void  ReadBits(IndexInput input)
+		{
+			count = input.ReadInt(); // read count
+			bits = new byte[(size >> 3) + 1]; // allocate bits
+			input.ReadBytes(bits, 0, bits.Length);
+		}
+		
+		/// <summary>read as a d-gaps list </summary>
+		private void  ReadDgaps(IndexInput input)
+		{
+			size = input.ReadInt(); // (re)read size
+			count = input.ReadInt(); // read count
+			bits = new byte[(size >> 3) + 1]; // allocate bits
+			int last = 0;
+			int n = Count();
+			while (n > 0)
+			{
+				last += input.ReadVInt();
+				bits[last] = input.ReadByte();
+				n -= BYTE_COUNTS[bits[last] & 0xFF];
 			}
 		}
 	}

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/Constants.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/Constants.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/Constants.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/Constants.cs Tue May  1 11:45:26 2007
@@ -20,12 +20,28 @@
 namespace Lucene.Net.Util
 {
 	
+	/// <summary> Licensed to the Apache Software Foundation (ASF) under one or more
+	/// contributor license agreements.  See the NOTICE file distributed with
+	/// this work for additional information regarding copyright ownership.
+	/// The ASF licenses this file to You under the Apache License, Version 2.0
+	/// (the "License"); you may not use this file except in compliance with
+	/// the License.  You may obtain a copy of the License at
+	/// 
+	/// http://www.apache.org/licenses/LICENSE-2.0
+	/// 
+	/// Unless required by applicable law or agreed to in writing, software
+	/// distributed under the License is distributed on an "AS IS" BASIS,
+	/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	/// See the License for the specific language governing permissions and
+	/// limitations under the License.
+	/// </summary>
+	
 	/// <summary> Some useful constants.
 	/// 
 	/// </summary>
 	/// <author>   Doug Cutting
 	/// </author>
-	/// <version>  $Id: Constants.java 189792 2005-06-09 18:58:30Z bmesser $
+	/// <version>  $Id: Constants.java 472959 2006-11-09 16:21:50Z yonik $
 	/// 
 	/// </version>
 	
@@ -35,6 +51,7 @@
 		{
 		} // can't construct
 		
+        // {{Aroush-2.1 those next constants are Java specific, what's the equivlant in C#?
 		/// <summary>The value of <tt>System.getProperty("java.version")<tt>. *</summary>
 		public static readonly System.String JAVA_VERSION = System.Configuration.ConfigurationSettings.AppSettings.Get("java.version");     // {{Aroush-1.9}}
 		/// <summary>True iff this is Java version 1.1. </summary>
@@ -44,6 +61,7 @@
 		/// <summary>True iff this is Java version 1.3. </summary>
 		public static readonly bool JAVA_1_3 = JAVA_VERSION.StartsWith("1.3.");
 		
+        // {{Aroush-2.1 are those envirement variables work with .NET
 		/// <summary>The value of <tt>System.getProperty("os.name")<tt>. *</summary>
 		public static readonly System.String OS_NAME = System.Environment.GetEnvironmentVariable("OS");
 		/// <summary>True iff running on Linux. </summary>

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/Package.html
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/Package.html?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/Package.html (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/Package.html Tue May  1 11:45:26 2007
@@ -1,10 +1,10 @@
-<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head>
-   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-   <meta name="Author" content="Doug Cutting">
-</head>
-<body>
-Some utility classes.
-</body>
-</html>
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+   <meta name="Author" content="Doug Cutting">
+</head>
+<body>
+Some utility classes.
+</body>
+</html>

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/PriorityQueue.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/PriorityQueue.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/PriorityQueue.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/PriorityQueue.cs Tue May  1 11:45:26 2007
@@ -20,19 +20,31 @@
 namespace Lucene.Net.Util
 {
 	
+	/// <summary> Licensed to the Apache Software Foundation (ASF) under one or more
+	/// contributor license agreements.  See the NOTICE file distributed with
+	/// this work for additional information regarding copyright ownership.
+	/// The ASF licenses this file to You under the Apache License, Version 2.0
+	/// (the "License"); you may not use this file except in compliance with
+	/// the License.  You may obtain a copy of the License at
+	/// 
+	/// http://www.apache.org/licenses/LICENSE-2.0
+	/// 
+	/// Unless required by applicable law or agreed to in writing, software
+	/// distributed under the License is distributed on an "AS IS" BASIS,
+	/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	/// See the License for the specific language governing permissions and
+	/// limitations under the License.
+	/// </summary>
+	
 	/// <summary>A PriorityQueue maintains a partial ordering of its elements such that the
 	/// least element can always be found in constant time.  Put()'s and pop()'s
 	/// require log(size) time. 
 	/// </summary>
-    [Serializable]
-    public abstract class PriorityQueue
+	public abstract class PriorityQueue
 	{
-        [NonSerialized]
-        private System.Object[] heap;
-        [NonSerialized]
-        private int size;
-        [NonSerialized]
-        private int maxSize;
+		private System.Object[] heap;
+		private int size;
+		private int maxSize;
 		
 		/// <summary>Determines the ordering of objects in this priority queue.  Subclasses
 		/// must define this one method. 
@@ -50,7 +62,7 @@
 		
 		/// <summary> Adds an Object to a PriorityQueue in log(size) time.
 		/// If one tries to add more objects than maxSize from initialize
-		/// a RuntimeException (ArrayIndexOutOfBound) is thrown.
+		/// a SystemException (ArrayIndexOutOfBound) is thrown.
 		/// </summary>
 		public void  Put(System.Object element)
 		{
@@ -62,7 +74,7 @@
 		/// <summary> Adds element to the PriorityQueue in log(size) time if either
 		/// the PriorityQueue is not full, or not lessThan(element, top()).
 		/// </summary>
-		/// <param name="element">
+		/// <param name="">element
 		/// </param>
 		/// <returns> true if element is added, false otherwise.
 		/// </returns>

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/ScorerDocQueue.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/ScorerDocQueue.cs?view=auto&rev=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/ScorerDocQueue.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/ScorerDocQueue.cs Tue May  1 11:45:26 2007
@@ -0,0 +1,274 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/* Derived from Lucene.Net.Util.PriorityQueue of March 2005 */
+using System;
+
+using Scorer = Lucene.Net.Search.Scorer;
+
+namespace Lucene.Net.Util
+{
+	
+	/// <summary>A ScorerDocQueue maintains a partial ordering of its Scorers such that the
+	/// least Scorer can always be found in constant time.  Put()'s and pop()'s
+	/// require log(size) time. The ordering is by Scorer.doc().
+	/// </summary>
+	public class ScorerDocQueue
+	{
+		// later: SpansQueue for spans with doc and term positions
+		private HeapedScorerDoc[] heap;
+		private int maxSize;
+		private int size;
+		
+		private class HeapedScorerDoc
+		{
+			private void  InitBlock(ScorerDocQueue enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+			}
+			private ScorerDocQueue enclosingInstance;
+			public ScorerDocQueue Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+			internal Scorer scorer;
+			internal int doc;
+			
+			internal HeapedScorerDoc(ScorerDocQueue enclosingInstance, Scorer s):this(enclosingInstance, s, s.Doc())
+			{
+			}
+			
+			internal HeapedScorerDoc(ScorerDocQueue enclosingInstance, Scorer scorer, int doc)
+			{
+				InitBlock(enclosingInstance);
+				this.scorer = scorer;
+				this.doc = doc;
+			}
+			
+			internal virtual void  Adjust()
+			{
+				doc = scorer.Doc();
+			}
+		}
+		
+		private HeapedScorerDoc topHSD; // same as heap[1], only for speed
+		
+		/// <summary>Create a ScorerDocQueue with a maximum size. </summary>
+		public ScorerDocQueue(int maxSize)
+		{
+			// assert maxSize >= 0;
+			size = 0;
+			int heapSize = maxSize + 1;
+			heap = new HeapedScorerDoc[heapSize];
+			this.maxSize = maxSize;
+			topHSD = heap[1]; // initially null
+		}
+		
+		/// <summary> Adds a Scorer to a ScorerDocQueue in log(size) time.
+		/// If one tries to add more Scorers than maxSize
+		/// a SystemException (ArrayIndexOutOfBound) is thrown.
+		/// </summary>
+		public void  Put(Scorer scorer)
+		{
+			size++;
+			heap[size] = new HeapedScorerDoc(this, scorer);
+			UpHeap();
+		}
+		
+		/// <summary> Adds a Scorer to the ScorerDocQueue in log(size) time if either
+		/// the ScorerDocQueue is not full, or not lessThan(scorer, top()).
+		/// </summary>
+		/// <param name="">scorer
+		/// </param>
+		/// <returns> true if scorer is added, false otherwise.
+		/// </returns>
+		public virtual bool Insert(Scorer scorer)
+		{
+			if (size < maxSize)
+			{
+				Put(scorer);
+				return true;
+			}
+			else
+			{
+				int docNr = scorer.Doc();
+				if ((size > 0) && (!(docNr < topHSD.doc)))
+				{
+					// heap[1] is top()
+					heap[1] = new HeapedScorerDoc(this, scorer, docNr);
+					DownHeap();
+					return true;
+				}
+				else
+				{
+					return false;
+				}
+			}
+		}
+		
+		/// <summary>Returns the least Scorer of the ScorerDocQueue in constant time.
+		/// Should not be used when the queue is empty.
+		/// </summary>
+		public Scorer Top()
+		{
+			// assert size > 0;
+			return topHSD.scorer;
+		}
+		
+		/// <summary>Returns document number of the least Scorer of the ScorerDocQueue
+		/// in constant time.
+		/// Should not be used when the queue is empty.
+		/// </summary>
+		public int TopDoc()
+		{
+			// assert size > 0;
+			return topHSD.doc;
+		}
+		
+		public float TopScore()
+		{
+			// assert size > 0;
+			return topHSD.scorer.Score();
+		}
+		
+		public bool TopNextAndAdjustElsePop()
+		{
+			return CheckAdjustElsePop(topHSD.scorer.Next());
+		}
+		
+		public bool TopSkipToAndAdjustElsePop(int target)
+		{
+			return CheckAdjustElsePop(topHSD.scorer.SkipTo(target));
+		}
+		
+		private bool CheckAdjustElsePop(bool cond)
+		{
+			if (cond)
+			{
+				// see also adjustTop
+				topHSD.doc = topHSD.scorer.Doc();
+			}
+			else
+			{
+				// see also popNoResult
+				heap[1] = heap[size]; // move last to first
+				heap[size] = null;
+				size--;
+			}
+			DownHeap();
+			return cond;
+		}
+		
+		/// <summary>Removes and returns the least scorer of the ScorerDocQueue in log(size)
+		/// time.
+		/// Should not be used when the queue is empty.
+		/// </summary>
+		public Scorer Pop()
+		{
+			// assert size > 0;
+			Scorer result = topHSD.scorer;
+			PopNoResult();
+			return result;
+		}
+		
+		/// <summary>Removes the least scorer of the ScorerDocQueue in log(size) time.
+		/// Should not be used when the queue is empty.
+		/// </summary>
+		private void  PopNoResult()
+		{
+			heap[1] = heap[size]; // move last to first
+			heap[size] = null;
+			size--;
+			DownHeap(); // adjust heap
+		}
+		
+		/// <summary>Should be called when the scorer at top changes doc() value.
+		/// Still log(n) worst case, but it's at least twice as fast to <pre>
+		/// { pq.top().change(); pq.adjustTop(); }
+		/// </pre> instead of <pre>
+		/// { o = pq.pop(); o.change(); pq.push(o); }
+		/// </pre>
+		/// </summary>
+		public void  AdjustTop()
+		{
+			// assert size > 0;
+			topHSD.Adjust();
+			DownHeap();
+		}
+		
+		/// <summary>Returns the number of scorers currently stored in the ScorerDocQueue. </summary>
+		public int Size()
+		{
+			return size;
+		}
+		
+		/// <summary>Removes all entries from the ScorerDocQueue. </summary>
+		public void  Clear()
+		{
+			for (int i = 0; i <= size; i++)
+			{
+				heap[i] = null;
+			}
+			size = 0;
+		}
+		
+		private void  UpHeap()
+		{
+			int i = size;
+			HeapedScorerDoc node = heap[i]; // save bottom node
+			int j = SupportClass.Number.URShift(i, 1);
+			while ((j > 0) && (node.doc < heap[j].doc))
+			{
+				heap[i] = heap[j]; // shift parents down
+				i = j;
+				j = SupportClass.Number.URShift(j, 1);
+			}
+			heap[i] = node; // install saved node
+			topHSD = heap[1];
+		}
+		
+		private void  DownHeap()
+		{
+			int i = 1;
+			HeapedScorerDoc node = heap[i]; // save top node
+			int j = i << 1; // find smaller child
+			int k = j + 1;
+			if ((k <= size) && (heap[k].doc < heap[j].doc))
+			{
+				j = k;
+			}
+			while ((j <= size) && (heap[j].doc < node.doc))
+			{
+				heap[i] = heap[j]; // shift up child
+				i = j;
+				j = i << 1;
+				k = j + 1;
+				if (k <= size && (heap[k].doc < heap[j].doc))
+				{
+					j = k;
+				}
+			}
+			heap[i] = node; // install saved node
+			topHSD = heap[1];
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/SmallFloat.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/SmallFloat.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/SmallFloat.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/SmallFloat.cs Tue May  1 11:45:26 2007
@@ -51,7 +51,7 @@
 			// Adjustment from a float zero exponent to our zero exponent,
 			// shifted over to our exponent position.
 			int fzero = (63 - zeroExp) << numMantissaBits;
-            int bits = System.BitConverter.ToInt32(System.BitConverter.GetBytes(f), 0);
+			int bits = System.BitConverter.ToInt32(System.BitConverter.GetBytes(f), 0);
 			int smallfloat = bits >> (24 - numMantissaBits);
 			if (smallfloat < fzero)
 			{
@@ -93,7 +93,7 @@
 		/// </summary>
 		public static sbyte FloatToByte315(float f)
 		{
-            int bits = System.BitConverter.ToInt32(System.BitConverter.GetBytes(f), 0);
+			int bits = System.BitConverter.ToInt32(System.BitConverter.GetBytes(f), 0);
 			int smallfloat = bits >> (24 - 3);
 			if (smallfloat < (63 - 15) << 3)
 			{
@@ -126,7 +126,7 @@
 		/// </summary>
 		public static sbyte FloatToByte52(float f)
 		{
-            int bits = System.BitConverter.ToInt32(System.BitConverter.GetBytes(f), 0);
+			int bits = System.BitConverter.ToInt32(System.BitConverter.GetBytes(f), 0);
 			int smallfloat = bits >> (24 - 5);
 			if (smallfloat < (63 - 2) << 5)
 			{

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/StringHelper.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/StringHelper.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/StringHelper.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/StringHelper.cs Tue May  1 11:45:26 2007
@@ -23,7 +23,7 @@
 	
 	/// <summary> Methods for manipulating strings.
 	/// 
-	/// $Id: StringHelper.java 150248 2004-03-25 13:39:59Z otis $
+	/// $Id: StringHelper.java 472959 2006-11-09 16:21:50Z yonik $
 	/// </summary>
 	public abstract class StringHelper
 	{

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/ToStringUtils.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/ToStringUtils.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/ToStringUtils.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/ToStringUtils.cs Tue May  1 11:45:26 2007
@@ -20,19 +20,19 @@
 namespace Lucene.Net.Util
 {
 	
-	public class ToStringUtils
-	{
-		public static System.String Boost(float boost)
-		{
-			if (boost != 1.0f)
-			{
+    public class ToStringUtils
+    {
+        public static System.String Boost(float boost)
+        {
+            if (boost != 1.0f)
+            {
                 float boostAsLong = (long) boost;
                 if (boostAsLong == boost)
                     return "^" + boost.ToString(".0");
                 return "^" + boost.ToString();
-			}
-			else
-				return "";
-		}
-	}
+            }
+            else
+                return "";
+        }
+    }
 }