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