本文整理汇总了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
}
开发者ID:galthaus,项目名称:ocb-dhcp,代码行数:8,代码来源:subnet.go
示例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
}
开发者ID:Financial-Times,项目名称:publish-availability-monitor,代码行数:11,代码来源:imagesetUUIDGenerator.go
示例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
}
开发者ID:JustinAzoff,项目名称:flow-indexer,代码行数:12,代码来源:leveldb.go
示例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))
}
开发者ID:uwedeportivo,项目名称:codejam,代码行数:52,代码来源:main.go
示例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())
}
}
开发者ID:nstehr,项目名称:go-nami,代码行数:22,代码来源:client_filehandler.go
示例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
}
开发者ID:RoaringBitmap,项目名称:roaring,代码行数:23,代码来源:smat.go
示例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
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:14,代码来源:roaring_test.go
示例8: FlipRange
func FlipRange(start, end int, bs *bitset.BitSet) {
for i := start; i < end; i++ {
bs.Flip(uint(i))
}
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:5,代码来源:roaring_test.go
示例9: Similarity
func Similarity(a, b *bitset.BitSet, nHashes uint) float64 {
count := a.SymmetricDifferenceCardinality(b)
return 1. - float64(count)/float64(nHashes)
}
开发者ID:postfix,项目名称:rphash,代码行数:4,代码来源:rp32.go
注:本文中的github.com/willf/bitset.BitSet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论