Skip to content

Commit 3cfabb2

Browse files
committed
Add overwrite() to BitMap64
1 parent 423cb4c commit 3cfabb2

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎pyroaring/bitmap.pxi‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,23 @@ cdef class BitMap64(AbstractBitMap64):
441441
"""
442442
self.__ixor__(other)
443443

444+
def overwrite(self, AbstractBitMap64 other):
445+
"""
446+
Clear the bitmap and overwrite it with another.
447+
448+
>>> bm = BitMap64([3, 12])
449+
>>> other = BitMap64([4, 14])
450+
>>> bm.overwrite(other)
451+
>>> other.remove(4)
452+
>>> bm
453+
BitMap64([4, 14])
454+
>>> other
455+
BitMap64([14])
456+
"""
457+
if self._c_bitmap == other._c_bitmap:
458+
raise ValueError('Cannot overwrite itself')
459+
croaring.roaring64_bitmap_overwrite(self._c_bitmap, other._c_bitmap)
460+
444461
def clear(self):
445462
"""
446463
Remove all elements from this set.

‎pyroaring/croaring.pxd‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ cdef extern from "roaring.h":
168168
roaring64_bitmap_t *roaring64_bitmap_portable_deserialize_safe(const char *buf, size_t maxbytes)
169169
bool roaring64_bitmap_internal_validate(const roaring64_bitmap_t *r, const char **reason)
170170
roaring64_bitmap_t *roaring64_bitmap_add_offset_signed(const roaring64_bitmap_t *r, bool positive, uint64_t offset)
171+
void roaring64_bitmap_overwrite(roaring64_bitmap_t *dest, const roaring64_bitmap_t *src)
171172
roaring64_iterator_t *roaring64_iterator_create(const roaring64_bitmap_t *r)
172173
void roaring64_iterator_free(roaring64_iterator_t *it)
173174
bool roaring64_iterator_has_value(const roaring64_iterator_t *it)

‎test.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,6 @@ def test_copy_writable(self, list1: list[int], cow: bool) -> None:
15601560
assert new_element in b2
15611561
assert new_element not in b1
15621562

1563-
@pytest.mark.skipif(not is_32_bits, reason="not supported yet")
15641563
@given(bitmap_cls, small_integer_list, small_integer_list, st.booleans())
15651564
def test_overwrite(self, BitMapClass: type[EitherBitMap], list1: list[int], list2: list[int], cow: bool) -> None:
15661565
assume(set(list1) != set(list2))

0 commit comments

Comments
 (0)