Skip to content

Commit 2b13dc1

Browse files
committed
Add StructureSettings and have EliasFano read it with default value fallback
1 parent 4c1effa commit 2b13dc1

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

Src/FastData/Config/DataConfig.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Genbox.FastData.Config;
1+
namespace Genbox.FastData.Config;
22

33
public abstract class DataConfig
44
{
@@ -31,4 +31,7 @@ public abstract class DataConfig
3131
/// performance.
3232
/// </summary>
3333
public int HashCapacityFactor { get; set; } = 1;
34+
35+
/// <summary>Can be used to give advanced fine-tuning parameters to individual data structures</summary>
36+
public Dictionary<string, object> StructureSettings { get; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
3437
}

Src/FastData/FastDataGenerator.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private static string GenerateNumericInternal<TKey, TValue>(ReadOnlyMemory<TKey>
283283

284284
LogStructureType(logger, structureType.Name);
285285

286-
IStructure<TKey, TValue, IContext> structure = NumericStructureFactory<TKey, TValue>(structureType, props, cacheHashData!, sorted);
286+
IStructure<TKey, TValue, IContext> structure = NumericStructureFactory<TKey, TValue>(cfg, structureType, props, cacheHashData!, sorted);
287287

288288
IEarlyExit[] earlyExits = CombineEarlyExits(structure.GetMandatoryExits(), NumericEarlyExits<TKey>.GetCandidates(type, props.MinKeyValue, props.MaxKeyValue, props.Range, props.BitMask, (uint)keys.Length, cfg.EarlyExitConfig));
289289

@@ -321,7 +321,7 @@ private static IEarlyExit[] CombineEarlyExits(IEnumerable<IEarlyExit> mandatoryE
321321
return combined.ToArray();
322322
}
323323

324-
private static IStructure<TKey, TValue, IContext> NumericStructureFactory<TKey, TValue>(Type type, NumericKeyProperties<TKey> props, HashData hashData, bool sorted)
324+
private static IStructure<TKey, TValue, IContext> NumericStructureFactory<TKey, TValue>(DataConfig cfg, Type type, NumericKeyProperties<TKey> props, HashData hashData, bool sorted)
325325
{
326326
if (type == typeof(ArrayStructure<,>))
327327
return new ArrayStructure<TKey, TValue>();
@@ -336,7 +336,7 @@ private static IStructure<TKey, TValue, IContext> NumericStructureFactory<TKey,
336336
if (type == typeof(ConditionalStructure<,>))
337337
return new ConditionalStructure<TKey, TValue>();
338338
if (type == typeof(EliasFanoStructure<,>))
339-
return new EliasFanoStructure<TKey, TValue>(props.MinKeyValue, props.MaxKeyValue, props.ValueConverter, sorted, 128); // TODO: Make skip a config
339+
return new EliasFanoStructure<TKey, TValue>(props.MinKeyValue, props.MaxKeyValue, props.ValueConverter, sorted, GetSetting(cfg, "SkipQuantum", 128));
340340
if (type == typeof(HashTableStructure<,>))
341341
return new HashTableStructure<TKey, TValue>(hashData);
342342
if (type == typeof(HashTableCompactStructure<,>))
@@ -353,6 +353,14 @@ private static IStructure<TKey, TValue, IContext> NumericStructureFactory<TKey,
353353
throw new InvalidOperationException($"Unsupported DataStructure {type}");
354354
}
355355

356+
private static T GetSetting<T>(DataConfig cfg, string key, T defaultValue)
357+
{
358+
if (!cfg.StructureSettings.TryGetValue(key, out object? value))
359+
return defaultValue;
360+
361+
return (T)value;
362+
}
363+
356364
private sealed class UsedFunctionVisitor : ExpressionVisitor
357365
{
358366
internal StringFunction Functions { get; private set; }

0 commit comments

Comments
 (0)