Skip to content

Commit f527600

Browse files
committed
Merge branch 'feature/netstandard2'
2 parents 777f564 + 75a8983 commit f527600

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

CardinalityEstimation/CardinalityEstimation.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
3+
<TargetFrameworks>net9.0;net8.0;netstandard2.0</TargetFrameworks>
4+
<LangVersion>latest</LangVersion>
45
<Configurations>Debug;Release;Release-Signed</Configurations>
56
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
67
<PackageId Condition=" '$(Configuration)' == 'Release-Signed' ">CardinalityEstimation.Signed</PackageId>

CardinalityEstimation/CardinalityEstimator.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace CardinalityEstimation
2727
{
2828
using System;
2929
using System.Collections.Generic;
30+
using System.Numerics;
3031
using System.Text;
3132
using Hash;
3233

@@ -214,8 +215,8 @@ internal CardinalityEstimator(GetHashCodeDelegate hashFunction, CardinalityEstim
214215
this.hashFunction = hashFunction;
215216
if (this.hashFunction == null)
216217
{
217-
this.hashFunction = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x));
218-
this.hashFunctionSpan = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x));
218+
this.hashFunction = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x), 0);
219+
this.hashFunctionSpan = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x), 0);
219220
}
220221
else
221222
{
@@ -237,8 +238,8 @@ internal CardinalityEstimator(GetHashCodeSpanDelegate hashFunctionSpan, Cardinal
237238
this.hashFunctionSpan = hashFunctionSpan;
238239
if (this.hashFunctionSpan == null)
239240
{
240-
this.hashFunction = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x));
241-
this.hashFunctionSpan = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x));
241+
this.hashFunction = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x), 0);
242+
this.hashFunctionSpan = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x), 0);
242243
}
243244
else
244245
{
@@ -846,7 +847,7 @@ public static byte GetSigma(ulong hash, byte bitsToCount)
846847
int knownZeros = 64 - bitsToCount;
847848

848849
var masked = hash & mask;
849-
var leadingZeros = (byte)ulong.LeadingZeroCount(masked);
850+
var leadingZeros = (byte)BitOperations.LeadingZeroCount(masked);
850851
return (byte)(leadingZeros - knownZeros + 1);
851852
}
852853

CardinalityEstimation/ConcurrentCardinalityEstimator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public ConcurrentCardinalityEstimator(CardinalityEstimator other)
168168
lockSlim = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
169169

170170
// Init the hash function - use default since we can't get it from the other estimator
171-
hashFunction = ((x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x)));
171+
hashFunction = ((x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x), 0));
172172

173173
sparseMaxElements = Math.Max(0, (m / 15) - 10);
174174

@@ -217,8 +217,8 @@ internal ConcurrentCardinalityEstimator(GetHashCodeDelegate hashFunction, Cardin
217217
this.hashFunction = hashFunction;
218218
if (this.hashFunction == null)
219219
{
220-
this.hashFunction = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x));
221-
this.hashFunctionSpan = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x));
220+
this.hashFunction = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x), 0);
221+
this.hashFunctionSpan = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x), 0);
222222
}
223223
else
224224
{
@@ -237,8 +237,8 @@ internal ConcurrentCardinalityEstimator(GetHashCodeSpanDelegate hashFunctionSpan
237237
this.hashFunctionSpan = hashFunctionSpan;
238238
if (this.hashFunction == null)
239239
{
240-
this.hashFunction = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x));
241-
this.hashFunctionSpan = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x));
240+
this.hashFunction = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x), 0);
241+
this.hashFunctionSpan = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x), 0);
242242
}
243243
}
244244

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#if !NETCOREAPP3_0_OR_GREATER
2+
namespace System.Numerics;
3+
4+
public static class BitOperations
5+
{
6+
public static uint LeadingZeroCount(ulong x)
7+
{
8+
x |= x >> 1;
9+
x |= x >> 2;
10+
x |= x >> 4;
11+
x |= x >> 8;
12+
x |= x >> 16;
13+
x |= x >> 32;
14+
15+
x -= x >> 1 & 0x5555555555555555;
16+
x = (x >> 2 & 0x3333333333333333) + (x & 0x3333333333333333);
17+
x = (x >> 4) + x & 0x0f0f0f0f0f0f0f0f;
18+
x += x >> 8;
19+
x += x >> 16;
20+
x += x >> 32;
21+
22+
const int numLongBits = sizeof(long) * 8;
23+
return numLongBits - (uint)(x & 0x0000007f);
24+
}
25+
}
26+
#endif
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#if !NETCOREAPP2_1_OR_GREATER
2+
using System.Collections.Generic;
3+
4+
namespace System.Linq;
5+
6+
public static class LinqExtensions
7+
{
8+
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
9+
{
10+
return new(source);
11+
}
12+
}
13+
#endif

0 commit comments

Comments
 (0)