You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by do...@apache.org on 2009/07/30 02:14:14 UTC
svn commit: r799135 - in /incubator/lucene.net/trunk/C#/src:
Lucene.Net/Store/CheckSumIndexInput.cs
Lucene.Net/Store/CheckSumIndexOutput.cs Lucene.Net/SupportClass.cs
Test/Test-VS2005.csproj Test/TestSupportClass.cs
Author: dougsale
Date: Thu Jul 30 00:14:14 2009
New Revision: 799135
URL: http://svn.apache.org/viewvc?rev=799135&view=rev
Log:
Implemented Java version of CRC32 in SupportClass, tested in new test and updated CheckSumIndexInput/Output
Added:
incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs
Modified:
incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/CheckSumIndexInput.cs
incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/CheckSumIndexOutput.cs
incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
incubator/lucene.net/trunk/C#/src/Test/Test-VS2005.csproj
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/CheckSumIndexInput.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/CheckSumIndexInput.cs?rev=799135&r1=799134&r2=799135&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/CheckSumIndexInput.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/CheckSumIndexInput.cs Thu Jul 30 00:14:14 2009
@@ -15,6 +15,9 @@
* limitations under the License.
*/
+using Checksum = SupportClass.Checksum;
+using CRC32 = SupportClass.CRC32;
+
namespace Lucene.Net.Store
{
@@ -23,31 +26,30 @@
public class ChecksumIndexInput : IndexInput
{
IndexInput main;
- //Checksum digest;
+ Checksum digest;
public ChecksumIndexInput(IndexInput main)
{
this.main = main;
- //digest = new CRC32();
+ digest = new CRC32();
}
public override byte ReadByte()
{
byte b = main.ReadByte();
- //digest.update(b);
+ digest.update(b);
return b;
}
public override void ReadBytes(byte[] b, int offset, int len)
{
main.ReadBytes(b, offset, len);
- //digest.update(b, offset, len);
+ digest.update(b, offset, len);
}
public long GetChecksum()
{
- return 0;
- //return digest.getValue();
+ return digest.getValue();
}
public override void Close()
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/CheckSumIndexOutput.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/CheckSumIndexOutput.cs?rev=799135&r1=799134&r2=799135&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/CheckSumIndexOutput.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/CheckSumIndexOutput.cs Thu Jul 30 00:14:14 2009
@@ -14,6 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+using Checksum = SupportClass.Checksum;
+using CRC32 = SupportClass.CRC32;
namespace Lucene.Net.Store
{
@@ -23,30 +25,29 @@
public class ChecksumIndexOutput : IndexOutput
{
IndexOutput main;
- //Checksum digest;
+ Checksum digest;
public ChecksumIndexOutput(IndexOutput main)
{
this.main = main;
- //digest = new CRC32();
+ digest = new CRC32();
}
public override void WriteByte(byte b)
{
- //digest.update(b);
+ digest.update(b);
main.WriteByte(b);
}
public override void WriteBytes(byte[] b, int offset, int length)
{
- //digest.update(b, offset, length);
+ digest.update(b, offset, length);
main.WriteBytes(b, offset, length);
}
public long GetChecksum()
{
- return 0;
- //return digest.getValue();
+ return digest.getValue();
}
public override void Flush()
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?rev=799135&r1=799134&r2=799135&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs Thu Jul 30 00:14:14 2009
@@ -35,6 +35,70 @@
/// </summary>
public class SupportClass
{
+ public interface Checksum
+ {
+ void reset();
+ void update(int b);
+ void update(byte[] b);
+ void update(byte[] b, int offset, int length);
+ Int64 getValue();
+ }
+
+ public class CRC32 : Checksum
+ {
+ private static readonly UInt32[] crcTable = InitializeCRCTable();
+
+ private static UInt32[] InitializeCRCTable()
+ {
+ UInt32[] crcTable = new UInt32[256];
+ for (UInt32 n = 0; n < 256; n++)
+ {
+ UInt32 c = n;
+ for (int k = 8; --k >= 0; )
+ {
+ if ((c & 1) != 0)
+ c = 0xedb88320 ^ (c >> 1);
+ else
+ c = c >> 1;
+ }
+ crcTable[n] = c;
+ }
+ return crcTable;
+ }
+
+ private UInt32 crc = 0;
+
+ public Int64 getValue()
+ {
+ return (Int64)crc & 0xffffffffL;
+ }
+
+ public void reset()
+ {
+ crc = 0;
+ }
+
+ public void update(int bval)
+ {
+ UInt32 c = ~crc;
+ c = crcTable[(c ^ bval) & 0xff] ^ (c >> 8);
+ crc = ~c;
+ }
+
+ public void update(byte[] buf, int off, int len)
+ {
+ UInt32 c = ~crc;
+ while (--len >= 0)
+ c = crcTable[(c ^ buf[off++]) & 0xff] ^ (c >> 8);
+ crc = ~c;
+ }
+
+ public void update(byte[] buf)
+ {
+ update(buf, 0, buf.Length);
+ }
+ }
+
public class TextSupport
{
/// <summary>
Modified: incubator/lucene.net/trunk/C#/src/Test/Test-VS2005.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Test-VS2005.csproj?rev=799135&r1=799134&r2=799135&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Test-VS2005.csproj (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Test-VS2005.csproj Thu Jul 30 00:14:14 2009
@@ -432,6 +432,7 @@
<Compile Include="Util\TestStringHelper.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="TestSupportClass.cs" />
<Compile Include="Util\_TestUtil.cs">
<SubType>Code</SubType>
</Compile>
Added: incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestSupportClass.cs?rev=799135&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs Thu Jul 30 00:14:14 2009
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+using NUnit.Framework;
+
+
+/// <summary>
+/// </summary>
+[TestFixture]
+public class TestSupportClass
+{
+ /// <summary></summary>
+ /// <throws></throws>
+ [Test]
+ public virtual void TestCRC32()
+ {
+ byte[] b = new byte[256];
+ for (int i = 0; i < b.Length; i++)
+ b[i] = (byte)i;
+
+ SupportClass.Checksum digest = new SupportClass.CRC32();
+ digest.update(b, 0, b.Length);
+
+ Int64 expected = 688229491;
+ Assert.AreEqual(expected, digest.getValue());
+ }
+}