Skip to content

Commit 0b3d287

Browse files
committed
Cleanup
1 parent 58943a7 commit 0b3d287

131 files changed

Lines changed: 575 additions & 712 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Locals/Directory.Packages.props

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22

33
<ItemGroup>
4+
<PackageVersion Include="AgileObjects.ReadableExpressions" Version="4.1.3" />
5+
<PackageVersion Include="Docker.DotNet" Version="3.125.15" />
6+
<PackageVersion Include="Genbox.FastData.SourceGenerator" Version="0.2.0" />
47
<PackageVersion Include="Genbox.FastFilter" Version="1.0.0-alpha.1" />
58
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0-2.final" />
6-
<PackageVersion Include="System.Memory" Version="4.6.3" />
9+
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="4.14.0" />
10+
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.3" />
11+
<PackageVersion Include="Mono.TextTemplating" Version="3.0.0" />
12+
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
13+
<PackageVersion Include="Serilog.Expressions" Version="5.0.0" />
14+
<PackageVersion Include="Serilog.Extensions.Logging" Version="10.0.0" />
15+
<PackageVersion Include="Serilog.Sinks.File" Version="7.0.0" />
716
<PackageVersion Include="Spectre.Console" Version="0.54.0" />
817
<PackageVersion Include="System.CommandLine" Version="2.0.3" />
918
<PackageVersion Include="System.Linq.Async" Version="7.0.0" />
19+
<PackageVersion Include="System.Memory" Version="4.6.3" />
1020
<PackageVersion Include="Verify.DiffPlex" Version="3.1.2" />
1121
<PackageVersion Include="Verify.XunitV3" Version="31.13.2" />
12-
<PackageVersion Include="AgileObjects.ReadableExpressions" Version="4.1.3" />
13-
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.3" />
14-
<PackageVersion Include="Serilog.Expressions" Version="5.0.0" />
15-
<PackageVersion Include="Serilog.Extensions.Logging" Version="10.0.0" />
16-
<PackageVersion Include="Serilog.Sinks.File" Version="7.0.0" />
17-
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
18-
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="4.14.0" />
19-
<PackageVersion Include="Genbox.FastData.SourceGenerator" Version="0.2.0" />
2022
<PackageVersion Include="xunit.v3.extensibility.core" Version="3.2.2" />
21-
<PackageVersion Include="Mono.TextTemplating" Version="3.0.0" />
22-
<PackageVersion Include="Docker.DotNet" Version="3.125.15" />
2323
</ItemGroup>
2424
</Project>

Src/FastData.Benchmarks/Benchmarks/CaseInsensitiveComparerBenchmarks.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using System.Runtime.CompilerServices;
23
using System.Runtime.InteropServices;
34
using System.Runtime.Intrinsics;
45
using System.Runtime.Intrinsics.X86;
56

67
namespace Genbox.FastData.Benchmarks.Benchmarks;
78

9+
[SuppressMessage("ReSharper", "ConvertToConstant.Local")]
10+
[SuppressMessage("ReSharper", "FieldCanBeMadeReadOnly.Local")]
811
public class CaseInsensitiveComparerBenchmarks
912
{
10-
private static string _target = "thisismystringwithcasing";
11-
private static string _myString = "ThisIsMyStringWithCasing";
1213
private const int TargetLength = 24;
14+
private string _target = "thisismystringwithcasing";
15+
private string _myString = "ThisIsMyStringWithCasing";
16+
17+
private static readonly byte[] Downcase =
18+
[
19+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
20+
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
21+
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
22+
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
23+
60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
24+
107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
25+
122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
26+
105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
27+
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
28+
135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
29+
150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
30+
165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
31+
180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
32+
195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
33+
210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
34+
225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
35+
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
36+
255
37+
];
1338

1439
[Benchmark]public bool WithKeyNormalization() => _myString.ToLowerInvariant() == _target;
1540
[Benchmark]public bool WithComparer() => StringComparer.OrdinalIgnoreCase.Equals(_myString, _target);
@@ -284,26 +309,4 @@ private static unsafe bool OptimizedCaseSensitive(string s1, string s2)
284309
return false;
285310
}
286311
}
287-
288-
private static readonly byte[] Downcase =
289-
[
290-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
291-
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
292-
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
293-
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
294-
60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
295-
107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
296-
122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
297-
105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
298-
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
299-
135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
300-
150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
301-
165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
302-
180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
303-
195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
304-
210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
305-
225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
306-
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
307-
255
308-
];
309312
}

