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


Golang address.Range類代碼示例

本文整理匯總了Golang中github.com/weaveworks/weave/net/address.Range的典型用法代碼示例。如果您正苦於以下問題:Golang Range類的具體用法?Golang Range怎麽用?Golang Range使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Range類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: walkFree

// Walk down the free list calling f() on the in-range portions, until
// f() returns true or we run out of free space.  Return true iff f() returned true
func (s *Space) walkFree(r address.Range, f func(address.Range) bool) bool {
	if r.Start >= r.End { // degenerate case
		return false
	}
	for i := 0; i < len(s.free); i += 2 {
		chunk := address.Range{Start: s.free[i], End: s.free[i+1]}
		if chunk.End <= r.Start { // this chunk comes before the range
			continue
		}
		if chunk.Start >= r.End {
			// all remaining free space is completely after range
			break
		}
		// at this point we know chunk.End>chunk.Start &&
		// chunk.End>r.Start && r.End>chunk.Start && r.End>r.Start
		// therefore max(start, r.Start) < min(end, r.End)
		// Restrict this block of free space to be in range
		if chunk.Start < r.Start {
			chunk.Start = r.Start
		}
		if chunk.End > r.End {
			chunk.End = r.End
		}
		// at this point we know start<end
		if f(chunk) {
			return true
		}
	}
	return false
}
開發者ID:codingbunch,項目名稱:weave,代碼行數:32,代碼來源:space.go

示例2: ownedInRange

func (alloc *Allocator) ownedInRange(ident string, r address.Range) (address.Address, bool) {
	for _, addr := range alloc.owned[ident] {
		if r.Contains(addr) {
			return addr, true
		}
	}
	return 0, false
}
開發者ID:ybalt,項目名稱:weave,代碼行數:8,代碼來源:allocator.go

示例3: ownedInRange

func (alloc *Allocator) ownedInRange(ident string, r address.Range) []address.CIDR {
	var c []address.CIDR
	for _, cidr := range alloc.owned[ident].Cidrs {
		if r.Contains(cidr.Addr) {
			c = append(c, cidr)
		}
	}
	return c
}
開發者ID:n054,項目名稱:weave,代碼行數:9,代碼來源:allocator.go

示例4: spaceRequestDenied

func (alloc *Allocator) spaceRequestDenied(sender mesh.PeerName, r address.Range) {
	for i := 0; i < len(alloc.pendingClaims); {
		claim := alloc.pendingClaims[i].(*claim)
		if r.Contains(claim.addr) {
			claim.deniedBy(alloc, sender)
			alloc.pendingClaims = append(alloc.pendingClaims[:i], alloc.pendingClaims[i+1:]...)
			continue
		}
		i++
	}
}
開發者ID:ybalt,項目名稱:weave,代碼行數:11,代碼來源:allocator.go

示例5: NewAllocator

// NewAllocator creates and initialises a new Allocator
func NewAllocator(ourName router.PeerName, ourUID router.PeerUID, ourNickname string, universe address.Range, quorum uint) *Allocator {
	return &Allocator{
		ourName:   ourName,
		universe:  universe,
		ring:      ring.New(universe.Start, address.Add(universe.Start, universe.Size()), ourName),
		owned:     make(map[string][]address.Address),
		paxos:     paxos.NewNode(ourName, ourUID, quorum),
		nicknames: map[router.PeerName]string{ourName: ourNickname},
		now:       time.Now,
	}
}
開發者ID:bohrqiu,項目名稱:weave,代碼行數:12,代碼來源:allocator.go


注:本文中的github.com/weaveworks/weave/net/address.Range類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。