Skip to content

Commit 081b19d

Browse files
committed
Add early exit gap detection
1 parent a73bbb5 commit 081b19d

185 files changed

Lines changed: 1978 additions & 788 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.

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- Scripted build: `pwsh Scripts/Build.ps1`.
2828
- Test full solution: `dotnet test FastData.slnx -c Debug`.
2929
- Test a single project: `dotnet test Src/FastData.Tests/FastData.Tests.csproj -c Debug`.
30+
- Test harness runner (uses real generators): `dotnet test --project Src/FastData.TestHarness.Runner/FastData.TestHarness.Runner.csproj -c Debug`.
3031
- Test project list:
3132
- `Src/FastData.Tests/FastData.Tests.csproj`
3233
- `Src/FastData.Cli.Tests/FastData.Cli.Tests.csproj`

Src/FastData.Benchmarks/Benchmarks/GPerfAnalyzerBenchmarks.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public GPerfAnalyzerBenchmarks()
1919
Random rng = new Random(42);
2020
_data = Enumerable.Range(1, 100).Select(_ => TestHelper.GenerateRandomString(rng, 50)).ToArray();
2121

22-
StringKeyProperties props = KeyAnalyzer.GetStringProperties(_data, false, false, GeneratorEncoding.ASCII);
23-
_analyzer = new GPerfAnalyzer(_data.Length, props, new GPerfAnalyzerConfig(), new Simulator(_data.Length, GeneratorEncoding.UTF16), NullLogger<GPerfAnalyzer>.Instance);
22+
StringKeyProperties props = KeyAnalyzer.GetStringProperties(_data, false, false, GeneratorEncoding.Utf16CodeUnits);
23+
_analyzer = new GPerfAnalyzer(_data.Length, props, new GPerfAnalyzerConfig(), new Simulator(_data.Length, GeneratorEncoding.Utf16CodeUnits), NullLogger<GPerfAnalyzer>.Instance);
2424
}
2525

2626
[Benchmark]

Src/FastData.Benchmarks/Benchmarks/KeyAnalyzerBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ public KeyAnalyzerBenchmarks()
1616
}
1717

1818
[Benchmark]
19-
public object GetStringProperties() => KeyAnalyzer.GetStringProperties(_data, true, false, GeneratorEncoding.UTF16);
19+
public object GetStringProperties() => KeyAnalyzer.GetStringProperties(_data, true, false, GeneratorEncoding.Utf16CodeUnits);
2020
}

Src/FastData.Benchmarks/Benchmarks/SegmentGeneratorsBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class SegmentGeneratorsBenchmarks
1515
private readonly OffsetGenerator _ofGen = new OffsetGenerator();
1616

1717
//We start at 8 and go up to 100 to cover as many cases as possible
18-
private readonly StringKeyProperties _props = KeyAnalyzer.GetStringProperties(Enumerable.Range(8, 100).Select(x => TestHelper.GenerateRandomString(Random.Shared, x)).ToArray(), false, false, GeneratorEncoding.UTF16);
18+
private readonly StringKeyProperties _props = KeyAnalyzer.GetStringProperties(Enumerable.Range(8, 100).Select(x => TestHelper.GenerateRandomString(Random.Shared, x)).ToArray(), false, false, GeneratorEncoding.Utf16CodeUnits);
1919

2020
[Benchmark]
2121
public object BruteForceGenerator() => _bfGen.Generate(_props).ToArray();

Src/FastData.Generator.CPlusPlus.TestHarness/CPlusPlusBootstrap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public sealed class CPlusPlusBootstrap : BootstrapBase
1111
public CPlusPlusBootstrap(HarnessType type) : base("CPlusPlus", ".cpp", type, "silkeh/clang", GetCommandTemplate(type))
1212
{
1313
CPlusPlusLanguageDef langDef = new CPlusPlusLanguageDef();
14-
Map = new TypeMap(langDef.TypeDefinitions, GeneratorEncoding.UTF8);
14+
Map = new TypeMap(langDef.TypeDefinitions, GeneratorEncoding.Utf8Bytes);
1515
}
1616

1717
public TypeMap Map { get; }

Src/FastData.Generator.CPlusPlus/CPlusPlusCodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Genbox.FastData.Generator.CPlusPlus;
77