Src/FastData.Benchmarks/Benchmarks/EarlyExitVsLookup.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
13
namespace Genbox.FastData.Benchmarks.Benchmarks;
24

35
/// <summary>Benchmarks where the threshold usually is between a full hash/lookup in a HashSet vs. how long a prefix/suffix early exit can be before it no longer makes sense</summary>
6+
[SuppressMessage("ReSharper", "ConvertToConstant.Local")]
7+
[SuppressMessage("ReSharper", "FieldCanBeMadeReadOnly.Local")]
48
public class EarlyExitVsLookup
59
{
610
private static string _myStr = "hello world";

Src/FastData.Benchmarks/Benchmarks/FastModBenchmarks.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using System.Runtime.CompilerServices;
23
using Genbox.FastData.Generators.Helpers;
34

45
namespace Genbox.FastData.Benchmarks.Benchmarks;
56

67
/// <summary>Benchmarks the difference between normal modulus and FastMod</summary>
8+
[SuppressMessage("ReSharper", "ConvertToConstant.Local")]
79
public class FastModBenchmarks
810
{
9-
private readonly uint _value = 3_000_000_000; //Note: Do not make this const!
10-
private readonly ushort _mod = 1024; //Note: Do not make this const!
1111
private const ushort _modConst = 1024;
12+
private readonly ushort _mod = 1024; //Note: Do not make this const!
1213

1314
private readonly ulong _mult = MathHelper.GetFastModMultiplier(int.MaxValue);
1415
private readonly uint _mult2 = GetFastModMultiplierSmall(3000);
16+
private readonly uint _value = 3_000_000_000; //Note: Do not make this const!
1517

1618
[Benchmark]
1719
public uint Const() => _value % 1024;

Src/FastData.Benchmarks/Benchmarks/NumericEarlyExitBenchmarks.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using System.Runtime.Intrinsics;
23
using System.Runtime.Intrinsics.X86;
34

45
namespace Genbox.FastData.Benchmarks.Benchmarks;
56

67
[DisassemblyDiagnoser]
8+
[SuppressMessage("ReSharper", "FieldCanBeMadeReadOnly.Local")]
79
public class NumericEarlyExitBenchmarks
810
{
911
private int _min = 3;

Src/FastData.Benchmarks/Benchmarks/PriorityStructureBenchmarks.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,28 @@ public void Cleanup()
2323
public void MinHeapTest()
2424
{
2525
for (double i = 0; i < 100; i++)
26-
{
2726
_heap.Add(i, true);
28-
}
2927
}
3028

3129
[Benchmark]
3230
public void RingBufferTest()
3331
{
3432
for (double i = 0; i < 100; i++)
35-
{
3633
_buffer.Add(i);
37-
}
3834
}
3935

4036
[Benchmark]
4137
public void FixedSetTest()
4238
{
4339
for (double i = 0; i < 100; i++)
44-
{
4540
_fixedSet.Add(i);
46-
}
4741
}
4842

4943
[Benchmark]
5044
public void SortedSetTest()
5145
{
5246
for (double i = 0; i < 100; i++)
53-
{
5447
_sorted.Add(i);
55-
}
5648
}
5749

5850
private sealed class FixedSet(int capacity)

Src/FastData.Benchmarks/Benchmarks/StringEarlyExitBenchmarks.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
13
namespace Genbox.FastData.Benchmarks.Benchmarks;
24

35
[DisassemblyDiagnoser]
6+
[SuppressMessage("ReSharper", "ConvertToConstant.Local")]
7+
[SuppressMessage("ReSharper", "FieldCanBeMadeReadOnly.Local")]
48
public class StringEarlyExitBenchmarks
59
{
610
private string _value = "hello world";

Src/FastData.Benchmarks/Benchmarks/StringHashBenchmarks.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ public ulong XXHashTest()
4242
ulong value = 0;
4343

4444
foreach (string s in _array)
45-
{
4645
value += XxHash.ComputeHash(s);
47-
}
4846

4947
return value;
5048
}
@@ -69,7 +67,7 @@ private static uint ComputeHash(ref char ptr, int length, ulong seed = PRIME64_5
6967
while (length >= 4)
7068
{
7169
hash1 ^= Round(0, ptr64);
72-
hash1 = RotateLeft(hash1, 27) * PRIME64_1 + PRIME64_4;
70+
hash1 = (RotateLeft(hash1, 27) * PRIME64_1) + PRIME64_4;
7371
ptr64 = ref Unsafe.Add(ref ptr64, 1);
7472
length -= 4;
7573
}

Src/FastData.Benchmarks/Benchmarks/StringVsBytesBenchmarks.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ public int GetHashCode(byte[]? obj)
7575
{
7676
int hash = 17;
7777
foreach (byte b in obj)
78-
{
79-
hash = hash * 31 + b;
80-
}
78+
hash = (hash * 31) + b;
8179
return hash;
8280
}
8381
}

Src/FastData.Benchmarks/Benchmarks/TimeComplexity.cs

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Numerics;
12
using System.Runtime.Intrinsics;
23
using System.Runtime.Intrinsics.X86;
34

@@ -8,9 +9,9 @@ public class TimeComplexity
89
private int[] _data = null!;
910
private int[] _eytzinger = null!;
1011
private HashSet<int> _hashSet = null!;
11-
private int[] _k16Keys = null!;
1212
private int[] _k16Children = null!;
1313
private byte[] _k16KeyCounts = null!;
14+
private int[] _k16Keys = null!;
1415

1516
[Params(1, 50, 100)]
1617
public int Query { get; set; }
@@ -50,10 +51,10 @@ private static void BuildEytzinger(int[] sorted, int[] eytzinger, int node, ref
5051
if (node >= eytzinger.Length)
5152
return;
5253

53-
BuildEytzinger(sorted, eytzinger, node * 2 + 1, ref index);
54+
BuildEytzinger(sorted, eytzinger, (node * 2) + 1, ref index);
5455
eytzinger[node] = sorted[index];
5556
index++;
56-
BuildEytzinger(sorted, eytzinger, node * 2 + 2, ref index);
57+
BuildEytzinger(sorted, eytzinger, (node * 2) + 2, ref index);
5758
}
5859

5960
private static int EytzingerSearch(int[] eytzinger, int value)
@@ -68,7 +69,7 @@ private static int EytzingerSearch(int[] eytzinger, int value)
6869
if (value == current)
6970
return node;
7071

71-
node = value < current ? node * 2 + 1 : node * 2 + 2;
72+
node = value < current ? (node * 2) + 1 : (node * 2) + 2;
7273
}
7374

7475
return -1;
@@ -87,7 +88,7 @@ private static int InterpolationSearch(int[] sorted, int value)
8788
if (lowValue == highValue)
8889
return value == lowValue ? low : -1;
8990

90-
int pos = low + (int)((long)(value - lowValue) * (high - low) / (highValue - lowValue));
91+
int pos = low + (int)(((long)(value - lowValue) * (high - low)) / (highValue - lowValue));
9192
int current = sorted[pos];
9293

9394
if (current == value)
@@ -243,41 +244,41 @@ private static int K16SearchBranchlessUnrolled(int[] keys, int[] children, int v
243244
int k15 = keys[keyBase + 15];
244245

245246
int eq = (value == k0 ? 1 : 0)
246-
| (value == k1 ? 1 : 0)
247-
| (value == k2 ? 1 : 0)
248-
| (value == k3 ? 1 : 0)
249-
| (value == k4 ? 1 : 0)
250-
| (value == k5 ? 1 : 0)
251-
| (value == k6 ? 1 : 0)
252-
| (value == k7 ? 1 : 0)
253-
| (value == k8 ? 1 : 0)
254-
| (value == k9 ? 1 : 0)
255-
| (value == k10 ? 1 : 0)
256-
| (value == k11 ? 1 : 0)
257-
| (value == k12 ? 1 : 0)
258-
| (value == k13 ? 1 : 0)
259-
| (value == k14 ? 1 : 0)
260-
| (value == k15 ? 1 : 0);
247+
| (value == k1 ? 1 : 0)
248+
| (value == k2 ? 1 : 0)
249+
| (value == k3 ? 1 : 0)
250+
| (value == k4 ? 1 : 0)
251+
| (value == k5 ? 1 : 0)
252+
| (value == k6 ? 1 : 0)
253+
| (value == k7 ? 1 : 0)
254+
| (value == k8 ? 1 : 0)
255+
| (value == k9 ? 1 : 0)
256+
| (value == k10 ? 1 : 0)
257+
| (value == k11 ? 1 : 0)
258+
| (value == k12 ? 1 : 0)
259+
| (value == k13 ? 1 : 0)
260+
| (value == k14 ? 1 : 0)
261+
| (value == k15 ? 1 : 0);
261262

262263
if (eq != 0)
263264
return node;
264265

265266
int childSlot = (value > k0 ? 1 : 0)
266-
+ (value > k1 ? 1 : 0)
267-
+ (value > k2 ? 1 : 0)
268-
+ (value > k3 ? 1 : 0)
269-
+ (value > k4 ? 1 : 0)
270-
+ (value > k5 ? 1 : 0)
271-
+ (value > k6 ? 1 : 0)
272-
+ (value > k7 ? 1 : 0)
273-
+ (value > k8 ? 1 : 0)
274-
+ (value > k9 ? 1 : 0)
275-
+ (value > k10 ? 1 : 0)
276-
+ (value > k11 ? 1 : 0)
277-
+ (value > k12 ? 1 : 0)
278-
+ (value > k13 ? 1 : 0)
279-
+ (value > k14 ? 1 : 0)
280-
+ (value > k15 ? 1 : 0);
267+
+ (value > k1 ? 1 : 0)
268+
+ (value > k2 ? 1 : 0)
269+
+ (value > k3 ? 1 : 0)
270+
+ (value > k4 ? 1 : 0)
271+
+ (value > k5 ? 1 : 0)
272+
+ (value > k6 ? 1 : 0)
273+
+ (value > k7 ? 1 : 0)
274+
+ (value > k8 ? 1 : 0)
275+
+ (value > k9 ? 1 : 0)
276+
+ (value > k10 ? 1 : 0)
277+
+ (value > k11 ? 1 : 0)
278+
+ (value > k12 ? 1 : 0)
279+
+ (value > k13 ? 1 : 0)
280+
+ (value > k14 ? 1 : 0)
281+
+ (value > k15 ? 1 : 0);
281282

282283
node = children[childBase + childSlot];
283284
}
@@ -369,9 +370,9 @@ private static int K16SearchSimd128(int[] keys, int[] children, int value)
369370
Vector128<int> eq3 = Sse2.CompareEqual(valueVector, v3);
370371

371372
ulong eqMask = (ulong)Sse2.MoveMask(eq0.AsByte())
372-
| ((ulong)Sse2.MoveMask(eq1.AsByte()) << 16)
373-
| ((ulong)Sse2.MoveMask(eq2.AsByte()) << 32)
374-
| ((ulong)Sse2.MoveMask(eq3.AsByte()) << 48);
373+
| ((ulong)Sse2.MoveMask(eq1.AsByte()) << 16)
374+
| ((ulong)Sse2.MoveMask(eq2.AsByte()) << 32)
375+
| ((ulong)Sse2.MoveMask(eq3.AsByte()) << 48);
375376

376377
if (eqMask != 0)
377378
return node;
@@ -386,10 +387,10 @@ private static int K16SearchSimd128(int[] keys, int[] children, int value)
386387
uint mask2 = (uint)Sse2.MoveMask(gt2.AsByte());
387388
uint mask3 = (uint)Sse2.MoveMask(gt3.AsByte());
388389

389-
int childSlot = (System.Numerics.BitOperations.PopCount(mask0)
390-
+ System.Numerics.BitOperations.PopCount(mask1)
391-
+ System.Numerics.BitOperations.PopCount(mask2)
392-
+ System.Numerics.BitOperations.PopCount(mask3)) / 4;
390+
int childSlot = (BitOperations.PopCount(mask0)
391+
+ BitOperations.PopCount(mask1)
392+
+ BitOperations.PopCount(mask2)
393+
+ BitOperations.PopCount(mask3)) / 4;
393394

394395
node = children[childBase + childSlot];
395396
}
@@ -416,7 +417,7 @@ private static int K16SearchSimd256(int[] keys, int[] children, int value)
416417
Vector256<int> eq0 = Avx2.CompareEqual(valueVector, v0);
417418
Vector256<int> eq1 = Avx2.CompareEqual(valueVector, v1);
418419
ulong eqMask = (ulong)Avx2.MoveMask(eq0.AsByte())
419-
| ((ulong)Avx2.MoveMask(eq1.AsByte()) << 32);
420+
| ((ulong)Avx2.MoveMask(eq1.AsByte()) << 32);
420421

421422
if (eqMask != 0)
422423
return node;
@@ -426,8 +427,8 @@ private static int K16SearchSimd256(int[] keys, int[] children, int value)
426427
uint mask0 = (uint)Avx2.MoveMask(gt0.AsByte());
427428
uint mask1 = (uint)Avx2.MoveMask(gt1.AsByte());
428429

429-
int childSlot = (System.Numerics.BitOperations.PopCount(mask0)
430-
+ System.Numerics.BitOperations.PopCount(mask1)) / 4;
430+
int childSlot = (BitOperations.PopCount(mask0)
431+
+ BitOperations.PopCount(mask1)) / 4;
431432

432433
node = children[childBase + childSlot];
433434
}

0 commit comments

Comments
 (0)