本文整理匯總了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
}
示例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}
}
示例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
}
示例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)
}
示例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()
}
}
示例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()
}
}
示例7: iterateRing
func iterateRing(rng *ring.Ring, out chan Pair) {
i := 0
rng.Do(func(ringCurrent interface{}) {
out <- Pair{i, ringCurrent}
i++
})
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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)
}
示例13: seed
func seed(r *ring.Ring) *ring.Ring {
if r.Value == nil {
r.Value = new(bucket)
} else {
r.Value.(*bucket).Reset()
}
return r
}
示例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
}
示例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()
}
}