本文整理匯總了Golang中container/list.Element.Prev方法的典型用法代碼示例。如果您正苦於以下問題:Golang Element.Prev方法的具體用法?Golang Element.Prev怎麽用?Golang Element.Prev使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類container/list.Element
的用法示例。
在下文中一共展示了Element.Prev方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TimeEvict
// this time eviction is called by a scheduler for background, periodic evictions
func TimeEvict(lru *LRUCache, now time.Time, ttl time.Duration) {
lru.mu.Lock()
defer lru.mu.Unlock()
if lru.list.Len() < 1 {
return
}
var n *entry
var el *list.Element
hasEvictCallback := lru.EvictCallback != nil
el = lru.list.Back()
for {
if el == nil {
break
}
n = el.Value.(*entry)
if now.Sub(n.time_accessed) > ttl {
// the Difference is greater than max TTL so we need to evict this entry
// first grab the next entry (as this is about to dissappear)
el = el.Prev()
lru.remove(n.key)
if hasEvictCallback {
lru.EvictCallback(n.key, n.value)
}
} else {
// since they are stored in time order, as soon as we find
// first item newer than ttl window, we are safe to bail
break
}
}
lru.last_ttl_check = time.Now()
}
示例2: incrElement
func (s *Summary) incrElement(el *list.Element) {
counter := el.Value.(*Counter)
counter.count++
// This element already has the largest count so it won't get moved.
if s.list.Front() == el {
return
}
// Starting at the previous element, move this element behind the first
// element we find which has a higher count.
moved := false
for currEl := el.Prev(); currEl != nil; currEl = currEl.Prev() {
if currEl.Value.(*Counter).count > counter.count {
s.list.MoveAfter(el, currEl)
moved = true
break
}
}
// If we didn't find an element with a higher count then this element must
// have the highest count. Move it to the front.
if !moved {
s.list.MoveToFront(el)
}
}
示例3: ValueChanged
func (me *orderedList) ValueChanged(e *list.Element) {
for prev := e.Prev(); prev != nil && me.lessFunc(e.Value, prev.Value); prev = e.Prev() {
me.list.MoveBefore(e, prev)
}
for next := e.Next(); next != nil && me.lessFunc(next.Value, e.Value); next = e.Next() {
me.list.MoveAfter(e, next)
}
}
示例4: findForAddY
func (o *ObjectIndex) findForAddY(item Coordsable) *list.Element {
y := item.GetCoords().Y
var e *list.Element
for e = o.listY.Front(); e != nil; e = e.Next() {
if e.Value.(Coordsable).GetCoords().Y > y {
return e.Prev()
}
if e.Next() == nil {
return e
}
}
return nil
}
示例5: ikcp_parse_data
//---------------------------------------------------------------------
// parse data
//---------------------------------------------------------------------
func ikcp_parse_data(kcp *Ikcpcb, newseg *IKCPSEG) {
var p *list.Element
sn := newseg.sn
repeat := 0
if _itimediff(sn, kcp.rcv_nxt+kcp.rcv_wnd) >= 0 ||
_itimediff(sn, kcp.rcv_nxt) < 0 {
return
}
for p = kcp.rcv_buf.Back(); p != nil; p = p.Prev() {
seg := p.Value.(*IKCPSEG)
if seg.sn == sn {
repeat = 1
break
}
if _itimediff(sn, seg.sn) > 0 {
break
}
}
if repeat == 0 {
if p == nil {
kcp.rcv_buf.PushFront(newseg)
} else {
kcp.rcv_buf.InsertAfter(newseg, p)
}
kcp.nrcv_buf++
} else {
}
for p = kcp.rcv_buf.Front(); p != nil; {
seg := p.Value.(*IKCPSEG)
if seg.sn == kcp.rcv_nxt && kcp.nrcv_que < kcp.rcv_wnd {
q := p.Next()
kcp.rcv_buf.Remove(p)
p = q
kcp.nrcv_buf--
kcp.rcv_queue.PushBack(seg)
//if kcp.user[0] == 0 {
//fmt.Println("insert from recvqueue2", kcp.rcv_queue.Len(), kcp.user)
//}
kcp.nrcv_que++
kcp.rcv_nxt++
} else {
break
}
}
//println("inputok!!!", kcp.nrcv_buf, kcp.nrcv_que, repeat, kcp.rcv_nxt, sn)
}
示例6: ResortElement
func (o *ObjectIndex) ResortElement(element *list.Element) {
coords := element.Value.(Coordsable).GetCoords()
for e := element.Prev(); e != nil; e = element.Prev() {
if e.Value.(Coordsable).GetCoords().X < coords.X {
break
}
o.listX.MoveBefore(element, e)
}
for e := element.Next(); e != nil; e = element.Next() {
if e.Value.(Coordsable).GetCoords().X > coords.X {
break
}
o.listX.MoveAfter(element, e)
}
}
示例7: elemLabelStmt
func (p *Program) elemLabelStmt(elem *list.Element) *LabelStatement {
if elem == nil {
return nil
}
stmt, ok := elem.Value.(*LabelStatement)
if ok {
return stmt
}
prev := elem.Prev()
if prev != nil {
stmt, ok = prev.Value.(*LabelStatement)
if ok {
return stmt
}
}
return nil
}
示例8: Tokenize
func (this *Tokenizer) Tokenize(p string, offset int, v *list.List) {
var t [10]string
var i *list.Element
var match bool
substr := 0
ln := 0
v = v.Init()
cont := 0
for cont < len(p) {
for WhiteSpace(p[cont]) {
cont++
offset++
}
LOG.Trace("Tokenizing [" + p[cont:] + "]")
match = false
for i = this.rules.Front(); i != nil && !match; i = i.Next() {
LOG.Trace("Checking rule " + i.Value.(Pair).first.(string))
ps := strings.Index(p[cont:], " ")
delta := cont + ps
if ps == -1 {
delta = cont + len(p) - cont
}
results := RegExHasSuffix(i.Value.(Pair).second.(*regexp.Regexp), p[cont:delta])
if len(results) > 0 {
match = true
ln = 0
substr = this.matches[i.Value.(Pair).first.(string)]
for j := If(substr == 0, 0, 1).(int); j <= substr && match; j++ {
t[j] = results[j]
ln += len(t[j])
LOG.Trace("Found match " + strconv.Itoa(j) + " [" + t[j] + "] for rule " + i.Value.(Pair).first.(string))
if string(i.Value.(Pair).first.(string)[0]) == "*" {
lower := strings.ToLower(t[j])
if !this.abrevs.Has(lower) {
match = false
LOG.Trace("Special rule and found match not in abbrev list. Rule not satisfied")
}
}
}
}
}
if match {
if i == nil {
i = this.rules.Back()
} else {
i = i.Prev()
}
substr = this.matches[i.Value.(Pair).first.(string)]
for j := If(substr == 0, 0, 1).(int); j <= substr && match; j++ {
if len(t[j]) > 0 {
LOG.Trace("Accepting matched substring [" + t[j] + "]")
w := NewWordFromLemma(t[j])
w.setSpan(offset, offset+len(t[j]))
offset += len(t[j])
v.PushBack(w)
} else {
LOG.Trace("Skipping matched null substring [" + t[j] + "]")
}
}
cont += ln
} else if cont < len(p) {
LOG.Warn("No rule matched input substring" + p[cont:] + " . Character " + string(p[cont:][0]) + " skipped . Check your tokenization rules")
cont++
}
}
offset++
}
示例9: annotate
//.........這裏部分代碼省略.........
//kd := make(map[string]float64)
//ks := make(map[string]string)
var tag string
var t int
tr := NewTrellis(se.Len()+1, this.kbest)
lemm = this.FindStates(se)
w = se.Front()
emms = lemm.Front()
for i, _ := range emms.Value.(*set.Set).List() {
tk := emms.Value.(*set.Set).List()[i]
k := tk.(*Bigram)
pi = this.ProbPi_log(k)
emm = this.ProbB_log(k, w.Value.(*Word))
aux = pi + emm
tr.insert(0, k, tr.InitState, 0, aux)
}
t = 1
emmsant = lemm.Front()
emms = lemm.Front().Next()
for w = se.Front().Next(); w != nil; w = w.Next() {
for _, k := range emms.Value.(*set.Set).List() {
emm = this.ProbB_log(k.(*Bigram), w.Value.(*Word))
for _, kant := range emmsant.Value.(*set.Set).List() {
if kant.(*Bigram).Second == k.(*Bigram).First {
for kb := 0; kb < tr.nbest(t-1, kant.(*Bigram)); kb++ {
pant := tr.delta(t-1, kant.(*Bigram), kb)
ptrans := this.ProbA_log(kant.(*Bigram), k.(*Bigram), w)
aux = pant + ptrans + emm
tr.insert(t, k.(*Bigram), kant.(*Bigram), kb, aux)
}
}
}
}
t++
emmsant = emms
emms = emms.Next()
}
max = TRELLIS_ZERO_logprob
w = se.Back()
emms = lemm.Back()
for _, k := range emms.Value.(*set.Set).List() {
for kb := 0; kb < tr.nbest(se.Len()-1, k.(*Bigram)); kb++ {
aux = tr.delta(se.Len()-1, k.(*Bigram), kb)
tr.insert(se.Len(), tr.EndState, k.(*Bigram), kb, aux)
}
}
for w := se.Front(); w != nil; w = w.Next() {
w.Value.(*Word).unselectAllAnalysis(0)
}
for bp := 0; bp < tr.nbest(se.Len(), tr.EndState); bp++ {
back := tr.phi(se.Len(), tr.EndState, bp)
st := back.first.(*Bigram)
kb := back.second.(int)
tag = st.Second
w = se.Back()
for t := se.Len() - 1; t >= 0; t-- {
bestk := list.New()
max = 0.0
for ka = w.Value.(*Word).Front(); ka != nil; ka = ka.Next() {
if this.Tags.GetShortTag(ka.Value.(*Analysis).getTag()) == tag {
if ka.Value.(*Analysis).getProb() > max {
max = ka.Value.(*Analysis).getProb()
bestk = bestk.Init()
bestk.PushBack(ka.Value.(*Analysis))
} else if ka.Value.(*Analysis).getProb() == max {
bestk.PushBack(ka.Value.(*Analysis))
}
}
}
for k := bestk.Front(); k != nil; k = k.Next() {
w.Value.(*Word).selectAnalysis(k.Value.(*Analysis), bp)
}
if t > 0 {
back = tr.phi(t, st, kb)
st = back.first.(*Bigram)
kb = back.second.(int)
tag = st.Second
w = w.Prev()
}
}
}
TRACE(3, "sentence analyzed", MOD_HMM)
}