Skip to content

Commit

Permalink
code simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
k-wojcik committed Jul 24, 2024
1 parent b641ce1 commit 9e34fd1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Roaring.Net/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
27 changes: 3 additions & 24 deletions src/Roaring.Net/Roaring32/Roaring32Bitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/Roaring.Net.Test/Roaring32/ContainsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/Roaring.Net.Test/Roaring32/RemoveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e34fd1

Please sign in to comment.