本文整理汇总了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()
}
}
示例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
}
示例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
}