]> Sergey Matveev's repositories - btrtrc.git/blob - typed-roaring/bitmap.go
Drop support for go 1.20
[btrtrc.git] / typed-roaring / bitmap.go
1 package typedRoaring
2
3 import (
4         "github.com/RoaringBitmap/roaring"
5 )
6
7 type Bitmap[T BitConstraint] struct {
8         roaring.Bitmap
9 }
10
11 func (me *Bitmap[T]) Contains(x T) bool {
12         return me.Bitmap.Contains(uint32(x))
13 }
14
15 func (me Bitmap[T]) Iterate(f func(x T) bool) {
16         me.Bitmap.Iterate(func(x uint32) bool {
17                 return f(T(x))
18         })
19 }
20
21 func (me *Bitmap[T]) Add(x T) {
22         me.Bitmap.Add(uint32(x))
23 }
24
25 func (me *Bitmap[T]) Rank(x T) uint64 {
26         return me.Bitmap.Rank(uint32(x))
27 }
28
29 func (me *Bitmap[T]) CheckedRemove(x T) bool {
30         return me.Bitmap.CheckedRemove(uint32(x))
31 }
32
33 func (me *Bitmap[T]) Clone() Bitmap[T] {
34         return Bitmap[T]{*me.Bitmap.Clone()}
35 }
36
37 func (me *Bitmap[T]) CheckedAdd(x T) bool {
38         return me.Bitmap.CheckedAdd(uint32(x))
39 }
40
41 func (me *Bitmap[T]) Remove(x T) {
42         me.Bitmap.Remove(uint32(x))
43 }
44
45 // Returns an uninitialized iterator for the type of the receiver.
46 func (Bitmap[T]) IteratorType() Iterator[T] {
47         return Iterator[T]{}
48 }