8-
public sealed class CPlusPlusCodeGenerator(CPlusPlusCodeGeneratorConfig cppCfg) : TemplatedCodeGenerator(new CPlusPlusLanguageDef(), GeneratorEncoding.UTF8)
8+
public sealed class CPlusPlusCodeGenerator(CPlusPlusCodeGeneratorConfig cppCfg) : TemplatedCodeGenerator(new CPlusPlusLanguageDef(), GeneratorEncoding.Utf8Bytes)
99
{
1010
protected override string GenerateTemplated<TKey, TValue>(GeneratorConfigBase genCfg, TemplateManager manager, Dictionary<string, object?> variables)
1111
{

Src/FastData.Generator.CPlusPlus/Internal/CPlusPlusLanguageDef.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ internal class CPlusPlusLanguageDef : ILanguageDef
2525

2626
new ObjectTypeDef(PrintDeclaration, PrintValue),
2727

28-
//Support reduction from UTF16 to ASCII
2928
new DynamicStringTypeDef(
30-
new StringType(GeneratorEncoding.UTF32, "std::u32string_view", static x => $"U\"{x}\""),
31-
new StringType(GeneratorEncoding.UTF16, "std::u16string_view", static x => $"u\"{x}\""),
32-
new StringType(GeneratorEncoding.UTF8, "std::string_view", static x => $"u8\"{x}\""),
33-
new StringType(GeneratorEncoding.ASCII, "std::string_view", static x => $"\"{x}\""))
29+
new StringType(GeneratorEncoding.Utf16CodeUnits, "std::u16string_view", static x => $"u\"{x}\""),
30+
new StringType(GeneratorEncoding.Utf8Bytes, "std::string_view", static x => $"u8\"{x}\""),
31+
new StringType(GeneratorEncoding.AsciiBytes, "std::string_view", static x => $"\"{x}\""))
3432
};
3533

3634
private static string PrintDeclaration(TypeMap map, Type type)

Src/FastData.Generator.CPlusPlus/Templates/Includes/Footer.ttinclude

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
if (GeneratorConfig is StringGeneratorConfig strCfg)
55
{
66
#>
7-
static constexpr size_t min_key_length = <#= strCfg.Constants.MinStringLength #>;
8-
static constexpr size_t max_key_length = <#= strCfg.Constants.MaxStringLength #>;
7+
static constexpr int32_t min_key_length = <#= strCfg.Constants.MinStringLength #>;
8+
static constexpr int32_t max_key_length = <#= strCfg.Constants.MaxStringLength #>;
99
static constexpr bool has_number = <#= strCfg.Constants.CharacterClasses.HasFlag(CharacterClass.Number) ? "true" : "false" #>;
1010
static constexpr bool has_uppercase = <#= strCfg.Constants.CharacterClasses.HasFlag(CharacterClass.Uppercase) ? "true" : "false" #>;
1111
static constexpr bool has_lowercase = <#= strCfg.Constants.CharacterClasses.HasFlag(CharacterClass.Lowercase) ? "true" : "false" #>;

Src/FastData.Generator.CPlusPlus/Templates/Includes/Functions.ttinclude

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
{
117117
if (keyType == TypeCode.Single)
118118
{
119-
return numCfg.HasZeroOrNaN
119+
return numCfg.HasZero
120120
? """
121121
uint32_t bits;
122122
std::memcpy(&bits, &value, sizeof(bits));
@@ -133,7 +133,7 @@
133133

134134
if (keyType == TypeCode.Double)
135135
{
136-
return numCfg.HasZeroOrNaN
136+
return numCfg.HasZero
137137
? """
138138
uint64_t bits;
139139
std::memcpy(&bits, &value, sizeof(bits));

Src/FastData.Generator.CPlusPlus/Templates/Includes/Header.ttinclude

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<#@ import namespace="Genbox.FastData.Generator.Extensions" #>
1010
<#@ import namespace="Genbox.FastData.Generator.Helpers" #>
1111
<#@ import namespace="Genbox.FastData.Generators" #>
12+
<#@ import namespace="Genbox.FastData.Generators.Helpers" #>
1213
<#@ import namespace="Genbox.FastData.Generators.Abstracts" #>
1314
<#@ import namespace="Genbox.FastData.Generators.EarlyExits" #>
1415
<#@ import namespace="Genbox.FastData.Generators.Enums" #>
@@ -100,7 +101,7 @@ class <#= CPlusPlusConfig.ClassName #> final {
100101
{ StringFunction.GetLastChar, "constexpr char GetLastChar(std::string_view str) { return str[str.length() - 1]; }" },
101102
{ StringFunction.GetLastCharLower, "constexpr char GetLastCharLower(std::string_view str) { return ToLowerAscii(GetLastChar(str)); }" },
102103

103-
{ StringFunction.GetLength, "constexpr uint32_t GetLength(std::string_view str) { return static_cast<uint32_t>(str.length()); }" },
104+
{ StringFunction.GetLength, "constexpr int32_t GetLength(std::string_view str) { return static_cast<int32_t>(str.length()); }" },
104105

105106
{ StringFunction.StartsWith, """
106107
constexpr bool StartsWith(std::string_view prefix, std::string_view str) {

0 commit comments

Comments
 (0)