Skip to content

Commit 81b64ca

Browse files
committed
Minor cleanup and add docs
1 parent e49ea93 commit 81b64ca

29 files changed

+162
-17
lines changed

Locals/Benchmarks.props

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

3-
<!-- Disable BenchmarkDotNet as code generators don't need it. We will special handle other benchmark projects -->
3+
<!-- Disable BenchmarkDotNet as code generators don't need it. We will special handle other benchmark projects -->
44

5-
<ItemGroup>
6-
<PackageReference Remove="BenchmarkDotNet"/>
7-
<Using Remove="BenchmarkDotNet.Attributes"/>
8-
</ItemGroup>
5+
<ItemGroup>
6+
<PackageReference Remove="BenchmarkDotNet" />
7+
<Using Remove="BenchmarkDotNet.Attributes" />
8+
</ItemGroup>
99

1010
</Project>

Locals/Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<PackageVersion Include="Serilog.Sinks.File" Version="7.0.0" />
2222
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
2323
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="4.14.0" />
24-
<PackageVersion Include="Genbox.FastData.SourceGenerator" Version="0.1.2"/>
24+
<PackageVersion Include="Genbox.FastData.SourceGenerator" Version="0.1.2" />
2525
</ItemGroup>
2626
</Project>

Src/FastData.InternalShared/Helpers/TestVectorHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ namespace Genbox.FastData.InternalShared.Helpers;
77

88
public static class TestVectorHelper
99
{
10-
1110
public static IEnumerable<ITestVector> GetTestVectors()
1211
{
1312
foreach (ITestVector testVector in GenerateTestVectors(GetSingleValues(), typeof(SingleValueStructure<>)))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
namespace Genbox.FastData.SourceGenerator.Attributes;
22

3+
/// <summary>Specifies the type of class to generate.</summary>
34
public enum ClassType
45
{
56
Unknown = 0,
7+
8+
/// <summary>It will generate a static class with static methods and properties.</summary>
69
Static,
10+
11+
/// <summary>It will generate a class with instance methods and properties.</summary>
712
Instance,
13+
14+
/// <summary>It will generate a struct with instance methods and properties.</summary>
815
Struct
916
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
namespace Genbox.FastData.SourceGenerator.Attributes;
22

3+
/// <summary>Specifies the visibility of the generated class.</summary>
34
public enum ClassVisibility : byte
45
{
56
Unknown = 0,
7+
/// <summary>The class will be internal.</summary>
68
Internal,
9+
/// <summary>The class will be public.</summary>
710
Public
811
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
namespace Genbox.FastData.SourceGenerator.Attributes;
22

3+
/// <summary>Specifies the data structure type to generate.</summary>
34
public enum StructureType : byte
45
{
6+
/// <summary>Automatically select the best structure type.</summary>
57
Auto = 0,
68

7-
// O(n) data structures
9+
/// <summary>Use a simple array structure. Complexity: O(n).</summary>
810
Array,
11+
12+
/// <summary>Use a conditional structure. Complexity: O(n).</summary>
913
Conditional,
1014

11-
// O(log(n)) data structures
15+
/// <summary>Use a binary search structure. Complexity: O(log n).</summary>
1216
BinarySearch,
1317

14-
// O(1) data structures
18+
/// <summary>Use a hash set structure. Complexity: O(1).</summary>
1519
HashSet
1620
}

Src/FastData/FastDataConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ namespace Genbox.FastData;
66
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
77
public sealed class FastDataConfig(StructureType structureType = StructureType.Auto)
88
{
9+
/// <summary>The type of structure to create. Defaults to Auto.</summary>
910
public StructureType StructureType { get; set; } = structureType;
11+
12+
/// <summary>For hash-based structures, you can set this factor higher or lower to control how many slots are used. A factor higher than 1 will use more memory, but can improve performance by reducing collisions. A factor lower than 1 will use less memory, but can increase collisions and thus reduce performance.</summary>
1013
public int HashCapacityFactor { get; set; } = 1;
1114
}

Src/FastData/FastDataGenerator.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ public static partial class FastDataGenerator
1919
{
2020
internal const StringComparison DefaultStringComparison = StringComparison.Ordinal;
2121

22+
/// <summary>Generate source code for the provided data.</summary>
23+
/// <param name="data">The data to generate from. Note that all objects must be the same type.</param>
24+
/// <param name="fdCfg">The configuration to use.</param>
25+
/// <param name="generator">The code generator to use.</param>
26+
/// <param name="source">The source code with the generated data structure.</param>
27+
/// <param name="factory">A logging factory</param>
28+
/// <returns>True, if the generation succeeded, Otherwise, it returns false.</returns>
29+
/// <exception cref="InvalidOperationException">Thrown when you gave an unsupported data type in data.</exception>
2230
public static bool TryGenerate(object[] data, FastDataConfig fdCfg, ICodeGenerator generator, out string? source, ILoggerFactory? factory = null) => data[0] switch
2331
{
2432
char => TryGenerate(data.Cast<char>().ToArray(), fdCfg, generator, out source, factory),
@@ -36,6 +44,14 @@ public static partial class FastDataGenerator
3644
_ => throw new InvalidOperationException($"Unsupported data type: {data[0].GetType().Name}")
3745
};
3846

47+
/// <summary>Generate source code for the provided data.</summary>
48+
/// <param name="data">The data to generate from.</param>
49+
/// <param name="fdCfg">The configuration to use.</param>
50+
/// <param name="generator">The code generator to use.</param>
51+
/// <param name="source">The source code with the generated data structure.</param>
52+
/// <param name="factory">A logging factory</param>
53+
/// <returns>True, if the generation succeeded, Otherwise, it returns false.</returns>
54+
/// <exception cref="InvalidOperationException">Thrown when you gave an unsupported data type in data.</exception>
3955
public static bool TryGenerate<T>(T[] data, FastDataConfig fdCfg, ICodeGenerator generator, out string? source, ILoggerFactory? factory = null) where T : notnull
4056
{
4157
if (data.Length == 0)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
namespace Genbox.FastData.Generators.Abstracts;
22

3+
/// <summary>Defines the interface for code generators</summary>
34
public interface ICodeGenerator
45
{
6+
/// <summary>Gets a value indicating whether the generator uses UTF-16 encoding for string inputs (used in hashing).</summary>
57
bool UseUTF16Encoding { get; }
8+
9+
/// <summary>Attempts to generate source code using the specified generator configuration and context.</summary>
10+
/// <typeparam name="T">The type of data being generated.</typeparam>
11+
/// <param name="genCfg">The generator configuration.</param>
12+
/// <param name="context">The context for code generation.</param>
13+
/// <param name="source">When this method returns, contains the generated source code if the operation succeeded; otherwise, null.</param>
14+
/// <returns>True if code generation succeeded; otherwise, false.</returns>
615
bool TryGenerate<T>(GeneratorConfig<T> genCfg, IContext context, out string? source);
716
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
namespace Genbox.FastData.Generators.Abstracts;
22

3+
/// <summary>Defines the interface for a context used during code generation. A context represents a self-contained container of data for a data structure.</summary>
34
public interface IContext;

0 commit comments

Comments
 (0)