lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mhern...@apache.org
Subject git commit: adding tests for counting trailing/leading zeros
Date Wed, 20 Aug 2014 18:16:22 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/pcl b1d556579 -> b31804212


adding tests for counting trailing/leading zeros


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/b3180421
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/b3180421
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/b3180421

Branch: refs/heads/pcl
Commit: b318042125209be4c5ee2b7ef1621732da615cbb
Parents: b1d5565
Author: Michael Herndon <mherndon@michaelherndon.com>
Authored: Wed Aug 20 14:15:30 2014 -0400
Committer: Michael Herndon <mherndon@michaelherndon.com>
Committed: Wed Aug 20 14:15:30 2014 -0400

----------------------------------------------------------------------
 .../Support/NumberExtensionMethods.cs           | 33 ++++++++++++---
 src/Lucene.Net.Core/Util/CharsRefBuilder.cs     |  8 ++--
 .../Lucene.Net.Core.Tests.csproj                |  1 +
 .../Support/TestNumberExtensionMethods.cs       | 43 ++++++++++++++++++++
 4 files changed, 76 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b3180421/src/Lucene.Net.Core/Support/NumberExtensionMethods.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/NumberExtensionMethods.cs b/src/Lucene.Net.Core/Support/NumberExtensionMethods.cs
index aa97ee2..1223bfa 100644
--- a/src/Lucene.Net.Core/Support/NumberExtensionMethods.cs
+++ b/src/Lucene.Net.Core/Support/NumberExtensionMethods.cs
@@ -67,25 +67,35 @@ namespace Lucene.Net.Support
 
             public static int Position(long value)
             {
-
-                var result = unchecked((uint) (value & -value)*0x022fdd63cc95386d) >>
58;
-                return POSITIONS[result];
+                var v = value;
+                
+                return POSITIONS[(v & -v) * 0x022fdd63cc95386d >> 58];
             }
         }
 
 
+        /// <summary>
+        /// Returns the leading zeros from the value.
+        /// </summary>
+        /// <param name="value">The value.</param>
+        /// <returns>System.Int32.</returns>
         public static int NumberOfLeadingZeros(this long value)
         {
             return (int) NumberOfLeadingZeros((ulong) value);
         }
 
+        /// <summary>
+        /// Returns the leading zeros from the value.
+        /// </summary>
+        /// <param name="value">The value.</param>
+        /// <returns>System.UInt32.</returns>
          [CLSCompliant(false)]
         public static uint NumberOfLeadingZeros(this ulong value)
         {
             if (value == 0)
                 return 64;
             uint number = 1;
-            var test = (uint)value >> 32;
+            var test = value >> 32;
 
 
             if (test == 0)
@@ -117,21 +127,32 @@ namespace Lucene.Net.Support
                 number += 2;
                 test <<= 2;
             }
-            number -= test >> 31;
+            number -= (uint)test >> 31;
 
             return number;
         }
 
+         /// <summary>
+         /// Returns the leading zeros from the value. Similar to __lzcnt in 
+         /// </summary>
+         /// <param name="value">The value.</param>
+         /// <returns>System.Int32.</returns>
         public static int NumberOfLeadingZeros(this int value)
         {
             return (int) NumberOfLeadingZeros((uint) value);
         }
 
+
+        /// <summary>
+        /// Returns the leading zeros from the value.
+        /// </summary>
+        /// <param name="value">The value.</param>
+        /// <returns>System.UInt32.</returns>
         [CLSCompliant(false)]
         public static uint NumberOfLeadingZeros(this uint value)
         {
             // from hacker's delight
-            http: //www.hackersdelight.org/permissions.htm
+            // http://www.hackersdelight.org/permissions.htm
             uint test, number;
             uint x = value;
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b3180421/src/Lucene.Net.Core/Util/CharsRefBuilder.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/CharsRefBuilder.cs b/src/Lucene.Net.Core/Util/CharsRefBuilder.cs
index bc51157..16a96aa 100644
--- a/src/Lucene.Net.Core/Util/CharsRefBuilder.cs
+++ b/src/Lucene.Net.Core/Util/CharsRefBuilder.cs
@@ -202,10 +202,10 @@ namespace Lucene.Net.Util
         /// <summary>
         /// Resizes and increases the length of the reference array.
         /// </summary>
-        /// <param name="mininumSize">The minimum size to grow the array.</param>
-        public void Grow(int mininumSize)
+        /// <param name="minimumSize">The minimum size to grow the array.</param>
+        public void Grow(int minimumSize)
         {
-            this.charsRef.Chars = ArrayUtil.Grow(this.charsRef.Chars, mininumSize);
+            this.charsRef.Chars = ArrayUtil.Grow(this.charsRef.Chars, minimumSize);
         }
 
         /// <inherits />
@@ -245,5 +245,7 @@ namespace Lucene.Net.Util
             return this.charsRef.GetEnumerator();
         }
         #endregion
+
+        public int minimumSize { get; set; }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b3180421/test/Lucene.Net.Core.Tests/Lucene.Net.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/test/Lucene.Net.Core.Tests/Lucene.Net.Core.Tests.csproj b/test/Lucene.Net.Core.Tests/Lucene.Net.Core.Tests.csproj
index 52d924a..54711db 100644
--- a/test/Lucene.Net.Core.Tests/Lucene.Net.Core.Tests.csproj
+++ b/test/Lucene.Net.Core.Tests/Lucene.Net.Core.Tests.csproj
@@ -59,6 +59,7 @@
   <ItemGroup>
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Support\ICloneableTests.cs" />
+    <Compile Include="Support\TestNumberExtensionMethods.cs" />
     <Compile Include="Util\BaseSorterTestCase.cs" />
     <Compile Include="Util\TestArrayUtil.cs" />
     <Compile Include="Util\TestBits.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b3180421/test/Lucene.Net.Core.Tests/Support/TestNumberExtensionMethods.cs
----------------------------------------------------------------------
diff --git a/test/Lucene.Net.Core.Tests/Support/TestNumberExtensionMethods.cs b/test/Lucene.Net.Core.Tests/Support/TestNumberExtensionMethods.cs
new file mode 100644
index 0000000..d931fb0
--- /dev/null
+++ b/test/Lucene.Net.Core.Tests/Support/TestNumberExtensionMethods.cs
@@ -0,0 +1,43 @@
+´╗┐using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lucene.Net.Support
+{
+    using Util;
+
+    public class TestNumberExtensionMethods : LuceneTestCase
+    {
+
+        [Test]
+        public void NumberOfLeadingZerosForInt()
+        {
+            Equal(32, 0x0.NumberOfLeadingZeros());
+            Equal(24, 0xff.NumberOfLeadingZeros());
+        }
+
+        [Test]
+        public void NumberOfLeadingZerosForLong()
+        {
+            Equal(64, ((long)0x0).NumberOfLeadingZeros());
+            Equal(56, ((long)0xff).NumberOfLeadingZeros());
+        }
+
+        [Test]
+        public void NumberOfTrailingZerosForInt()
+        {
+            Equal(4, 10000.NumberOfTrailingZeros());
+            Equal(6, 1000000.NumberOfTrailingZeros());
+        }
+
+
+        [Test]
+        public void NumberOfTrailingZerosForLong()
+        {
+            Equal(3, 1000L.NumberOfTrailingZeros());
+            Equal(5, 100000L.NumberOfTrailingZeros());
+        }
+    }
+}


Mime
View raw message