Rename because it is ordered
This commit is contained in:
parent
b5b363ae9f
commit
e3cec3423b
28 changed files with 104 additions and 104 deletions
53
PersistentOrderedMap/KeyStrategies/StandardStrategy.cs
Normal file
53
PersistentOrderedMap/KeyStrategies/StandardStrategy.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
namespace PersistentOrderedMap;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
/// <summary>
|
||||
/// A universal key strategy for any type that relies on standard comparisons
|
||||
/// (IComparable, IComparer, or custom StringComparers) without SIMD prefixes.
|
||||
/// </summary>
|
||||
public readonly struct StandardStrategy<K> : IKeyStrategy<K>
|
||||
{
|
||||
private readonly IComparer<K> _comparer;
|
||||
|
||||
// If no comparer is provided, it defaults to Comparer<K>.Default
|
||||
// which automatically uses IComparable<K> if the type implements it.
|
||||
|
||||
public StandardStrategy()
|
||||
{
|
||||
_comparer = Comparer<K>.Default;
|
||||
}
|
||||
|
||||
public StandardStrategy(IComparer<K>? comparer)
|
||||
{
|
||||
_comparer = comparer ?? Comparer<K>.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(K key) => 0;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Compare(K x, K y)
|
||||
{
|
||||
return _comparer.Compare(x, y);
|
||||
}
|
||||
}
|
||||
public readonly struct StandardStrategy2<K, TComparer> : IKeyStrategy<K>
|
||||
where TComparer : struct, IComparer<K>
|
||||
{
|
||||
private readonly TComparer _comparer;
|
||||
|
||||
public StandardStrategy2(TComparer comparer) => _comparer = comparer;
|
||||
|
||||
public bool UsesPrefixes => false;
|
||||
public bool UseBinarySearch => true;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Compare(K x, K y) => _comparer.Compare(x, y);
|
||||
|
||||
public long GetPrefix(K key) => 0;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue