diff --git a/src/ZoneTree/Comparers/ComparerFromRefComparer.cs b/src/ZoneTree/Comparers/ComparerFromRefComparer.cs new file mode 100644 index 0000000..d85522d --- /dev/null +++ b/src/ZoneTree/Comparers/ComparerFromRefComparer.cs @@ -0,0 +1,19 @@ +using System.Runtime.CompilerServices; + +namespace Tenray.ZoneTree.Comparers; + +public sealed class ComparerFromRefComparer : IComparer +{ + public readonly IRefComparer RefComparer; + + public ComparerFromRefComparer(IRefComparer refComparer) + { + RefComparer = refComparer; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Compare(TKey x, TKey y) + { + return RefComparer.Compare(x, y); + } +} diff --git a/src/ZoneTree/Comparers/IRefComparer.cs b/src/ZoneTree/Comparers/IRefComparer.cs index 9b3e945..0d355e8 100644 --- a/src/ZoneTree/Comparers/IRefComparer.cs +++ b/src/ZoneTree/Comparers/IRefComparer.cs @@ -1,6 +1,5 @@ namespace Tenray.ZoneTree.Comparers; - /// /// Defines a method that a type implements to compare two objects. /// diff --git a/src/ZoneTree/Comparers/RefComparerExtensions.cs b/src/ZoneTree/Comparers/RefComparerExtensions.cs new file mode 100644 index 0000000..a8c88b7 --- /dev/null +++ b/src/ZoneTree/Comparers/RefComparerExtensions.cs @@ -0,0 +1,66 @@ +using System.Runtime.CompilerServices; +using Tenray.ZoneTree.Comparers; + +namespace Tenray.ZoneTree.Comparers; + +public static class RefComparerExtensions +{ + public static IComparer ToComparer(this IRefComparer refComparer) + { + return new ComparerFromRefComparer(refComparer); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool AreEqual( + this IRefComparer refComparer, + in TKey a, + in TKey b) + { + return refComparer.Compare(a, b) == 0; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool AreNotEqual( + this IRefComparer refComparer, + in TKey a, + in TKey b) + { + return refComparer.Compare(a, b) != 0; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool ALessThanB( + this IRefComparer refComparer, + in TKey a, + in TKey b) + { + return refComparer.Compare(a, b) < 0; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool ALessOrEqualToB( + this IRefComparer refComparer, + in TKey a, + in TKey b) + { + return refComparer.Compare(a, b) <= 0; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool AGreaterThanB( + this IRefComparer refComparer, + in TKey a, + in TKey b) + { + return refComparer.Compare(a, b) > 0; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool AGreaterOrEqualToB( + this IRefComparer refComparer, + in TKey a, + in TKey b) + { + return refComparer.Compare(a, b) >= 0; + } +} \ No newline at end of file diff --git a/src/ZoneTree/Directory.Build.props b/src/ZoneTree/Directory.Build.props index 45a1d12..387baf5 100644 --- a/src/ZoneTree/Directory.Build.props +++ b/src/ZoneTree/Directory.Build.props @@ -5,8 +5,8 @@ Ahmed Yasin Koculu ZoneTree ZoneTree - 1.7.4.0 - 1.7.4.0 + 1.7.5.0 + 1.7.5.0 Ahmed Yasin Koculu ZoneTree ZoneTree is a persistent, high-performance, transactional, ACID-compliant ordered key-value database for NET. It can operate in memory or on local/cloud storage.