當前位置: 首頁>>代碼示例>>Golang>>正文


Golang bitset.BitSet類代碼示例

本文整理匯總了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;未經允許,請勿轉載。