Skip to content

Commit 5e4d4e7

Browse files
committed
Add more configuration
1 parent 3ee447d commit 5e4d4e7

5 files changed

Lines changed: 24 additions & 7 deletions

File tree

Src/FastData/Config/DataConfig.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
public abstract class DataConfig
44
{
5+
/// <summary>Configuration controlling which structures are available and their limits.</summary>
6+
public StructureConfig StructureConfig { get; set; } = StructureConfig.Default;
7+
8+
/// <summary>Configuration controlling early-exit behavior.</summary>
9+
public EarlyExitConfig EarlyExitConfig { get; set; } = EarlyExitConfig.Default;
10+
11+
/// <summary>Enable approximate matching using a Bloom filter.</summary>
12+
public bool AllowApproximateMatching { get; set; }
13+
514
/// <summary>The type of structure to create. Defaults to Auto.</summary>
615
public Type? StructureTypeOverride { get; set; }
716

Src/FastData/Config/EarlyExitConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static EarlyExitConfig Default
3030
}
3131
}
3232

33+
public bool Disabled { get; set; }
3334
public uint MinItemCount { get; set; }
3435

3536
public void DisableEarlyExit(Type earlyExitType) => _disabled.Add(earlyExitType);

Src/FastData/FastDataGenerator.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ private static string GenerateStringInternal<TValue>(ReadOnlyMemory<string> keys
111111
if (cfg.StructureTypeOverride != null)
112112
structureType = cfg.StructureTypeOverride;
113113
else
114-
structureType = StringStructures.GetBest(keys, !values.IsEmpty, props.LengthData.LengthMap.Min, props.LengthData.LengthMap.Max, false, props.LengthData.Unique, StructureConfig.Default, x => EnsureHashData(x.Span));
114+
structureType = StringStructures.GetBest(keys, !values.IsEmpty, props.LengthData.LengthMap.Min, props.LengthData.LengthMap.Max, cfg.AllowApproximateMatching, props.LengthData.Unique, cfg.StructureConfig, x => EnsureHashData(x.Span));
115115

116-
IEarlyExit[] earlyExits = StringEarlyExits.GetCandidates(structureType, props, cfg, generator.Encoding, EarlyExitConfig.Default).ToArray();
116+
IEarlyExit[] earlyExits = StringEarlyExits.GetCandidates(structureType, props, cfg.IgnoreCase, generator.Encoding, cfg.EarlyExitConfig).ToArray();
117117

118118
LogStructureType(logger, structureType.Name);
119119

@@ -143,6 +143,7 @@ HashData EnsureHashData(ReadOnlySpan<string> keySpan)
143143

144144
(HashData hashData, StringHashInfo _) = GetStringHash(keySpan);
145145
cacheHashData = hashData;
146+
146147
// cacheHashInfo = ...; //TODO: Disabled temporarily until i can look at the compiler again
147148
return hashData;
148149
}
@@ -245,12 +246,12 @@ private static string GenerateNumericInternal<TKey, TValue>(ReadOnlyMemory<TKey>
245246
cacheHashData = GetNumericHash(keys.Span);
246247
}
247248
else
248-
structureType = NumericStructures<TKey>.GetBest(keys, !values.IsEmpty, props.Density, props.IsConsecutive, false, StructureConfig.Default, x =>
249+
structureType = NumericStructures<TKey>.GetBest(keys, !values.IsEmpty, props.Density, props.IsConsecutive, cfg.AllowApproximateMatching, cfg.StructureConfig, x =>
249250
{
250251
return cacheHashData = GetNumericHash(x.Span);
251252
});
252253

253-
IEarlyExit[] earlyExits = NumericEarlyExits<TKey>.GetCandidates(type, props.MinKeyValue, props.MaxKeyValue, props.Range, props.BitMask, (uint)keys.Length, EarlyExitConfig.Default).ToArray();
254+
IEarlyExit[] earlyExits = NumericEarlyExits<TKey>.GetCandidates(type, props.MinKeyValue, props.MaxKeyValue, props.Range, props.BitMask, (uint)keys.Length, cfg.EarlyExitConfig).ToArray();
254255

255256
LogStructureType(logger, structureType.Name);
256257

@@ -299,4 +300,4 @@ private static IStructure<TKey, TValue, IContext> NumericStructureFactory<TKey,
299300

300301
throw new InvalidOperationException($"Unsupported DataStructure {type}");
301302
}
302-
}
303+
}

Src/FastData/Internal/NumericEarlyExits.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ internal static class NumericEarlyExits<TKey>
1010
{
1111
internal static IEnumerable<IEarlyExit> GetCandidates(Type structureType, TKey min, TKey max, ulong range, ulong bitMask, uint itemCount, EarlyExitConfig config)
1212
{
13+
if (config.Disabled)
14+
yield break;
15+
1316
if (!config.IsEnabledForStructure(structureType))
1417
yield break;
1518

Src/FastData/Internal/StringEarlyExits.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ namespace Genbox.FastData.Internal;
1010

1111
internal static class StringEarlyExits
1212
{
13-
internal static IEnumerable<IEarlyExit> GetCandidates(Type structureType, StringKeyProperties props, StringDataConfig cfg, GeneratorEncoding enc, EarlyExitConfig config)
13+
internal static IEnumerable<IEarlyExit> GetCandidates(Type structureType, StringKeyProperties props, bool ignoreCase, GeneratorEncoding enc, EarlyExitConfig config)
1414
{
15+
if (config.Disabled)
16+
yield break;
17+
1518
if (!config.IsEnabledForStructure(structureType))
1619
yield break;
1720

@@ -38,7 +41,7 @@ internal static IEnumerable<IEarlyExit> GetCandidates(Type structureType, String
3841
yield break;
3942
}
4043

41-
if (ShouldApplyCharMap(props.LengthData.LengthMap.Min, props.CharacterData.AllAscii, enc, cfg.IgnoreCase))
44+
if (ShouldApplyCharMap(props.LengthData.LengthMap.Min, props.CharacterData.AllAscii, enc, ignoreCase))
4245
{
4346
AsciiMap firstMap = props.CharacterData.FirstCharMap;
4447
if (config.IsEarlyExitEnabled(typeof(CharEqualsEarlyExit)) && firstMap.BitCount == 1)

0 commit comments

Comments
 (0)