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


Golang List.PushFront方法代碼示例

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


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

示例1: main

func main() {

	give := make(chan []byte)
	get := make(chan []byte)

	go func() {
		q := new(list.List)

		for {
			if q.Len() == 0 {
				q.PushFront(make([]byte, 100))
			}

			e := q.Front()

			select {
			case s := <-give:
				q.PushFront(s)

			case get <- e.Value.([]byte):
				q.Remove(e)
			}
		}
	}()

	// Gets a new buffer from the recycler.
	buffer := <-get

	// Give it back to the recycler.
	give <- buffer

	// Get the recycled buffer again.
	buffer = <-get
}
開發者ID:nomad-software,項目名稱:go-channel-compendium,代碼行數:34,代碼來源:main.go

示例2: StackSpec

func StackSpec(c Context) {
	stack := new(list.List)

	c.Specify("An empty stack", func() {

		c.Specify("contains no elements", func() {
			c.Expect(stack.Len()).Equals(0)
		})
	})

	c.Specify("When elements are pushed onto a stack", func() {
		stack.PushFront("pushed first")
		stack.PushFront("pushed last")

		c.Specify("then it contains some elements", func() {
			c.Expect(stack.Len()).NotEquals(0)
		})
		c.Specify("the element pushed last is popped first", func() {
			poppedFirst := stack.Remove(stack.Front())
			c.Expect(poppedFirst).Equals("pushed last")
		})
		c.Specify("the element pushed first is popped last", func() {
			stack.Remove(stack.Front())
			poppedLast := stack.Remove(stack.Front())
			c.Expect(poppedLast).Equals("pushed first")
		})
	})
}
開發者ID:orfjackal,項目名稱:nanospec.go,代碼行數:28,代碼來源:nanospec_example_test.go

示例3: houseKeeping

func houseKeeping(get, give chan interface{},
	factory func() interface{}) {
	q := new(list.List)
	for {
		if q.Len() == 0 {
			atomic.AddInt64(&makes, 1)
			q.PushFront(queued{when: time.Now(), data: factory()})
		}

		element := q.Front()
		timeout := time.NewTimer(time.Minute)
		select {
		case b := <-give:
			timeout.Stop()
			q.PushFront(queued{when: time.Now(), data: b})

		case get <- element.Value.(queued).data:
			timeout.Stop()
			q.Remove(element)

		case <-timeout.C:
			e := q.Front()
			for e != nil {
				n := e.Next()
				if time.Since(e.Value.(queued).when) > time.Minute {
					q.Remove(e)
					e.Value = nil
				}
				e = n
			}
		}
	}
}
開發者ID:postfix,項目名稱:golib-1,代碼行數:33,代碼來源:recycler.go

示例4: CreateObject

func CreateObject(l *list.List, newId, protectorId *protected_objects.ObjectIdMessage,
	encKey *tao.Keys, program *auth.Prin, domain *tao.Domain, newType string,
	newVal []byte) error {

	if !domain.Guard.IsAuthorized(*program, "CREATE", []string{protectorId.String()}) {
		return errors.New("program not authorized to create requested secret")
	}

	_, _, err := readObjRec(l, encKey, newId)
	if err == nil {
		return errors.New("creating object with existing id")
	}

	protectorType, protectorKey, err := readObjRec(l, encKey, protectorId)
	if err != nil {
		return err
	}
	if *protectorType != "key" {
		return errors.New("creating object protected by object type not key")
	}

	new := protected_objects.ObjectMessage{
		ObjId:   newId,
		ObjVal:  newVal,
		ObjType: &newType}
	pNew, err := protected_objects.MakeProtectedObject(new, *protectorId.ObjName,
		*protectorId.ObjEpoch, protectorKey)

	l.PushFront(*pNew)
	return nil
}
開發者ID:tmroeder,項目名稱:cloudproxy,代碼行數:31,代碼來源:secret_service.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: bufferRecycler

func bufferRecycler(give, get chan *bytes.Buffer) {
	q := new(list.List)

	for {
		//This means that we are getting more than we are giving and memory is not being
		//cleaned up properly
		if q.Len() > 1000 {
			log.Warnf("Memory Recycler Overload (high memory use): %d", q.Len())
		}

		if q.Len() == 0 {
			q.PushFront(&bytes.Buffer{})
		}

		e := q.Front()

		select {
		case s := <-give:
			s.Reset()
			q.PushFront(s)

		case get <- e.Value.(*bytes.Buffer):
			q.Remove(e)
		}
	}
}
開發者ID:choirudin2210,項目名稱:platform-layer,代碼行數:26,代碼來源:memorybuffer.go

