當前位置: 首頁>>代碼示例>>Golang>>正文


Golang List.PushFrontList方法代碼示例

本文整理匯總了Golang中container/list.List.PushFrontList方法的典型用法代碼示例。如果您正苦於以下問題:Golang List.PushFrontList方法的具體用法?Golang List.PushFrontList怎麽用?Golang List.PushFrontList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在container/list.List的用法示例。


在下文中一共展示了List.PushFrontList方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: outOfOrder

func outOfOrder(l *list.List) {
	iTotal := 25
	if iTotal > l.Len() {
		iTotal = l.Len()
	}
	ll := make([]*list.List, iTotal)

	for i := 0; i < iTotal; i++ {
		ll[i] = list.New()
	}
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for e := l.Front(); e != nil; e = e.Next() {
		fpath, ok := e.Value.(string)
		if !ok {
			panic("The path is invalid string")
		}
		if rand.Int()%2 == 0 {
			ll[r.Intn(iTotal)].PushFront(fpath)
		} else {
			ll[r.Intn(iTotal)].PushBack(fpath)
		}
	}

	r0 := rand.New(rand.NewSource(time.Now().UnixNano()))
	l.Init()
	for i := 0; i < iTotal; i++ {
		if r0.Intn(2) == 0 {
			l.PushBackList(ll[i])
		} else {
			l.PushFrontList(ll[i])
		}
		ll[i].Init()
	}
}
開發者ID:hwch,項目名稱:go-dev,代碼行數:34,代碼來源:mp3decode.go

示例2: tileWorker

func tileWorker(T *quadratic.Map, alternativeStack chan *list.List, sink chan<- *quadratic.Map, workerCount chan int, halt chan int, tileMaps []*quadratic.Map, chooseNextEdge func(*quadratic.Map) *quadratic.Edge, maxtiles int, tileSymmetry string, showIntermediate bool) {
	localAlternatives := new(list.List)
Work:
	for {
		select {
		case <-halt:
			halt <- 1
			fmt.Fprintf(os.Stderr, "premature halt\n")
			return
		case L := <-alternativeStack:
			L.PushFrontList(localAlternatives)
			localAlternatives.Init()
			alternativeStack <- L
		default:
			if T.Faces.Len() > maxtiles && maxtiles > 0 {
				sink <- T
				break Work
			} else if noActiveFaces(T) {
				finishTime, _, _ := os.Time()
				fmt.Fprintf(os.Stderr, "new tiling complete, took %v seconds\n", finishTime-initializationTime)
				sink <- T
				break Work
			} else if showIntermediate {
				sink <- T
			}
			alternatives := addTilesByEdge(T, tileMaps, chooseNextEdge, tileSymmetry)
			if alternatives.Len() == 0 {
				break Work
			}
			T = alternatives.Remove(alternatives.Front()).(*quadratic.Map)
			localAlternatives.PushFrontList(alternatives)
			//fmt.Fprintf(os.Stderr,"currently have %v faces\n",T.Faces.Len())
		}
	}
	L := <-alternativeStack
	L.PushFrontList(localAlternatives)
	localAlternatives.Init()
	alternativeStack <- L

	workers := <-workerCount
	workerCount <- workers - 1
}
開發者ID:ebering,項目名稱:zellij,代碼行數:42,代碼來源:zellij.go

示例3: SortList

//to sort a list, based on the distance from the given key in ascending order
func SortList(l *list.List, keyId ID) {
	//a new list to keep the sorted elements
	sorted := list.New()
	//iterate over the given list
	for e := l.Front(); e != nil; e = e.Next() {
		var changed bool = false
		//compute distance
		var c *Contact
		c = e.Value.(*Contact)
		dist := c.NodeID.Xor(keyId)
		//loop over the sorted array to find position for the current element
		if sorted.Len() == 0 {
			sorted.PushFront(c)
			continue
		}
		for s := sorted.Front(); s != nil; s = s.Next() {
			c1 := s.Value.(*Contact)
			dist1 := c1.NodeID.Xor(keyId)
			larger := dist1.Less(dist)
			// if larger is true then insert the element in the current position
			// end the loop
			if larger {
				changed = true
				sorted.InsertBefore(c, s)
				break
			}
		}
		//if not changed, insert the element at the back
		if !changed {
			sorted.PushBack(c)
		}
	}
	//push the sorted list into the parameter of the function
	l = list.New()
	l.PushFrontList(sorted)
	return
}
開發者ID:dipendra009,項目名稱:Kademlia-Tester,代碼行數:38,代碼來源:kademlia.go


注:本文中的container/list.List.PushFrontList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。