Skip to content

Commit c579ab5

Browse files
committed
Add ToExistingArray function
1 parent 773047c commit c579ab5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

roaring.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,18 +421,27 @@ func FromBitSet(bitset *bitset.BitSet) *Bitmap {
421421
// ToArray creates a new slice containing all of the integers stored in the Bitmap in sorted order
422422
func (rb *Bitmap) ToArray() []uint32 {
423423
array := make([]uint32, rb.GetCardinality())
424+
ar := rb.toArray(&array)
425+
return *ar
426+
}
427+
428+
func (rb *Bitmap) toArray(array *[]uint32) *[]uint32 {
424429
pos := 0
425430
pos2 := 0
426431

427432
for pos < rb.highlowcontainer.size() {
428433
hs := uint32(rb.highlowcontainer.getKeyAtIndex(pos)) << 16
429434
c := rb.highlowcontainer.getContainerAtIndex(pos)
430435
pos++
431-
pos2 = c.fillLeastSignificant16bits(array, pos2, hs)
436+
pos2 = c.fillLeastSignificant16bits(*array, pos2, hs)
432437
}
433438
return array
434439
}
435440

441+
func (rb *Bitmap) ToExistingArray(array *[]uint32) *[]uint32 {
442+
return rb.toArray(array)
443+
}
444+
436445
// GetSizeInBytes estimates the memory usage of the Bitmap. Note that this
437446
// might differ slightly from the amount of bytes required for persistent storage
438447
func (rb *Bitmap) GetSizeInBytes() uint64 {

0 commit comments

Comments
 (0)