本文整理汇总了Golang中container/ring.Ring类的典型用法代码示例。如果您正苦于以下问题:Golang Ring类的具体用法?Golang Ring怎么用?Golang Ring使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ring类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: meta_del
func (c *Cache) meta_del(r *ring.Ring) {
delete(c.keys, r.Value.(*entry).key)
if r == c.hand_hot {
c.hand_hot = c.hand_hot.Prev()
}
if r == c.hand_cold {
c.hand_cold = c.hand_cold.Prev()
}
if r == c.hand_test {
c.hand_test = c.hand_test.Prev()
}
r.Prev().Unlink(1)
}
开发者ID:wheelcomplex,项目名称:go-clockpro,代码行数:18,代码来源:clockpro.go
示例17: 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
示例18: read
func (rb *ringBuffer) read(lines int) []string {
if lines <= 0 {
return []string{}
}
// Only need a read lock because nothing we're about to do affects the internal state of the
// ringBuffer. Mutliple reads can happen in parallel. Only writing requires an exclusive lock.
rb.mutex.RLock()
defer rb.mutex.RUnlock()
var start *ring.Ring
if lines < rb.ring.Len() {
start = rb.ring.Move(-1 * (lines - 1))
} else {
start = rb.ring.Next()
}
data := make([]string, 0, lines)
start.Do(func(line interface{}) {
if line == nil || lines <= 0 {
return
}
lines--
data = append(data, line.(string))
})
return data
}
开发者ID:jchauncey,项目名称:logger,代码行数:24,代码来源:adapter.go
示例19: shingleCurrentRingState
func (s *ShingleFilter) shingleCurrentRingState(ring *ring.Ring, itemsInRing int) analysis.TokenStream {
rv := make(analysis.TokenStream, 0)
for shingleN := s.min; shingleN <= s.max; shingleN++ {
// if there are enough items in the ring
// to produce a shingle of this size
if itemsInRing >= shingleN {
thisShingleRing := ring.Move(-(shingleN - 1))
shingledBytes := make([]byte, 0)
pos := 0
start := -1
end := 0
for i := 0; i < shingleN; i++ {
if i != 0 {
shingledBytes = append(shingledBytes, []byte(s.tokenSeparator)...)
}
curr := thisShingleRing.Value.(*analysis.Token)
if pos == 0 && curr.Position != 0 {
pos = curr.Position
}
if start == -1 && curr.Start != -1 {
start = curr.Start
}
if curr.End != -1 {
end = curr.End
}
shingledBytes = append(shingledBytes, curr.Term...)
thisShingleRing = thisShingleRing.Next()
}
token := analysis.Token{
Type: analysis.Shingle,
Term: shingledBytes,
}
if pos != 0 {
token.Position = pos
}
if start != -1 {
token.Start = start
}
if end != -1 {
token.End = end
}
rv = append(rv, &token)
}
}
return rv
}
开发者ID:ekanite,项目名称:bleve,代码行数:46,代码来源:shingle.go
示例20: 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
注:本文中的container/ring.Ring类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论