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


Golang List.Remove方法代码示例

本文整理汇总了Golang中container/list.List.Remove方法的典型用法代码示例。如果您正苦于以下问题:Golang List.Remove方法的具体用法?Golang List.Remove怎么用?Golang List.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在container/list.List的用法示例。


在下文中一共展示了List.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: multiplexSounds

// Go through the current buffer for all sounds in the play queue, and sum
// up their values. Multiple sounds playing at the same time mathematically
// (and in the real world) works like this, but in software, we have a minimum/maximum
// value of -1.0/1.0. Thus, if the sum is outside those bounds, "clipping" will occur.
// Let's live with it for v1.
func multiplexSounds(output buffer, queue *list.List) {
	var finished []*list.Element

	multiplexed := make(buffer, bufferSize)
	for e := queue.Front(); e != nil; e = e.Next() {
		// Cast list element to queueItem.
		item := e.Value.(*queueItem)

		// Sum the magnitudes with the multiplier.
		for i, val := range item.contents[item.played] {
			multiplexed[i] += val
		}

		// If we have played all buffers, remove ourselves from the queue.
		item.played++
		if item.played >= len(item.contents) {
			finished = append(finished, e)
		}
	}
	for _, e := range finished {
		queue.Remove(e)
	}

	copy(output, multiplexed)
}
开发者ID:billyboar,项目名称:GCSolutions,代码行数:30,代码来源:player.go

示例4: processEvents

// Process game events. Implements screen interface.
func (c *config) processEvents(eventq *list.List) (transition int) {
	for e := eventq.Front(); e != nil; e = e.Next() {
		eventq.Remove(e)
		event := e.Value.(*event)
		switch event.id {
		case toggleOptions:
			c.activate(screenDeactive)
			if c.keysRebound {
				saver := newSaver()
				saver.persistBindings(c.keys)
				publish(eventq, keysRebound, c.keys)
			}
			return c.exitTransition
		case rebindKey:
			if rke, ok := event.data.(rebindKeyEvent); ok {
				c.rebindKey(rke.index, rke.key)
			} else {
				logf("options.processEvents: did not receive rebindKeyEvent")
			}
		case quitLevel:
			c.mp.returnToMenu()
			return chooseGame
		case rollCredits:
			c.rollCredits()
		case toggleMute:
			c.toggleMute()
		}

	}
	return configGame
}
开发者ID:kissthink,项目名称:bampf,代码行数:32,代码来源:config.go

示例5: 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

示例6: searchRiverStates

func searchRiverStates(queue *list.List) {
	current := queue.Back().Value.(itemState)

	if current.isFinal() {
		// 已经是最后状态了
		printRiver(queue)
	} else {
		if current.currentAction.direct == 0 {
			for i := 0; i < 5; i++ {
				next := current.move(backAction[i])
				//next.printState()
				if next.validate() && !isProcessedRiverState(queue, next) {
					queue.PushBack(next)
					searchRiverStates(queue)
					queue.Remove(queue.Back())
				}
			}
		} else {
			for i := 0; i < 5; i++ {
				next := current.move(goAction[i])
				//next.printState()
				if next.validate() && !isProcessedRiverState(queue, next) {
					queue.PushBack(next)
					searchRiverStates(queue)
					queue.Remove(queue.Back())
				}
			}
		}
	}
}
开发者ID:yybear,项目名称:-Algorithmfun,代码行数:30,代码来源:demonsAndMonks.go

示例7: Fetcher

func Fetcher(queue *list.List, limit int) chan *WikiArticle {
	articles := make(chan *WikiArticle)
	go func() {
		for i := 0; i < limit; i++ {
			for queue.Front() == nil {
				runtime.Gosched()
			}
			// url := q.PopFront()
			article := queue.Front().Value.(*WikiArticle)
			queue.Remove(queue.Front())

			r, url, e := http.Get(article.url)
			if e != nil {
				println("Failed:", article.url)
				continue
			}
			println("Fetched:", article.depth, url)

			buf := bytes.NewBufferString("")
			io.Copy(buf, r.Body)
			article.content = buf.String()
			r.Body.Close()
			articles <- article
		}
		close(articles)
	}()
	return articles
}
开发者ID:surma-dump,项目名称:wikicrawl,代码行数:28,代码来源:wikicrawl.go

示例8: listen

func listen(mr *MapReduce, stage JobType, completed *int, jobs *list.List) {

	NumOther := 0
	switch stage {
	case Map:
		NumOther = mr.nReduce
	case Reduce:
		NumOther = mr.nMap
	}

	if jobs.Len() != 0 {
		select {
		//wait for worker responses
		case r := <-mr.responses:
			HandleResponse(r, completed, jobs)

		//wait for available if none are available
		case id := <-mr.available:
			w := mr.Workers[id]
			//pop off a job id
			j := jobs.Remove(jobs.Front()).(int)
			args := &DoJobArgs{mr.file, stage, j, NumOther}
			go SendRPC(mr, w, args, j)
		}
	} else {
		r := <-mr.responses
		HandleResponse(r, completed, jobs)
	}
}
开发者ID:salibrandi,项目名称:mexos,代码行数:29,代码来源:master.go

