namespace PersistentOrderedMap; using System.Runtime.CompilerServices; /// /// A universal key strategy for any type that relies on standard comparisons /// (IComparable, IComparer, or custom StringComparers) without SIMD prefixes. /// public readonly struct StandardStrategy : IKeyStrategy { private readonly IComparer _comparer; // If no comparer is provided, it defaults to Comparer.Default // which automatically uses IComparable if the type implements it. public StandardStrategy() { _comparer = Comparer.Default; } public StandardStrategy(IComparer? comparer) { _comparer = comparer ?? Comparer.Default; } // Tell the B-Tree to skip SIMD routing and just use LinearSearch public bool UsesPrefixes => false; public bool UseBinarySearch => true; // This will never be called because UsesPrefixes is false, // but we must satisfy the interface. [MethodImpl(MethodImplOptions.AggressiveInlining)] public long GetPrefix(TK key) => 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Compare(TK x, TK y) { return _comparer.Compare(x, y); } } public readonly struct StandardStrategy2 : IKeyStrategy where TComparer : struct, IComparer { private readonly TComparer _comparer; public StandardStrategy2(TComparer comparer) => _comparer = comparer; public bool UsesPrefixes => false; public bool UseBinarySearch => true; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Compare(TK x, TK y) => _comparer.Compare(x, y); public long GetPrefix(TK key) => 0; }