File: bitset_iter.go

package info (click to toggle)
golang-github-bits-and-blooms-bitset 1.22.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 760 kB
  • sloc: makefile: 3
file content (23 lines) | stat: -rw-r--r-- 433 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//go:build go1.23
// +build go1.23

package bitset

import (
	"iter"
	"math/bits"
)

func (b *BitSet) EachSet() iter.Seq[uint] {
	return func(yield func(uint) bool) {
		for wordIndex, word := range b.set {
			idx := 0
			for trail := bits.TrailingZeros64(word); trail != 64; trail = bits.TrailingZeros64(word >> idx) {
				if !yield(uint(wordIndex<<log2WordSize + idx + trail)) {
					return
				}
				idx += trail + 1
			}
		}
	}
}