示例9: handleDonePeerMsg

// handleDonePeerMsg deals with peers that have signalled they are done.  It
// removes the peer as a candidate for syncing and in the case where it was
// the current sync peer, attempts to select a new best peer to sync from.  It
// is invoked from the syncHandler goroutine.
func (b *blockManager) handleDonePeerMsg(peers *list.List, p *peer) {
	// Remove the peer from the list of candidate peers.
	for e := peers.Front(); e != nil; e = e.Next() {
		if e.Value == p {
			peers.Remove(e)
			break
		}
	}

	log.Infof("BMGR: Lost peer %s", p)

	// Remove requested transactions from the global map so that they will
	// be fetched from elsewhere next time we get an inv.
	for k := range p.requestedTxns {
		delete(b.requestedTxns, k)
	}

	// Remove requested blocks from the global map so that they will be
	// fetched from elsewhere next time we get an inv.
	// TODO(oga) we could possibly here check which peers have these blocks
	// and request them now to speed things up a little.
	for k := range p.requestedBlocks {
		delete(b.requestedBlocks, k)
	}

	// Attempt to find a new peer to sync from if the quitting peer is the
	// sync peer.
	if b.syncPeer != nil && b.syncPeer == p {
		b.syncPeer = nil
		b.startSync(peers)
	}
}
开发者ID:Belxjander,项目名称:btcd,代码行数:36,代码来源:blockmanager.go

示例10: listRemove

// removes PCB element from a linked list
func listRemove(p *PCB, ls *list.List) {
	for e := ls.Front(); e != nil; e = e.Next() {
		if e.Value.(*PCB).PID == p.PID {
			ls.Remove(e)
		}
	}
}
开发者ID:tatathk,项目名称:CS2106-process-manager,代码行数:8,代码来源:manager.go

示例11: rcbListRemove

// removes RCB element from a linked list
func rcbListRemove(r *RCB, ls *list.List) {
	for e := ls.Front(); e != nil; e = e.Next() {
		if e.Value.(*RCB).RID == r.RID {
			ls.Remove(e)
		}
	}
}
开发者ID:tatathk,项目名称:CS2106-process-manager,代码行数:8,代码来源:manager.go

示例12: EvalWords

func (interp *Interp) EvalWords(words *list.List) string {
	var retval string

	frame := interp.stack.PeekFrame()
	words = frame.SubstituteWords(interp, words)

	new_frame := interp.stack.PushFrame()

	name := words.Remove(words.Front()).(Word).String()
	cmd, error := interp.FindCommand(name, words)

	if error != nil {
		fmt.Println(error)
		os.Exit(1)
	}

	new_frame.BindArguments(cmd, words)

	if cmd.native_body == nil {
		retval = new_frame.Eval(interp, cmd.body)
	} else {
		retval = cmd.native_body(interp, new_frame)
	}

	interp.stack.PopFrame()

	return retval
}
开发者ID:nwidger,项目名称:gotcl,代码行数:28,代码来源:interp.go

示例13: pushMetric

// pushMetric adds the metric to the end of the list and returns a comma separated string of the
// previous 61 entries.  We return 61 instead of 60 (an hour) because the chart on the client
// tracks deltas between these values - there is nothing to compare the first value against.
func pushMetric(history *list.List, ev expvar.Var) string {
	history.PushBack(ev.String())
	if history.Len() > 61 {
		history.Remove(history.Front())
	}
	return JoinStringList(history)
}
开发者ID:barbourkd,项目名称:inbucket,代码行数:10,代码来源:listener.go

示例14: revokeLeases

func (ss *storageServer) revokeLeases(leaseHolders *list.List, key string) {
	for e := leaseHolders.Front(); e != nil; e = e.Next() {
		leaseWrap := e.Value.(LeaseWrapper)
		// If lease has already expired, don't do anything
		if time.Since(leaseWrap.timeGranted).Seconds() >
			storagerpc.LeaseSeconds+storagerpc.LeaseGuardSeconds {
			leaseHolders.Remove(e)
			continue
		}
		successChan := make(chan error)
		go ss.waitForRevokeLease(leaseWrap.hostport, key, successChan)
	Loop:
		for {
			select {
			case err := <-successChan:
				if err != nil {
					fmt.Println(err)
				} else {
					break Loop
				}
			default:
				if time.Since(leaseWrap.timeGranted).Seconds() >
					storagerpc.LeaseSeconds+storagerpc.LeaseGuardSeconds {
					fmt.Println("timed out")
					break Loop
				}
				//time.Sleep(time.Second)
			}
		}
		leaseHolders.Remove(e)
	}

}
开发者ID:aditij1,项目名称:p2aditijakkamat,代码行数:33,代码来源:storageserver_impl.go

示例15: 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


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