func (rb *RoaringBitmap) Iterator() <-chan uint32 {
	ch := make(chan uint32)
	go func() {
		for _, entry := range rb.containers {
			hs := uint32(entry.key) << 16
			switch typedContainer := entry.container.(type) {
			case *arrayContainer:
				pos := 0
				for pos < typedContainer.cardinality {
					ls := typedContainer.content[pos]
					pos = pos + 1
					ch <- (hs | uint32(ls))
				}
			case *bitmapContainer:
				i := typedContainer.nextSetBit(0)
				for i >= 0 {
					ch <- (hs | uint32(i))
					i = typedContainer.nextSetBit(i + 1)
				}
			}
		}
		close(ch)
	}()
	return ch
}
Iterator returns an iterator over the RoaringBitmap which can be used with "for range".
package goroar
import (
	"bytes"
	"fmt"
	"log"
	"os"
	"strconv"
	"text/template"
)
type entry struct {
	key       uint16
	container container
}
type RoaringBitmap struct {
	containers []entry
}
func New() *RoaringBitmap {
	containers := make([]entry, 0, 4)
	return &RoaringBitmap{containers}
}
func BitmapOf(values ...uint32) *RoaringBitmap {
	rb := New()
	for _, value := range values {
		rb.Add(value)
	}
	return rb
}
func (rb *RoaringBitmap) Add(x uint32) {
	hb, lb := highlowbits(x)
	pos := rb.containerIndex(hb)
	if pos >= 0 {
		container := rb.containers[pos].container
		rb.containers[pos].container = container.add(lb)
	} else {
		ac := newArrayContainer()
		ac.add(lb)
		rb.increaseCapacity()
		loc := -pos - 1
		rb.containers = rb.containers[:len(rb.containers)+1]
		copy(rb.containers[loc+1:], rb.containers[loc:])
		e := entry{hb, ac}
		rb.containers[loc] = e
	}
}
func (rb *RoaringBitmap) Contains(i uint32) bool {
	pos := rb.containerIndex(highbits(i))
	if pos < 0 {
		return false
	}
	return rb.containers[pos].container.contains(lowbits(i))
}
func (rb *RoaringBitmap) Cardinality() int {
	var cardinality int
	for _, entry := range rb.containers {
		cardinality = cardinality + entry.container.getCardinality()
	}
	return cardinality
}
func (rb *RoaringBitmap) And(other *RoaringBitmap) {
	pos1 := 0
	pos2 := 0
	length1 := len(rb.containers)
	length2 := len(other.containers)
Main:
	for pos1 < length1 && pos2 < length2 {
		s1 := rb.keyAtIndex(pos1)
		s2 := other.keyAtIndex(pos2)
		for {
			if s1 < s2 {
				rb.removeAtIndex(pos1)
				length1 = length1 - 1
				if pos1 == length1 {
					break Main
				}
				s1 = rb.keyAtIndex(pos1)
			} else if s1 > s2 {
				pos2 = pos2 + 1
				if pos2 == length2 {
					break Main
				}
				s2 = other.keyAtIndex(pos2)
			} else {
				c := rb.containers[pos1].container.and(other.containers[pos2].container)
				if c.getCardinality() > 0 {
					rb.containers[pos1].container = c
					pos1 = pos1 + 1
				} else {
					rb.removeAtIndex(pos1)
					length1 = length1 - 1
				}
				pos2 = pos2 + 1
				if (pos1 == length1) || (pos2 == length2) {
					break Main
				}
				s1 = rb.keyAtIndex(pos1)
				s2 = other.keyAtIndex(pos2)
			}
		}
	}
	rb.resize(pos1)
}
func (rb *RoaringBitmap) Or(other *RoaringBitmap) {
	pos1, pos2 := 0, 0
	length1 := len(rb.containers)
	length2 := len(other.containers)
main:
	for pos1 < length1 && pos2 < length2 {
		s1 := rb.keyAtIndex(pos1)
		s2 := other.keyAtIndex(pos2)
		for {
			if s1 < s2 {
				pos1++
				if pos1 == length1 {
					break main
				}
				s1 = rb.keyAtIndex(pos1)
			} else if s1 > s2 {
				rb.insertAt(pos1, s2, other.containers[pos2].container)
				pos1++
				length1++
				pos2++
				if pos2 == length2 {
					break main
				}
				s2 = other.containers[pos2].key
			} else {
				rb.containers[pos1].container = rb.containers[pos1].container.or(other.containers[pos2].container)
				pos1++
				pos2++
				if pos1 == length1 || pos2 == length2 {
					break main
				}
				s1 = rb.containers[pos1].key
				s2 = other.containers[pos2].key
			}
		}
	}
	if pos1 == length1 {
		rb.containers = append(rb.containers, other.containers[pos2:length2]...)
	}
}
func (rb *RoaringBitmap) Xor(other *RoaringBitmap) {
	pos1, pos2 := 0, 0
	length1 := len(rb.containers)
	length2 := len(other.containers)
main:
	for pos1 < length1 && pos2 < length2 {
		s1 := rb.keyAtIndex(pos1)
		s2 := other.keyAtIndex(pos2)
		for {
			if s1 < s2 {
				pos1++
				if pos1 == length1 {
					break main
				}
				s1 = rb.keyAtIndex(pos1)
			} else if s1 > s2 {
				rb.insertAt(pos1, s2, other.containers[pos2].container)
				pos1++
				length1++
				pos2++
				if pos2 == length2 {
					break main
				}
				s2 = other.containers[pos2].key
			} else {
				c := rb.containers[pos1].container.xor(other.containers[pos2].container)
				if c.getCardinality() > 0 {
					rb.containers[pos1].container = c
					pos1++
				} else {
					rb.removeAtIndex(pos1)
					length1--
				}
				pos2++
				if pos1 == length1 || pos2 == length2 {
					break main
				}
				s1 = rb.containers[pos1].key
				s2 = other.containers[pos2].key
			}
		}
	}
	if pos1 == length1 {
		rb.containers = append(rb.containers, other.containers[pos2:length2]...)
	}
}
func (rb *RoaringBitmap) AndNot(other *RoaringBitmap) {
	pos1, pos2 := 0, 0
	length1 := len(rb.containers)
	length2 := len(other.containers)
main:
	for pos1 < length1 && pos2 < length2 {
		s1 := rb.keyAtIndex(pos1)
		s2 := other.keyAtIndex(pos2)
		for {
			if s1 < s2 {
				pos1++
				if pos1 == length1 {
					break main
				}
				s1 = rb.keyAtIndex(pos1)
			} else if s1 > s2 {
				pos2++
				if pos2 == length2 {
					break main
				}
				s2 = other.containers[pos2].key
			} else {
				c := rb.containers[pos1].container.andNot(other.containers[pos2].container)
				if c.getCardinality() > 0 {
					rb.containers[pos1].container = c
					pos1++
				} else {
					rb.removeAtIndex(pos1)
					length1--
				}
				pos2++
				if pos1 == length1 || pos2 == length2 {
					break main
				}
				s1 = rb.containers[pos1].key
				s2 = other.containers[pos2].key
			}
		}
	}
}