@@ -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