当前位置: 首页>>代码示例>>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;未经允许,请勿转载。