Skip to content

Commit

Permalink
clear method
Browse files Browse the repository at this point in the history
  • Loading branch information
k-wojcik committed Jul 24, 2024
1 parent 6a387f8 commit b641ce1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Roaring.Net/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ internal static unsafe class NativeMethods
[DllImport("roaring")]
public static extern void roaring_bitmap_remove_range_closed(IntPtr bitmap, uint min, uint max);

[DllImport("roaring")]
public static extern void roaring_bitmap_clear(IntPtr bitmap);

[DllImport("roaring")]
public static extern void roaring_bitmap_remove_many(IntPtr bitmap, uint count, uint* values);

Expand Down
2 changes: 2 additions & 0 deletions src/Roaring.Net/Roaring32/Roaring32Bitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public void RemoveRange(uint min, uint max)
NativeMethods.roaring_bitmap_remove_range_closed(_pointer, min, max);
}

public void Clear() => NativeMethods.roaring_bitmap_clear(_pointer);

// TODO roaring_bitmap_contains_bulk

public bool Contains(uint value) => NativeMethods.roaring_bitmap_contains(_pointer, value);
Expand Down
26 changes: 26 additions & 0 deletions test/Roaring.Net.Test/Roaring32/RemoveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,30 @@ public void RemoveRange_CorrectRange_BitmapRemovesRange(uint minTest, uint maxTe

Assert.Equal(expected, actual);
}

[Fact]
public void Clear_BitmapIsEmpty_DoesNotRemoveValues()
{
// Arrange
using var testObject = Roaring32BitmapTestObject.GetEmpty();

// Act
testObject.Bitmap.Clear();

// Assert
Assert.Empty(testObject.Bitmap.Values);
}

[Fact]
public void Clear_BitmapHasValues_RemovesAllValuesFromBitmap()
{
// Arrange
using var testObject = Roaring32BitmapTestObject.GetDefault();

// Act
testObject.Bitmap.Clear();

// Assert
Assert.Empty(testObject.Bitmap.Values);
}
}

0 comments on commit b641ce1

Please sign in to comment.