From 5b9d6595eee844af9e720215085b869fce159e6b Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Sat, 7 Jan 2023 22:46:57 +0600 Subject: [PATCH] Use generic math in `FirstIsToTheLeftOfSecond` and `FirstIsToTheRightOfSecond` --- .../RecursionlessSizeBalancedTree.cs | 5 ++--- .../Platform.Collections.Methods.Tests/SizeBalancedTree.cs | 4 ++-- .../SizedAndThreadedAVLBalancedTree.cs | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/csharp/Platform.Collections.Methods.Tests/RecursionlessSizeBalancedTree.cs b/csharp/Platform.Collections.Methods.Tests/RecursionlessSizeBalancedTree.cs index 02199f0..670ddb1 100644 --- a/csharp/Platform.Collections.Methods.Tests/RecursionlessSizeBalancedTree.cs +++ b/csharp/Platform.Collections.Methods.Tests/RecursionlessSizeBalancedTree.cs @@ -58,9 +58,8 @@ public void Free(TElement node) public bool IsEmpty(TElement node) => EqualityComparer.Default.Equals(GetElement(node), default); - protected override bool FirstIsToTheLeftOfSecond(TElement first, TElement second) => Comparer.Compare(first, second) < 0; - - protected override bool FirstIsToTheRightOfSecond(TElement first, TElement second) => Comparer.Compare(first, second) > 0; + protected override bool FirstIsToTheLeftOfSecond(TElement first, TElement second) => first < second; + protected override bool FirstIsToTheRightOfSecond(TElement first, TElement second) => first > second; protected override ref TElement GetLeftReference(TElement node) => ref GetElement(node).Left; diff --git a/csharp/Platform.Collections.Methods.Tests/SizeBalancedTree.cs b/csharp/Platform.Collections.Methods.Tests/SizeBalancedTree.cs index b410c53..6b55e9f 100644 --- a/csharp/Platform.Collections.Methods.Tests/SizeBalancedTree.cs +++ b/csharp/Platform.Collections.Methods.Tests/SizeBalancedTree.cs @@ -58,9 +58,9 @@ public void Free(TElement node) public bool IsEmpty(TElement node) => EqualityComparer.Default.Equals(GetElement(node), default); - protected override bool FirstIsToTheLeftOfSecond(TElement first, TElement second) => Comparer.Compare(first, second) < 0; + protected override bool FirstIsToTheLeftOfSecond(TElement first, TElement second) => first < second; - protected override bool FirstIsToTheRightOfSecond(TElement first, TElement second) => Comparer.Compare(first, second) > 0; + protected override bool FirstIsToTheRightOfSecond(TElement first, TElement second) => first > second; protected override ref TElement GetLeftReference(TElement node) => ref GetElement(node).Left; diff --git a/csharp/Platform.Collections.Methods.Tests/SizedAndThreadedAVLBalancedTree.cs b/csharp/Platform.Collections.Methods.Tests/SizedAndThreadedAVLBalancedTree.cs index d240d59..9b50487 100644 --- a/csharp/Platform.Collections.Methods.Tests/SizedAndThreadedAVLBalancedTree.cs +++ b/csharp/Platform.Collections.Methods.Tests/SizedAndThreadedAVLBalancedTree.cs @@ -61,9 +61,9 @@ public void Free(TElement node) public bool IsEmpty(TElement node) => EqualityComparer.Default.Equals(GetElement(node), default); - protected override bool FirstIsToTheLeftOfSecond(TElement first, TElement second) => Comparer.Compare(first, second) < 0; + protected override bool FirstIsToTheLeftOfSecond(TElement first, TElement second) => first < second; - protected override bool FirstIsToTheRightOfSecond(TElement first, TElement second) => Comparer.Compare(first, second) > 0; + protected override bool FirstIsToTheRightOfSecond(TElement first, TElement second) => first > second; protected override sbyte GetBalance(TElement node) => GetElement(node).Balance;