本文整理汇总了Golang中github.com/willf/bitset.BitSet类的典型用法代码示例。如果您正苦于以下问题:Golang BitSet类的具体用法?Golang BitSet怎么用?Golang BitSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BitSet类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: firstClearBit
func firstClearBit(bs *bitset.BitSet) (uint, bool) {
for i := uint(0); i < bs.Len(); i++ {
if !bs.Test(i) {
return i, true
}
}
return 0, false
}
示例2: toBitSet
func toBitSet(number uint64) bitset.BitSet {
lsbString := strconv.FormatUint(number, 2)
var b bitset.BitSet
for i, character := range lsbString {
if character == '1' {
b.Set(uint(len(lsbString)-1) - uint(i))
}
}
return b
}
示例3: bitsetToDocs
func (ls *LevelDBStore) bitsetToDocs(bs *bitset.BitSet) ([]string, error) {
var err error
var docs []string
for i, e := bs.NextSet(0); e; i, e = bs.NextSet(i + 1) {
name, err := ls.DocumentIDToName(uint64(i))
if err != nil {
break
}
docs = append(docs, name)
}
return docs, err
}
示例4: solve
func solve(pr *codejam.Problem, d *data) {
n := len(d.pairs)
ais := make([]int, n)
bis := make([]int, n)
for i := 0; i < n; i++ {
ais[i] = i
bis[i] = i
}
psa := &pairSorter{
indices: ais,
pairs: d.pairs,
column: 0,
}
psb := &pairSorter{
indices: bis,
pairs: d.pairs,
column: 1,
}
sort.Sort(psa)
sort.Sort(psb)
var nw int
for i := 0; i < n-1; i++ {
v := d.pairs[ais[i]][1]
k := sort.Search(n, func(j int) bool {
return d.pairs[bis[j]][1] >= v
})
// count common indices from ais[i+1:] and bis[:k]
var ba bitset.BitSet
var bb bitset.BitSet
for _, c := range ais[i+1:] {
ba.Set(uint(c))
}
for _, c := range bis[:k] {
bb.Set(uint(c))
}
nw += int(ba.IntersectionCardinality(&bb))
}
pr.Write(fmt.Sprintf("Case #%d: %d\n", d.testIndex, nw))
}
示例5: requestRetransmit
func requestRetransmit(blocks []int, bs *bitset.BitSet, conn net.Conn, e Encoder, isRestart bool) {
if len(blocks) <= 0 {
return
}
var missingBlocks []int
if isRestart {
missingBlocks = blocks[0:1]
} else {
for _, b := range blocks {
if !bs.Test(uint(b)) {
missingBlocks = append(missingBlocks, b)
}
}
}
payload := Retransmit{IsRestart: isRestart, BlockNums: missingBlocks}
pkt := Packet{Type: RETRANSMIT, Payload: payload}
_, err := sendPacket(&pkt, conn, e)
if err != nil {
log.Println("Error sending retransmit blocks: " + err.Error())
}
}
示例6: equalsBitSet
func (p *smatPair) equalsBitSet(a *bitset.BitSet, b *Bitmap) bool {
for i, e := a.NextSet(0); e; i, e = a.NextSet(i + 1) {
if !b.ContainsInt(int(i)) {
fmt.Printf("in a bitset, not b bitmap, i: %d\n", i)
fmt.Printf(" a bitset: %s\n b bitmap: %s\n",
a.String(), b.String())
return false
}
}
i := b.Iterator()
for i.HasNext() {
v := i.Next()
if !a.Test(uint(v)) {
fmt.Printf("in b bitmap, not a bitset, v: %d\n", v)
fmt.Printf(" a bitset: %s\n b bitmap: %s\n",
a.String(), b.String())
return false
}
}
return true
}
示例7: equalsBitSet
func equalsBitSet(a *bitset.BitSet, b *Bitmap) bool {
for i, e := a.NextSet(0); e; i, e = a.NextSet(i + 1) {
if !b.ContainsInt(int(i)) {
return false
}
}
i := b.Iterator()
for i.HasNext() {
if !a.Test(uint(i.Next())) {
return false
}
}
return true
}
示例8: FlipRange
func FlipRange(start, end int, bs *bitset.BitSet) {
for i := start; i < end; i++ {
bs.Flip(uint(i))
}
}
示例9: Similarity
func Similarity(a, b *bitset.BitSet, nHashes uint) float64 {
count := a.SymmetricDifferenceCardinality(b)
return 1. - float64(count)/float64(nHashes)
}