github.com/anacrolix/torrent@v1.61.0/typed-roaring/bitmap.go (about)

     1  package typedRoaring
     2  
     3  import (
     4  	"github.com/RoaringBitmap/roaring"
     5  )
     6  
     7  // TODO: Update to roaring v2 or higher
     8  type Bitmap[T BitConstraint] struct {
     9  	roaring.Bitmap
    10  }
    11  
    12  func (me *Bitmap[T]) Contains(x T) bool {
    13  	return me.Bitmap.Contains(uint32(x))
    14  }
    15  
    16  func (me Bitmap[T]) Iterate(f func(x T) bool) {
    17  	me.Bitmap.Iterate(func(x uint32) bool {
    18  		return f(T(x))
    19  	})
    20  }
    21  
    22  func (me *Bitmap[T]) Add(x T) {
    23  	me.Bitmap.Add(uint32(x))
    24  }
    25  
    26  func (me *Bitmap[T]) Rank(x T) uint64 {
    27  	return me.Bitmap.Rank(uint32(x))
    28  }
    29  
    30  func (me *Bitmap[T]) CheckedRemove(x T) bool {
    31  	return me.Bitmap.CheckedRemove(uint32(x))
    32  }
    33  
    34  func (me *Bitmap[T]) Clone() Bitmap[T] {
    35  	return Bitmap[T]{*me.Bitmap.Clone()}
    36  }
    37  
    38  func (me *Bitmap[T]) CheckedAdd(x T) bool {
    39  	return me.Bitmap.CheckedAdd(uint32(x))
    40  }
    41  
    42  func (me *Bitmap[T]) Remove(x T) {
    43  	me.Bitmap.Remove(uint32(x))
    44  }
    45  
    46  // Returns an uninitialized iterator for the type of the receiver.
    47  func (Bitmap[T]) IteratorType() Iterator[T] {
    48  	return Iterator[T]{}
    49  }
    50  
    51  // TODO: Override Bitmap.Iterator.