github.com/segmentio/parquet-go@v0.0.0-20230712180008-5d42db8f0d47/bitmap.go (about)

     1  package parquet
     2  
     3  import "sync"
     4  
     5  type bitmap struct {
     6  	bits []uint64
     7  }
     8  
     9  func (m *bitmap) reset(size int) {
    10  	size = (size + 63) / 64
    11  	if cap(m.bits) < size {
    12  		m.bits = make([]uint64, size, 2*size)
    13  	} else {
    14  		m.bits = m.bits[:size]
    15  		m.clear()
    16  	}
    17  }
    18  
    19  func (m *bitmap) clear() {
    20  	for i := range m.bits {
    21  		m.bits[i] = 0
    22  	}
    23  }
    24  
    25  var (
    26  	bitmapPool sync.Pool // *bitmap
    27  )
    28  
    29  func acquireBitmap(n int) *bitmap {
    30  	b, _ := bitmapPool.Get().(*bitmap)
    31  	if b == nil {
    32  		b = &bitmap{bits: make([]uint64, n, 2*n)}
    33  	} else {
    34  		b.reset(n)
    35  	}
    36  	return b
    37  }
    38  
    39  func releaseBitmap(b *bitmap) {
    40  	if b != nil {
    41  		bitmapPool.Put(b)
    42  	}
    43  }