本文整理匯總了Golang中container/list.List.Back方法的典型用法代碼示例。如果您正苦於以下問題:Golang List.Back方法的具體用法?Golang List.Back怎麽用?Golang List.Back使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類container/list.List
的用法示例。
在下文中一共展示了List.Back方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sync_subs
/* synchronize subtitles by knowing the time of the first and the last subtitle.
* to archive this we must use the linear equation: y = mx + b */
func sync_subs(subs *list.List, synced_first_ms uint, synced_last_ms uint) {
var slope, yint float64
desynced_first_ms := subs.Front().Value.(*subtitle).start
desynced_last_ms := subs.Back().Value.(*subtitle).start
/* m = (y2 - y1) / (x2 - x1)
* m: slope
* y2: synced_last_ms
* y1: synced_first_ms
* x2: desynced_last_ms
* x1: desynced_first_ms */
slope = float64(synced_last_ms-synced_first_ms) / float64(desynced_last_ms-desynced_first_ms)
/* b = y - mx
* b: yint
* y: synced_last_ms
* m: slope
* x: desynced_last_ms */
yint = float64(synced_last_ms) - slope*float64(desynced_last_ms)
for e := subs.Front(); e != nil; e = e.Next() {
sub := e.Value.(*subtitle)
/* y = mx + b
* y: sub.start and sub.end
* m: slope
* x: sub.start and sub.end
* b: yint */
sub.start = uint(roundFloat64(slope*float64(sub.start) + yint))
sub.end = uint(roundFloat64(slope*float64(sub.end) + yint))
}
}
示例2: addIfHigh
// Adds the given story id and bayes factor to the given list if it
// is higher than at least one of the ones already in the list
func addIfHigh(scores *list.List, length int, storyid int64, k float64) {
s := score{storyid: storyid, score: k}
// Add the score if the list is empty
last := scores.Back()
if last == nil {
scores.PushBack(s)
return
}
if scores.Len() < length {
insertScore(scores, length, s)
return
}
// Add the score to the list if it is high enough
lowest, ok := last.Value.(score)
if !ok {
log.Fatal("Could not extract score from sorted list")
}
if k < lowest.score {
return
}
// If this point is reached, we insert the score
insertScore(scores, length, s)
}
示例3: addResponseNodesToSL
//add Nodes we here about in the reply to the shortList, only if that node is not in the sentList
func addResponseNodesToSL(fnodes []FoundNode, shortList *list.List, sentMap map[ID]bool, targetID ID) {
for i := 0; i < len(fnodes); i++ {
foundNode := &fnodes[i]
_, inSentList := sentMap[foundNode.NodeID]
//if the foundNode is already in sentList, dont add it to shortList
if inSentList {
continue
}
for e := shortList.Front(); e != nil; e = e.Next() {
if e.Value.(*FoundNode).NodeID.Equals(foundNode.NodeID) {
break
}
dist := e.Value.(*FoundNode).NodeID.Distance(targetID)
foundNodeDist := foundNode.NodeID.Distance(targetID)
//if responseNode is closer than node in ShortList, add it
if foundNodeDist < dist {
shortList.InsertBefore(foundNode, e)
//keep the shortList length < Kconst
if shortList.Len() > KConst {
shortList.Remove(shortList.Back())
}
//node inserted! getout
break
}
}
}
}
示例4: Delete
func Delete(e Elem, L *list.List) bool {
ret := false
if L.Len() == 0 {
return ret
}
back := L.Back()
if e.GetTime() > back.Value.(Elem).GetTime() {
return ret
}
el := L.Front()
Loop:
for i := 0; el != nil; i++ {
elt := el.Value.(Elem).GetTime()
if elt > e.GetTime() {
break Loop
} else if e.IsEqual(el.Value.(Elem)) {
L.Remove(el)
ret = true
break Loop
}
el = el.Next()
}
return ret
}
示例5: Insert
func Insert(e Elem, L *list.List) int {
if L.Len() == 0 {
L.PushFront(e)
return L.Len()
}
front := L.Front()
if e.GetTime() < front.Value.(Elem).GetTime() {
L.InsertBefore(e, front)
return L.Len()
}
el := L.Back()
Loop:
for {
if el.Value.(Elem).GetTime() > e.GetTime() {
el = el.Prev()
} else {
break Loop
}
}
L.InsertAfter(e, el)
return L.Len()
}
示例6: registerNewVideos
func registerNewVideos(videos *list.List) {
insertCount := 0
startVideoId := ""
endVideoId := ""
for video := videos.Back(); video != nil; video = video.Prev() {
videoObj := video.Value.(map[string]string)
if isExistsVideo(videoObj["id"]) {
continue
}
stmtIns, stmtInsErr := db.Prepare("INSERT INTO new_videos (id, title, post_datetime, status) VALUES( ?, ?, ?, ?)")
if stmtInsErr != nil {
panic(stmtInsErr.Error())
}
defer stmtIns.Close()
// fmt.Println(videoObj["id"], " ", videoObj["datetime"], " ", videoObj["title"])
insertCount++
if startVideoId == "" {
startVideoId = videoObj["id"]
}
endVideoId = videoObj["id"]
_, insErr := stmtIns.Exec(videoObj["id"], videoObj["title"], videoObj["datetime"], 0)
if insErr != nil {
panic(insErr.Error())
}
}
fmt.Println("datetime=[" + time.Now().String() + "] insertCount=[" + fmt.Sprint(insertCount) + "] startVideoId=[" + startVideoId + "] endVideoId=[" + endVideoId + "]")
}
示例7: findSource
// findSource tries to find corresponding Send event to ev.
func findSource(sends *list.List, ev *trace.Event) *trace.Event {
for e := sends.Back(); e != nil; e = e.Prev() {
send := e.Value.(*trace.Event)
if send.Args[1] == ev.Args[1] && send.Args[0] == ev.Args[0] {
sends.Remove(e)
return send
}
}
return nil
}
示例8: endOfSentence
func (this *Splitter) endOfSentence(w *list.Element, v *list.List) bool {
if w == v.Back() {
return true
} else {
r := w
r = r.Next()
f := r.Value.(*Word).getForm()
return strings.Title(f) == f || this.starters.Has(f)
}
}
示例9: find
// find is used to locate an element in a list by value. It will
// return true and a pointer to the element if the element was found
// and false and a pointer to the last element of the list (or nil)
// otherwise.
func find(lst *list.List, value Vertex) (bool, *list.Element) {
elem := lst.Front()
if elem != nil {
for elem != lst.Back() && elem.Value != value {
elem = elem.Next()
}
if elem.Value == value {
return true, elem
}
}
return false, elem
}
示例10: searchStateOnAction
func searchStateOnAction(queue *list.List, current bucketState, from, to int) {
canDump := current.canDump(from, to)
if canDump {
next := bucketState{buckets: []int{current.buckets[0], current.buckets[1], current.buckets[2]}}
current.dumpWater(from, to, &next)
if !isProcessedState(queue, next) {
queue.PushBack(next)
searchStates(queue)
queue.Remove(queue.Back())
}
}
}
示例11: removeFromList
// removes up to n elements from the list starting backwards and putting their
// values in the removed slice (which should be atleast remove big). Also returns how
// many were removed
func removeFromList(l *list.List, remove int, removed []types.ObjectIndex) int {
var e = l.Back()
var prev *list.Element
var i = 0
for ; remove > i && e != nil; i++ {
prev = e.Prev()
removed[i] = l.Remove(e).(types.ObjectIndex)
e = prev
}
return i
}
示例12: searchStates
func searchStates(queue *list.List) {
current := queue.Back().Value.(bucketState)
if current.isFinal() {
// 已經是最後狀態了
printResult(queue)
} else {
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
searchStateOnAction(queue, current, j, i)
}
}
}
}
示例13: insertUnseenSorted
// maxLength should be >= length of original inputList
func insertUnseenSorted(inputList *list.List, items [](Contact), compare func(Contact, Contact) int, alreadySeen map[ID]bool, maxLength int) {
for i, _ := range items {
c := items[i]
if !alreadySeen[c.NodeID] {
insertSorted(inputList, c, compare)
if inputList.Len() == maxLength {
inputList.Remove(inputList.Back())
}
}
}
}
示例14: rm
func rm(l *list.List, args []string) {
switch len(args) {
case 0:
fmt.Println("What element do you want to remove?")
os.Exit(1)
default:
// check if remaining args are integers
nums := make([]int, len(args))
for i, a := range args {
n, err := strconv.Atoi(a)
if err != nil {
fmt.Printf("%q is not an item number.\n", a)
os.Exit(1)
}
nums[i] = n
}
// Sort nums largest to smallest
sort.Ints(nums)
reverse(nums)
// make sure integers is not out of bounds
if max(nums...) > l.Len() {
fmt.Printf("item [%d] is out of bounds.\n", max(nums...))
os.Exit(1)
} else if min(nums...) < 1 {
fmt.Printf("item [%d] is out of bounds.\n", min(nums...))
os.Exit(1)
}
// Collect elements
index := 0
elements := make([]*list.Element, len(nums))
itemNumber, element := l.Len(), l.Back()
for _, n := range nums {
for n < itemNumber {
element = element.Prev()
itemNumber--
}
elements[index] = element
index++
}
// Remove elements
for i, e := range elements {
fmt.Printf("Removing item[%d]:", nums[i])
printJSON(l.Remove(e))
}
fmt.Println()
}
}
示例15: notifyExpired
//notifyExpired func
func (self *TimeWheel) notifyExpired(idx int) {
var remove *list.List
self.lock.RLock()
slots := self.wheel[idx]
for e := slots.hooks.Back(); nil != e; e = e.Prev() {
sj := e.Value.(*slotJob)
sj.ttl--
//ttl expired
if sj.ttl <= 0 {
if nil == remove {
remove = list.New()
}
//記錄刪除
remove.PushFront(e)
self.slotJobWorkers <- true
//async
go func() {
defer func() {
if err := recover(); nil != err {
//ignored
log.Error("TimeWheel|notifyExpired|Do|ERROR|%s\n", err)
}
<-self.slotJobWorkers
}()
sj.do()
sj.ch <- true
close(sj.ch)
// log.Debug("TimeWheel|notifyExpired|%d\n", sj.ttl)
}()
}
}
self.lock.RUnlock()
if nil != remove {
//remove
for e := remove.Back(); nil != e; e = e.Prev() {
re := e.Value.(*list.Element)
self.lock.Lock()
slots.hooks.Remove(e.Value.(*list.Element))
delete(self.hashWheel, re.Value.(*slotJob).id)
self.lock.Unlock()
}
}
}