本文整理汇总了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;未经允许,请勿转载。 |
请发表评论