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


Golang ring.Ring類代碼示例

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


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

示例1: outputBigram

func (s *CJKBigramFilter) outputBigram(r *ring.Ring, itemsInRing *int, pos int) *analysis.Token {
	if *itemsInRing == 2 {
		thisShingleRing := r.Move(-1)
		shingledBytes := make([]byte, 0)

		// do first token
		prev := thisShingleRing.Value.(*analysis.Token)
		shingledBytes = append(shingledBytes, prev.Term...)

		// do second token
		thisShingleRing = thisShingleRing.Next()
		curr := thisShingleRing.Value.(*analysis.Token)
		shingledBytes = append(shingledBytes, curr.Term...)

		token := analysis.Token{
			Type:     analysis.Double,
			Term:     shingledBytes,
			Position: pos,
			Start:    prev.Start,
			End:      curr.End,
		}
		return &token
	}
	return nil
}
開發者ID:bcampbell,項目名稱:bleve,代碼行數:25,代碼來源:cjk_bigram.go

示例2: 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}
}
開發者ID:acieroid,項目名稱:nov13,代碼行數:28,代碼來源:mainmenu.go

示例3: buildUnigram

func (s *CJKBigramFilter) buildUnigram(r *ring.Ring, itemsInRing *int, pos int) *analysis.Token {
	if *itemsInRing == 2 {
		thisShingleRing := r.Move(-1)
		// do first token
		prev := thisShingleRing.Value.(*analysis.Token)
		token := analysis.Token{
			Type:     analysis.Single,
			Term:     prev.Term,
			Position: pos,
			Start:    prev.Start,
			End:      prev.End,
		}
		return &token
	} else if *itemsInRing == 1 {
		// do first token
		prev := r.Value.(*analysis.Token)
		token := analysis.Token{
			Type:     analysis.Single,
			Term:     prev.Term,
			Position: pos,
			Start:    prev.Start,
			End:      prev.End,
		}
		return &token
	}
	return nil
}
開發者ID:bcampbell,項目名稱:bleve,代碼行數:27,代碼來源:cjk_bigram.go

示例4: printRing

func printRing(r *ring.Ring) {
	elements := make([]interface{}, 0, r.Len())
	r.Do(func(i interface{}) {
		elements = append(elements, i)
	})
	log.Printf("%v", elements)
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:7,代碼來源:ring.go

示例5: slicifyRing

func slicifyRing(r *ring.Ring) {
	l := r.Len()
	s := make([]WindowData, 0, l)
	for i := 0; i < l; i++ {
		s = append(s, r.Value.(WindowData))
		r = r.Prev()
	}
}
開發者ID:pavel-kolesnikov,項目名稱:window,代碼行數:8,代碼來源:window_test.go

示例6: slicifyRing

func slicifyRing(r *ring.Ring) {
	l := r.Len()
	s := make([]float64, 0, l)
	for i := 0; i < l; i++ {
		s = append(s, r.Value.(float64))
		r = r.Prev()
	}
}
開發者ID:postfix,項目名稱:golib-1,代碼行數:8,代碼來源:window_test.go

示例7: iterateRing

func iterateRing(rng *ring.Ring, out chan Pair) {
	i := 0

	rng.Do(func(ringCurrent interface{}) {
		out <- Pair{i, ringCurrent}
		i++
	})
}
開發者ID:gitter-badger,項目名稱:cfops,代碼行數:8,代碼來源:iterate.go

示例8: removeFromRing

func removeFromRing(r *ring.Ring, s string) *ring.Ring {
	newRing := ring.New(0)
	r.Do(func(v interface{}) {
		if v != s {
			newRing = addToRing(newRing, v.(string))
		}
	})
	return newRing
}
開發者ID:mashuai,項目名稱:pgreplicaproxy,代碼行數:9,代碼來源:ringutil.go

示例9: current_extremes

func current_extremes(r *ring.Ring) (int, int) {
	length := r.Len()
	if length%2 != 0 {
		fmt.Fprintln(os.Stderr, "error: Ring must be even")
		os.Exit(1)
	}
	fmt.Println(r.Value)

	return r.Value.(int), r.Move(length / 2).Value.(int)
}
開發者ID:igncp,項目名稱:code-gym,代碼行數:10,代碼來源:multiple-return.go

示例10: 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

示例11: 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

示例12: AddMessage

func (m *MessageBuffer) AddMessage(channel, message string) {
	if int32(m.buffer.Len()) >= m.maxsize { // buffer full?
		m.lostmsgs += 1
		return
	}
	var elem *ring.Ring = ring.New(1)
	var msg *bufferedMessage = &bufferedMessage{
		Channel: channel,
		Message: message,
	}
	elem.Value = msg
	// Add element elem to buffer.
	m.buffer.Prev().Link(elem)
}
開發者ID:tonnerre,項目名稱:justanotherircbot,代碼行數:14,代碼來源:messagebuffer.go

示例13: seed

func seed(r *ring.Ring) *ring.Ring {
	if r.Value == nil {
		r.Value = new(bucket)
	} else {
		r.Value.(*bucket).Reset()
	}
	return r
}
開發者ID:cyberdelia,項目名稱:circuitry,代碼行數:8,代碼來源:window.go

示例14: flush

func (s *CJKBigramFilter) flush(r *ring.Ring, itemsInRing *int, pos int) *analysis.Token {
	var rv *analysis.Token
	if *itemsInRing == 1 {
		rv = s.buildUnigram(r, itemsInRing, pos)
	}
	r.Value = nil
	*itemsInRing = 0
	return rv
}
開發者ID:bcampbell,項目名稱:bleve,代碼行數:9,代碼來源:cjk_bigram.go

示例15: 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()
	}
}
開發者ID:wheelcomplex,項目名稱:go-clockpro,代碼行數:18,代碼來源:clockpro.go


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