lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r836316 - /incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/NumericUtils.cs
Date Sun, 15 Nov 2009 02:24:29 GMT
Author: aroush
Date: Sun Nov 15 02:24:29 2009
New Revision: 836316

URL: http://svn.apache.org/viewvc?rev=836316&view=rev
Log:
Patch of LUCENENET-197: LongToPrefixCoded in NumericUtils does not work for negitive Numbers
2.9.0

Modified:
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/NumericUtils.cs

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/NumericUtils.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Util/NumericUtils.cs?rev=836316&r1=836315&r2=836316&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/NumericUtils.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Util/NumericUtils.cs Sun Nov 15 02:24:29
2009
@@ -117,15 +117,15 @@
 				throw new System.ArgumentException("Illegal shift value, must be 0..63");
 			int nChars = (63 - shift) / 7 + 1, len = nChars + 1;
 			buffer[0] = (char) (SHIFT_START_LONG + shift);
-			long sortableBits = val ^ unchecked((long) 0x8000000000000000L);   // {{Aroush-2.9}} using
'unchecked' here!
-			sortableBits = SupportClass.Number.URShift(sortableBits, shift);
+            ulong sortableBits = BitConverter.ToUInt64(BitConverter.GetBytes(val), 0) ^ 0x8000000000000000L;
+			sortableBits = sortableBits >> shift;
 			while (nChars >= 1)
 			{
 				// Store 7 bits per character for good efficiency when UTF-8 encoding.
 				// The whole number is right-justified so that lucene can prefix-encode
 				// the terms more efficiently.
 				buffer[nChars--] = (char) (sortableBits & 0x7f);
-				sortableBits = SupportClass.Number.URShift(sortableBits, 7);
+				sortableBits = sortableBits >> 7;
 			}
 			return len;
 		}
@@ -223,7 +223,7 @@
 			int shift = prefixCoded[0] - SHIFT_START_LONG;
 			if (shift > 63 || shift < 0)
 				throw new System.FormatException("Invalid shift value in prefixCoded string (is encoded
value really a LONG?)");
-			long sortableBits = 0L;
+			ulong sortableBits = 0UL;
 			for (int i = 1, len = prefixCoded.Length; i < len; i++)
 			{
 				sortableBits <<= 7;
@@ -232,9 +232,9 @@
 				{
 					throw new System.FormatException("Invalid prefixCoded numerical value representation
(char " + System.Convert.ToString((int) ch, 16) + " at position " + i + " is invalid)");
 				}
-				sortableBits |= (long) ch;
+				sortableBits |= (ulong) ch;
 			}
-			return (sortableBits << shift) ^ unchecked((long) 0x8000000000000000L); // {{Aroush-2.9}}
using 'unchecked' here!
+			return BitConverter.ToInt64(BitConverter.GetBytes((sortableBits << shift) ^ 0x8000000000000000L),
0);
 		}
 		
 		/// <summary> Returns an int from prefixCoded characters.



Mime
View raw message