From 9e34fd19fd3cb53d242db397f73f73e51a32219d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20W=C3=B3jcik?= Date: Wed, 24 Jul 2024 22:13:59 +0200 Subject: [PATCH] code simplified --- src/Roaring.Net/NativeMethods.cs | 2 +- src/Roaring.Net/Roaring32/Roaring32Bitmap.cs | 27 +++---------------- .../Roaring32/ContainsTests.cs | 2 ++ .../Roaring.Net.Test/Roaring32/RemoveTests.cs | 2 ++ 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/Roaring.Net/NativeMethods.cs b/src/Roaring.Net/NativeMethods.cs index 7ddacf5..2b12fd5 100644 --- a/src/Roaring.Net/NativeMethods.cs +++ b/src/Roaring.Net/NativeMethods.cs @@ -70,7 +70,7 @@ internal static unsafe class NativeMethods [DllImport("roaring")] [return: MarshalAs(UnmanagedType.I1)] - public static extern bool roaring_bitmap_contains_range(IntPtr bitmap, uint min, uint max); + public static extern bool roaring_bitmap_contains_range(IntPtr bitmap, ulong min, ulong max); [DllImport("roaring")] [return: MarshalAs(UnmanagedType.I1)] diff --git a/src/Roaring.Net/Roaring32/Roaring32Bitmap.cs b/src/Roaring.Net/Roaring32/Roaring32Bitmap.cs index 470dc45..60827d5 100644 --- a/src/Roaring.Net/Roaring32/Roaring32Bitmap.cs +++ b/src/Roaring.Net/Roaring32/Roaring32Bitmap.cs @@ -34,23 +34,7 @@ public static Roaring32Bitmap FromRange(uint min, uint max, uint step = 1) throw new ArgumentOutOfRangeException(nameof(step), step, "The step cannot be equal to 0."); } - if (min == uint.MaxValue) - { - return FromValues(new[]{ min }); - } - - if (max != uint.MaxValue) - { - max += 1; - } - else - { - var bitmap = new Roaring32Bitmap(NativeMethods.roaring_bitmap_from_range(min, max, step)); - bitmap.Add(uint.MaxValue); - return bitmap; - } - - return new(NativeMethods.roaring_bitmap_from_range(min, max, step)); + return new(NativeMethods.roaring_bitmap_from_range(min, (ulong)max + 1, step)); } public static Roaring32Bitmap FromValues(uint[] values) => FromValues(values, 0U, (uint)values.Length); @@ -159,13 +143,8 @@ public bool ContainsRange(uint min, uint max) { throw new ArgumentOutOfRangeException(nameof(min), min, "The minimum value cannot be greater than the maximum value."); } - - if (max != uint.MaxValue) - { - max += 1; - } - - return NativeMethods.roaring_bitmap_contains_range(_pointer, min, max); + + return NativeMethods.roaring_bitmap_contains_range(_pointer, min, (ulong)max + 1); } public bool Equals(Roaring32Bitmap bitmap) diff --git a/test/Roaring.Net.Test/Roaring32/ContainsTests.cs b/test/Roaring.Net.Test/Roaring32/ContainsTests.cs index 06f53a1..86ba65d 100644 --- a/test/Roaring.Net.Test/Roaring32/ContainsTests.cs +++ b/test/Roaring.Net.Test/Roaring32/ContainsTests.cs @@ -72,6 +72,8 @@ public void ContainsRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeExc [InlineData(200, 300, 100, 350, false)] [InlineData(uint.MaxValue - 100,uint.MaxValue, uint.MaxValue - 1, uint.MaxValue, true)] [InlineData(uint.MaxValue - 100,uint.MaxValue, uint.MaxValue, uint.MaxValue, true)] + [InlineData(uint.MaxValue,uint.MaxValue, uint.MaxValue, uint.MaxValue, true)] + [InlineData(uint.MaxValue - 1,uint.MaxValue - 1, uint.MaxValue, uint.MaxValue, false)] public void ContainsRange_CorrectRange_ReturnsExpectedResult(uint minTest, uint maxTest, uint min, uint max, bool expected) { // Arrange diff --git a/test/Roaring.Net.Test/Roaring32/RemoveTests.cs b/test/Roaring.Net.Test/Roaring32/RemoveTests.cs index 8e227f9..cae2a83 100644 --- a/test/Roaring.Net.Test/Roaring32/RemoveTests.cs +++ b/test/Roaring.Net.Test/Roaring32/RemoveTests.cs @@ -147,6 +147,8 @@ public void RemoveRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeExcep [InlineData(200, 300, 100, 350)] [InlineData(uint.MaxValue - 100,uint.MaxValue, uint.MaxValue - 1, uint.MaxValue)] [InlineData(uint.MaxValue - 100,uint.MaxValue, uint.MaxValue, uint.MaxValue)] + [InlineData(uint.MaxValue,uint.MaxValue, uint.MaxValue, uint.MaxValue)] + [InlineData(uint.MaxValue - 1,uint.MaxValue, uint.MaxValue, uint.MaxValue)] public void RemoveRange_CorrectRange_BitmapRemovesRange(uint minTest, uint maxTest, uint min, uint max) { // Arrange