Skip to content

Commit 9f4f91e

Browse files
committed
Convert BitSetStructure to use value converter
1 parent 72146a4 commit 9f4f91e

1 file changed

Lines changed: 2 additions & 17 deletions

File tree

Src/FastData/Internal/Structures/BitSetStructure.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ public BitSetContext<TKey, TValue> Create(ReadOnlyMemory<TKey> keys, ReadOnlyMem
1919
ulong[] bitset = new ulong[(range + 63) / 64];
2020
TValue[]? denseValues = values.IsEmpty ? null : new TValue[range];
2121

22-
Func<TKey, long> func = GetLongConverter(keyType);
23-
long minKey = func(props.MinKeyValue);
22+
long minKey = props.ValueConverter(props.MinKeyValue);
2423

2524
for (int i = 0; i < keySpan.Length; i++)
2625
{
27-
ulong offset = (ulong)(func(keySpan[i]) - minKey);
26+
ulong offset = (ulong)(props.ValueConverter(keySpan[i]) - minKey);
2827
int word = (int)(offset >> 6);
2928
bitset[word] |= 1UL << (int)(offset & 63);
3029

@@ -34,18 +33,4 @@ public BitSetContext<TKey, TValue> Create(ReadOnlyMemory<TKey> keys, ReadOnlyMem
3433

3534
return new BitSetContext<TKey, TValue>(bitset, denseValues);
3635
}
37-
38-
private static Func<TKey, long> GetLongConverter(KeyType keyType) => keyType switch
39-
{
40-
KeyType.SByte => static key => (sbyte)(object)key,
41-
KeyType.Int16 => static key => (short)(object)key,
42-
KeyType.Int32 => static key => (int)(object)key,
43-
KeyType.Int64 => static key => (long)(object)key,
44-
KeyType.Byte => static key => (byte)(object)key,
45-
KeyType.UInt16 => static key => (ushort)(object)key,
46-
KeyType.UInt32 => static key => (uint)(object)key,
47-
KeyType.UInt64 => static key => (long)(ulong)(object)key,
48-
KeyType.Char => static key => (ushort)(object)key,
49-
_ => throw new InvalidOperationException($"Unsupported key type: {keyType}")
50-
};
5136
}

0 commit comments

Comments
 (0)