Skip to content

Commit

Permalink
Merge pull request #7 from ming4883/master
Browse files Browse the repository at this point in the history
Fixing compile errors and better .NET20 build support
  • Loading branch information
noricube authored Dec 19, 2017
2 parents 3e24b34 + 77ec2fe commit 3ab59c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion xxHashSharp.Net20.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30110.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xxHashSharp", "xxHashSharp\xxHashSharp.Net20.csproj", "{9AC2E740-AA2F-41A8-81C2-AF2E182F9D16}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xxHashSharp", "xxHashSharp.Net20\xxHashSharp.Net20.csproj", "{9AC2E740-AA2F-41A8-81C2-AF2E182F9D16}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Compile Include="..\xxHashSharp\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\xxHashSharp\xxHash.cs">
<Link>xxHash.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="xxHash.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Reference Include="System">
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
21 changes: 11 additions & 10 deletions xxHashSharp/xxHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
*/

using System;
using System.IO;

namespace xxHashSharp
{
Expand Down Expand Up @@ -140,10 +141,10 @@ public static uint CalculateHash(Stream stream, long len = -1, uint seed = 0)
if (len >= 16)
{
var limit = len - 16;
var v1 = seed + Prime321 + Prime322;
var v2 = seed + Prime322;
var v1 = seed + PRIME32_1 + PRIME32_2;
var v2 = seed + PRIME32_2;
var v3 = seed + 0;
var v4 = seed - Prime321;
var v4 = seed - PRIME32_1;

do
{
Expand All @@ -166,7 +167,7 @@ public static uint CalculateHash(Stream stream, long len = -1, uint seed = 0)
}
else
{
h32 = seed + Prime325;
h32 = seed + PRIME32_5;
}

h32 += (uint)len;
Expand All @@ -175,26 +176,26 @@ public static uint CalculateHash(Stream stream, long len = -1, uint seed = 0)
while (index <= len - 4)
{
stream.Read(buffer, 0, buffer.Length);
h32 += BitConverter.ToUInt32(buffer, 0) * Prime323;
h32 = RotateLeft(h32, 17) * Prime324;
h32 += BitConverter.ToUInt32(buffer, 0) * PRIME32_3;
h32 = RotateLeft(h32, 17) * PRIME32_4;
index += 4;
}

buffer = new byte[1];
while (index < len)
{
stream.Read(buffer, 0, buffer.Length);
h32 += buffer[0] * Prime325;
h32 = RotateLeft(h32, 11) * Prime321;
h32 += buffer[0] * PRIME32_5;
h32 = RotateLeft(h32, 11) * PRIME32_1;
index++;
}

stream.Seek(streamPosition, SeekOrigin.Begin);

h32 ^= h32 >> 15;
h32 *= Prime322;
h32 *= PRIME32_2;
h32 ^= h32 >> 13;
h32 *= Prime323;
h32 *= PRIME32_3;
h32 ^= h32 >> 16;

return h32;
Expand Down

0 comments on commit 3ab59c6

Please sign in to comment.