本文整理汇总了Golang中container/ring.Ring.Link方法的典型用法代码示例。如果您正苦于以下问题:Golang Ring.Link方法的具体用法?Golang Ring.Link怎么用?Golang Ring.Link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类container/ring.Ring
的用法示例。
在下文中一共展示了Ring.Link方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewMainMenu
func NewMainMenu(mapDir string, w, h int) (m *MainMenu) {
file, err := os.Open(mapDir)
defer file.Close()
if err != nil {
panic(err)
}
fis, err := file.Readdir(0)
if err != nil {
panic(err)
}
var maps *ring.Ring
for _, fi := range fis {
if strings.HasSuffix(fi.Name(), ".txt") {
name := fi.Name()
mapName := name[:len(name)-4]
r := ring.New(1)
r.Value = mapName
if maps != nil {
maps.Link(r)
} else {
maps = r
}
}
}
return &MainMenu{maps, time.Now(), w, h}
}
示例2: meta_add
func (c *Cache) meta_add(key string, r *ring.Ring) {
c.evict()
c.keys[key] = r
r.Link(c.hand_hot)
if c.hand_hot == nil {
// first element
c.hand_hot = r
c.hand_cold = r
c.hand_test = r
}
if c.hand_cold == c.hand_hot {
c.hand_cold = c.hand_cold.Prev()
}
}
示例3: main
func main() {
var n, m int
f, _ := os.Create("yes.pprof")
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
fmt.Scan(&n)
fmt.Scan(&m)
bucket2number := make(map[int]*ring.Ring)
number2bucket := map[int]int{0: 0, n - 1: n - 1}
bucketlen := map[int]int{0: 1, n - 1: 1}
bucket2number[0] = ring.New(1)
bucket2number[0].Value = 0
bucket2number[n-1] = ring.New(1)
bucket2number[n-1].Value = n - 1
var a, b int
var la, lb *ring.Ring
var debug = false
for i := 0; i <= m; i++ {
fmt.Scan(&a, &b)
ba, ok := number2bucket[a]
if !ok {
number2bucket[a] = a
bucketlen[a] = 1
ba = a
la = ring.New(1)
la.Value = a
bucket2number[ba] = la
} else {
la = bucket2number[ba]
}
bb, ok := number2bucket[b]
if !ok {
number2bucket[b] = b
bucketlen[b] = 1
bb = b
lb = ring.New(1)
lb.Value = b
bucket2number[bb] = lb
} else {
lb = bucket2number[bb]
}
if ba != bb {
// Not connected yet
if bucketlen[ba] < bucketlen[bb] {
la, lb = lb, la
ba, bb = bb, ba
}
for j := 0; j < bucketlen[bb]; j++ {
number2bucket[lb.Value.(int)] = ba
lb = lb.Next()
}
la.Link(lb)
bucketlen[ba] += bucketlen[bb]
delete(bucket2number, bb)
if number2bucket[0] == number2bucket[n-1] {
fmt.Printf("Connected at %d\n", i)
return
}
}
if debug {
fmt.Printf("%d -> %d\n", a, b)
fmt.Print("Bucket2Number\n")
for k, v := range bucket2number {
fmt.Print(k)
v.Do(
func(x interface{}) {
fmt.Printf(" %d", x.(int))
})
fmt.Println()
}
fmt.Print("Number2Bucket\n")
for k, v := range number2bucket {
fmt.Printf("%d: %d\n", k, v)
}
}
}
fmt.Println("Not connected")
}