Skip to content

Commit b425952

Browse files
committed
Rename IsContiguous to IsConsecutive for consistency
1 parent 93f6ffa commit b425952

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

Src/FastData.Tests/KeyAnalyzerTests.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,40 @@ namespace Genbox.FastData.Tests;
77
public class KeyAnalyzerTests
88
{
99
[Fact]
10-
public void GetProperties_IsContiguous_AllPrimitiveTypes()
10+
public void GetProperties_IsConsecutive_Test()
1111
{
12-
Assert.True(GetProperties(['a', 'b', 'c']).IsContiguous);
13-
Assert.False(GetProperties(['a', 'c']).IsContiguous);
12+
Assert.True(GetProperties(['a', 'b', 'c']).IsConsecutive);
13+
Assert.False(GetProperties(['a', 'c']).IsConsecutive);
1414

15-
Assert.True(GetProperties(new sbyte[] { -1, 0, 1 }).IsContiguous);
16-
Assert.False(GetProperties(new sbyte[] { -1, 1, 2 }).IsContiguous);
15+
Assert.True(GetProperties(new sbyte[] { -1, 0, 1 }).IsConsecutive);
16+
Assert.False(GetProperties(new sbyte[] { -1, 1, 2 }).IsConsecutive);
1717

18-
Assert.True(GetProperties(new byte[] { 1, 2, 3 }).IsContiguous);
19-
Assert.False(GetProperties(new byte[] { 1, 3, 4 }).IsContiguous);
18+
Assert.True(GetProperties(new byte[] { 1, 2, 3 }).IsConsecutive);
19+
Assert.False(GetProperties(new byte[] { 1, 3, 4 }).IsConsecutive);
2020

21-
Assert.True(GetProperties(new short[] { 10, 11, 12 }).IsContiguous);
22-
Assert.False(GetProperties(new short[] { 10, 11, 13 }).IsContiguous);
21+
Assert.True(GetProperties(new short[] { 10, 11, 12 }).IsConsecutive);
22+
Assert.False(GetProperties(new short[] { 10, 11, 13 }).IsConsecutive);
2323

24-
Assert.True(GetProperties(new ushort[] { 10, 11, 12 }).IsContiguous);
25-
Assert.False(GetProperties(new ushort[] { 10, 11, 13 }).IsContiguous);
24+
Assert.True(GetProperties(new ushort[] { 10, 11, 12 }).IsConsecutive);
25+
Assert.False(GetProperties(new ushort[] { 10, 11, 13 }).IsConsecutive);
2626

27-
Assert.True(GetProperties([100, 101]).IsContiguous);
28-
Assert.False(GetProperties([100, 102]).IsContiguous);
27+
Assert.True(GetProperties([100, 101]).IsConsecutive);
28+
Assert.False(GetProperties([100, 102]).IsConsecutive);
2929

30-
Assert.True(GetProperties([100u, 101u]).IsContiguous);
31-
Assert.False(GetProperties([100u, 102u]).IsContiguous);
30+
Assert.True(GetProperties([100u, 101u]).IsConsecutive);
31+
Assert.False(GetProperties([100u, 102u]).IsConsecutive);
3232

33-
Assert.True(GetProperties([long.MaxValue - 2, long.MaxValue - 1, long.MaxValue]).IsContiguous);
34-
Assert.False(GetProperties([1L, 3L, 4L]).IsContiguous);
33+
Assert.True(GetProperties([long.MaxValue - 2, long.MaxValue - 1, long.MaxValue]).IsConsecutive);
34+
Assert.False(GetProperties([1L, 3L, 4L]).IsConsecutive);
3535

36-
Assert.True(GetProperties([1ul, 2ul, 3ul]).IsContiguous);
37-
Assert.False(GetProperties([1ul, 2ul, 4ul]).IsContiguous);
36+
Assert.True(GetProperties([1ul, 2ul, 3ul]).IsConsecutive);
37+
Assert.False(GetProperties([1ul, 2ul, 4ul]).IsConsecutive);
3838

39-
Assert.True(GetProperties([0.5f, 1.5f, 2.5f]).IsContiguous);
40-
Assert.False(GetProperties([0f, 0.9f, 2f]).IsContiguous);
39+
Assert.True(GetProperties([0.5f, 1.5f, 2.5f]).IsConsecutive);
40+
Assert.False(GetProperties([0f, 0.9f, 2f]).IsConsecutive);
4141

42-
Assert.True(GetProperties([0.5d, 1.5d, 2.5d]).IsContiguous);
43-
Assert.False(GetProperties([0d, 0.9d, 2d]).IsContiguous);
42+
Assert.True(GetProperties([0.5d, 1.5d, 2.5d]).IsConsecutive);
43+
Assert.False(GetProperties([0d, 0.9d, 2d]).IsConsecutive);
4444
}
4545

4646
[Theory]

Src/FastData/FastDataGenerator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ private static string GenerateInternal<TKey, TValue>(TKey[] keys, TValue[]? valu
9090
if (keys.Length == 1)
9191
return GenerateWrapper(generator, genCfg, new SingleValueStructure<TKey, TValue>(), keys, values);
9292

93-
// RangeStructure handles contiguous keys; keyed lookups are limited to integer-like key types for now.
94-
if (props.IsContiguous && (values == null || keyType is not (KeyType.Single or KeyType.Double or KeyType.String)))
93+
// RangeStructure handles consecutive keys; keyed lookups are limited to integer-like key types.
94+
if (props.IsConsecutive && (values == null || SupportsKeyedRange(keyType)))
9595
return GenerateWrapper(generator, genCfg, new RangeStructure<TKey, TValue>(), keys, values);
9696

9797
// For small amounts of data, logic is the fastest. However, it increases the assembly size, so we want to try some special cases first.
@@ -225,6 +225,8 @@ private static string GenerateWrapper<TKey, TValue, TContext>(ICodeGenerator gen
225225
return generator.Generate(genCfg, res);
226226
}
227227

228+
private static bool SupportsKeyedRange(KeyType keyType) => keyType is not (KeyType.Single or KeyType.Double or KeyType.String);
229+
228230
internal static Candidate GetBestHash(ReadOnlySpan<string> data, StringProperties props, StringAnalyzerConfig cfg, ILoggerFactory factory, GeneratorEncoding encoding, bool includeDefault)
229231
{
230232
Simulator sim = new Simulator(data.Length, encoding);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
namespace Genbox.FastData.Internal.Analysis.Properties;
22

3-
internal sealed record KeyProperties<T>(T MinKeyValue, T MaxKeyValue, bool HasZeroOrNaN, bool IsContiguous) : IProperties;
3+
internal sealed record KeyProperties<T>(T MinKeyValue, T MaxKeyValue, bool HasZeroOrNaN, bool IsConsecutive) : IProperties;

0 commit comments

Comments
 (0)