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


Golang Ring.Next方法代碼示例

本文整理匯總了Golang中container/ring.Ring.Next方法的典型用法代碼示例。如果您正苦於以下問題:Golang Ring.Next方法的具體用法?Golang Ring.Next怎麽用?Golang Ring.Next使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在container/ring.Ring的用法示例。


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

示例1: findInRing

func findInRing(in *ring.Ring, f func(r interface{}) bool) *ring.Ring {
	if f(in.Value) {
		return in
	}
	for p := in.Next(); p != in; p = p.Next() {
		if f(p.Value) {
			return p
		}
	}
	return nil
}
開發者ID:welterde,項目名稱:go-nntp,代碼行數:11,代碼來源:exampleserver.go

示例2: containsTask

func containsTask(finishedTasks *ring.Ring, taskId string) bool {
	for i := 0; i < defaultFinishedTasksSize; i++ {
		value := finishedTasks.Next().Value
		if value == nil {
			continue
		}
		if value.(string) == taskId {
			return true
		}
	}
	return false
}
開發者ID:jdef,項目名稱:kubernetes-mesos,代碼行數:12,代碼來源:scheduler.go

示例3: RingToStringInt64

func RingToStringInt64(r *ring.Ring, delim string, delta bool) string {
	bb := new(bytes.Buffer)
	prev := r.Value.(int64)
	r = r.Next()
	for i := 1; i < r.Len(); i++ {
		if delta {
			if r.Value.(int64) == int64(0) {
				bb.WriteString(fmt.Sprintf("0%s", delim))
			} else {
				d := r.Value.(int64) - prev
				bb.WriteString(fmt.Sprintf("%d%s", d, delim))
			}
			prev = r.Value.(int64)
		} else {
			bb.WriteString(fmt.Sprintf("%d%s", r.Value.(int64), delim))
		}
		r = r.Next()
	}
	return strings.TrimSuffix(bb.String(), delim)
}
開發者ID:bocajim,項目名稱:helpers,代碼行數:20,代碼來源:ring.go

示例4: generadorTPS

func generadorTPS(nroMaxPeticiones uint64, lambda float64, q chan<- []byte, contadorPeticiones *uint64, forever bool, tiras *ring.Ring, procesoLlegada string) {
	if procesoLlegada == "M" {
		for ; forever || *contadorPeticiones < nroMaxPeticiones; *contadorPeticiones++ {
			time.Sleep(time.Duration(int64(1000000000.0 * rand.ExpFloat64() / lambda)))
			q <- (tiras.Value.([]byte))
			tiras = tiras.Next()
		}
	} else { /* procesoLlegada == "D" */
		// Utilizo un Ticker como referencia.
		// Lo encapsulo en generadorTPS porque el Ticker utiliza un canal sincrono.
		// aunque el ticker nunca se bloquea
		ticker := time.NewTicker(time.Duration(int64(1000000000.0 / lambda)))

		for ; forever || *contadorPeticiones < nroMaxPeticiones; *contadorPeticiones++ {
			<-ticker.C
			q <- (tiras.Value.([]byte))
			tiras = tiras.Next()
		}

		ticker.Stop()
	}
	close(q)
}
開發者ID:Rezax07,項目名稱:pruebas,代碼行數:23,代碼來源:stress.go

示例5: 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")
}
開發者ID:dpaneda,項目名稱:code,代碼行數:95,代碼來源:yes.go

示例6: rollup

func rollup(r *ring.Ring) *ring.Ring {
	n := r.Next()
	return seed(n)
}
開發者ID:cyberdelia,項目名稱:circuitry,代碼行數:4,代碼來源:window.go


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