MCPcopy Create free account
hub / github.com/RoaringBitmap/roaring / WriteDenseTo

Method WriteDenseTo

roaring.go:187–224  ·  view source on GitHub ↗

WriteDenseTo writes to a slice of uint64s representing the bitmap as a dense bitmap. Callers are responsible for allocating enough space in the bitmap using DenseSize. Useful to convert a roaring bitmap to a format that can be used by other libraries like https://github.com/bits-and-blooms/bitset or

(bitmap []uint64)

Source from the content-addressed store, hash-verified

185// Useful to convert a roaring bitmap to a format that can be used by other libraries
186// like https://github.com/bits-and-blooms/bitset or https://github.com/kelindar/bitmap
187func (rb *Bitmap) WriteDenseTo(bitmap []uint64) {
188 for i, ct := range rb.highlowcontainer.containers {
189 hb := uint32(rb.highlowcontainer.keys[i]) << 16
190
191 switch c := ct.(type) {
192 case *arrayContainer:
193 for _, x := range c.content {
194 n := int(hb | uint32(x))
195 bitmap[n>>log2WordSize] |= uint64(1) << uint(x%64)
196 }
197
198 case *bitmapContainer:
199 copy(bitmap[int(hb)>>log2WordSize:], c.bitmap)
200
201 case *runContainer16:
202 for j := range c.iv {
203 start := uint32(c.iv[j].start)
204 end := start + uint32(c.iv[j].length) + 1
205 lo := int(hb|start) >> log2WordSize
206 hi := int(hb|(end-1)) >> log2WordSize
207
208 if lo == hi {
209 bitmap[lo] |= (^uint64(0) << uint(start%64)) &
210 (^uint64(0) >> (uint(-end) % 64))
211 continue
212 }
213
214 bitmap[lo] |= ^uint64(0) << uint(start%64)
215 for n := lo + 1; n < hi; n++ {
216 bitmap[n] = ^uint64(0)
217 }
218 bitmap[hi] |= ^uint64(0) >> (uint(-end) % 64)
219 }
220 default:
221 panic("unsupported container type")
222 }
223 }
224}
225
226// Checksum computes a hash (FNV-1a) for a bitmap that is suitable for
227// using bitmaps as elements in hash sets or as keys in hash maps, as well as

Callers 3

ToDenseMethod · 0.95
BenchmarkFromDenseFunction · 0.80
BenchmarkWriteDenseToFunction · 0.80

Calls

no outgoing calls

Tested by 2

BenchmarkFromDenseFunction · 0.64
BenchmarkWriteDenseToFunction · 0.64