示例7: recycler

func recycler(give, get chan []byte) {
	q := new(list.List)

	for {
		//This means that we are getting more than we are giving and memory is not being
		//cleaned up properly
		if q.Len() > 1000 {
			log.Warnf("Memory Recycler Overload (high memory use): %d", q.Len())
		}

		if q.Len() == 0 {
			q.PushFront(make([]byte, defaultMemorySize))
		}

		e := q.Front()

		select {
		case s := <-give:
			q.PushFront(s[:0])

		case get <- e.Value.([]byte):
			q.Remove(e)
		}
	}
}
開發者ID:choirudin2210,項目名稱:platform-layer,代碼行數:25,代碼來源:memory.go

示例8: buildArgumentsTrim

func (server *Server) buildArgumentsTrim(arguments *list.List, params imageserver.Params) error {
	trim, _ := params.GetBool("trim")
	if trim {
		// We must execute trim first. (order of operations)
		arguments.PushFront("-trim")
	}
	return nil
}
開發者ID:phamhongviet,項目名稱:imageserver,代碼行數:8,代碼來源:graphicsmagick.go

示例9: HandleResponse

func HandleResponse(r *ReplyInfo, completed *int, jobs *list.List) {
	if r.OK {
		//add to our completed count
		*completed++
	} else {
		//add job back to queue, it failed.
		jobs.PushFront(r.job)
	}
}
開發者ID:salibrandi,項目名稱:mexos,代碼行數:9,代碼來源:master.go

示例10: dfsrp

func dfsrp(g *Digraph, s int, marked map[int]bool, l *list.List) {
	marked[s] = true
	for _, v := range g.Adj(s) {
		if !marked[v.vertex] {
			dfsrp(g, v.vertex, marked, l)
		}
	}
	l.PushFront(s) // Reverse post
}
開發者ID:cnbuff410,項目名稱:algo,代碼行數:9,代碼來源:scc.go

示例11: Bish_mech

func Bish_mech(bpos pos) list.List {
	options := list.List{}
	// positions of the form row+i,col+i, where i is (TODO: fix this)> -min(row,col) and <
	// for now lazy implementation that will have options removed as out of board later
	for i := -7; i < 8; i++ {
		options.PushFront(pos{bpos.row + i, bpos.col + i})
	}
	return options
}
開發者ID:srigsby,項目名稱:go-chess-bot,代碼行數:9,代碼來源:move_mechanics.go

示例12: Pawn_mech

func Pawn_mech(ppos pos) list.List {
	options := list.List{}
	// +1 fwd, TODO: +2 fwd if on homeRow
	// TODO: en passant
	options.PushFront(pos{ppos.row + 1, ppos.col})
	// pawn attack
	options.PushFront(pos{ppos.row + 1, ppos.col + 1})
	options.PushFront(pos{ppos.row + 1, ppos.col - 1})
	return options
}
開發者ID:srigsby,項目名稱:go-chess-bot,代碼行數:10,代碼來源:move_mechanics.go

示例13: AddObject

// Add the indicated protected object to the list.
func AddObject(l *list.List, obj ObjectMessage) error {
	for e := l.Front(); e != nil; e = e.Next() {
		o := e.Value.(ObjectMessage)
		if o.ObjId.ObjName == obj.ObjId.ObjName && o.ObjId.ObjEpoch == obj.ObjId.ObjEpoch {
			return nil
		}
	}
	l.PushFront(interface{}(obj))
	return nil
}
開發者ID:tmroeder,項目名稱:cloudproxy,代碼行數:11,代碼來源:protected_obj.go

示例14: King_mech

func King_mech(kpos pos) list.List {
	options := list.List{}
	// TODO: casteling, requires remembering if King ever has been in check
	for a := -1; a < 2; a++ {
		for b := -1; b < 2; b++ {
			options.PushFront(pos{kpos.row + a, kpos.col + b})
			// TODO: remove no-move move, (a=0,b=0)
		}
	}
	return options
}
開發者ID:srigsby,項目名稱:go-chess-bot,代碼行數:11,代碼來源:move_mechanics.go

示例15: Rook_mech

func Rook_mech(rpos pos) list.List {
	options := list.List{}
	for newCol := 1; newCol < 9; newCol++ {
		options.PushFront(pos{rpos.row, newCol})
	}
	for newRow := 1; newRow < 9; newRow++ {
		options.PushFront(pos{newRow, rpos.col})
	}
	//TODO: this will include current position twice and should have current position removed from options by filtering!
	return options
}
開發者ID:srigsby,項目名稱:go-chess-bot,代碼行數:11,代碼來源:move_mechanics.go


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