当前位置: 首页>>代码示例>>Golang>>正文


Golang List.Back方法代码示例

本文整理汇总了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))
	}
}
开发者ID:vStone,项目名称:subsync,代码行数:33,代码来源:subsync.go

示例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)
}
开发者ID:alienscience,项目名称:bread,代码行数:31,代码来源:sorted.go

示例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
			}
		}
	}
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:28,代码来源:kademlia.go

示例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
}
开发者ID:jeffallen,项目名称:go-warp,代码行数:26,代码来源:DT.go

示例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()
}
开发者ID:jeffallen,项目名称:go-warp,代码行数:25,代码来源:DT.go

示例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 + "]")
}
开发者ID:hogesuke,项目名称:NicoNewVideoChecker,代码行数:33,代码来源:NewVideoCollector.go

示例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
}
开发者ID:yujinqiu,项目名称:gotrace,代码行数:11,代码来源:convert.go

示例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)
	}
}
开发者ID:payfriendz,项目名称:go-freeling,代码行数:11,代码来源:splitter.go

示例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
}
开发者ID:mkindahl,项目名称:gograph,代码行数:16,代码来源:storage.go

示例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())
		}
	}
}
开发者ID:yybear,项目名称:-Algorithmfun,代码行数:12,代码来源:water.go

示例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
}
开发者ID:na--,项目名称:nedomi,代码行数:15,代码来源:lru.go

示例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)
			}
		}
	}
}
开发者ID:yybear,项目名称:-Algorithmfun,代码行数:13,代码来源:water.go

示例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())
			}
		}
	}
}
开发者ID:jontonsoup,项目名称:tin-foil-hat,代码行数:14,代码来源:helpers.go

示例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()
	}
}
开发者ID:tgrijalva,项目名称:lst,代码行数:51,代码来源:lst.go

示例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()
		}
	}

}
开发者ID:materone,项目名称:turbo,代码行数:52,代码来源:time_wheel.go


注:本文中的container/list.List.Back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。