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


Golang heap.Remove函數代碼示例

本文整理匯總了Golang中container/heap.Remove函數的典型用法代碼示例。如果您正苦於以下問題:Golang Remove函數的具體用法?Golang Remove怎麽用?Golang Remove使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: Mark

func (x *TopApps) Mark(ApplicationId string, z time.Time) {
	t := z.Unix()

	x.Lock()
	defer x.Unlock()

	y := x.m[ApplicationId]
	if y != nil {
		z1 := heap.Remove(&x.t, y.ti).(*topAppsEntry)
		if z1 != y {
			panic("z1 != y")
		}
		z2 := heap.Remove(&x.n, y.ni).(*topAppsEntry)
		if z2 != y {
			panic("z2 != y")
		}
	} else {
		// New entry
		y = &topAppsEntry{ApplicationId: ApplicationId}
		x.m[ApplicationId] = y
	}

	y.Mark(t)

	heap.Push(&x.t, y)
	heap.Push(&x.n, y)
}
開發者ID:johntdyer,項目名稱:golang-devops-stuff,代碼行數:27,代碼來源:top_apps.go

示例2: TestHeapRemove

func TestHeapRemove(t *testing.T) {
	q := pq.NewQueue()
	q.Push(&message{8})
	q.Push(&message{3})
	q.Push(&message{9})
	q.Push(&message{1})
	q.Push(&message{10})
	q.Push(&message{2})
	q.Push(&message{5})
	q.Push(&message{6})
	q.Push(&message{7})
	q.Push(&message{4})
	heap.Init(q)

	r := heap.Remove(q, 5).(pq.Queueable)
	fmt.Println("removed:", r)

	if r.Priority() != 9 {
		t.Fatalf("Remove() fails, incorrect member removed.", r.Priority())
	}

	mb, _ := q.Member(0)
	if mb.Priority() != 1 {
		t.Fatalf("Remove() fails, unexpected value for min member")
	}
}
開發者ID:gnanderson,項目名稱:pqueue,代碼行數:26,代碼來源:pqueue_test.go

示例3: OnTick

func (tm *TimerMgr) OnTick() {
	nowTime := time.Now()
	for {
		if tm.tq.Len() > 0 {
			t := heap.Pop(tm.tq)
			if te, ok := t.(*TimerEntity); ok {
				if te.next.Before(nowTime) {
					if te.times > 0 {
						te.times--
					}
					//Avoid async stop timer failed
					if te.times != 0 {
						te.next = te.next.Add(te.interval)
						heap.Push(tm.tq, te)
					}
					if !SendTimeout(te) {
						if v, ok := tm.tq.ref[te.h]; ok {
							heap.Remove(tm.tq, v)
						}
					}
				} else {
					heap.Push(tm.tq, te)
					return
				}
			}
		} else {
			return
		}
	}
}
開發者ID:zwczou,項目名稱:goserver,代碼行數:30,代碼來源:timer.go

示例4: update

func (g *Graph) update(n *Node, lowCost int) {
	if n.lowCost > lowCost {
		heap.Remove(g, n.index)
		n.lowCost = lowCost
		heap.Push(g, n)
	}
}
開發者ID:JSoddy,項目名稱:goplay,代碼行數:7,代碼來源:prim.go

示例5: update

func (this *priorityQueue) update(node *HuffmanNode, ch string, weight float64) {
	heap.Remove(this, node.index)
	node.ch = ch
	node.weight = weight
	heap.Push(this, node)

}
開發者ID:pokerG,項目名稱:Go-DataStructure,代碼行數:7,代碼來源:Huffman2.go

示例6: CancelAlarm

func (t *TaskRunner) CancelAlarm(alarm *GoQuicAlarm) {
	item := t.alarmList[alarm]
	if item.heapIdx >= 0 {
		heap.Remove(t.alarmHeap, item.heapIdx)
	}
	t.resetTimer()
}
開發者ID:zzragida,項目名稱:goquic,代碼行數:7,代碼來源:task_runner.go

示例7: StorePosts

func (s *MemStorage) StorePosts(req *http.Request, posts []Activity) {
	s.mu.Lock()
	defer s.mu.Unlock()
	for _, post := range posts {
		if s.filter != nil && !s.filter(post) {
			continue
		}
		log.Printf("store: %s\n", post.Id)
		s.m[post.Id] = post
		updated := false
		datespec := GetDatespec(post.Published)
		for i, p := range s.a[datespec] {
			if p.Id == post.Id {
				s.a[datespec][i] = post
				updated = true
				break
			}
		}
		if !updated {
			s.a[datespec] = append(s.a[datespec], post)
		}
		heap.Push(&s.h, post)
		if s.h.Len() >= 10 {
			_ = heap.Remove(&s.h, s.h.Len()-1)
		}
	}
}
開發者ID:ukai,項目名稱:blogplus,代碼行數:27,代碼來源:storage.go

示例8: advanceRoot

// advanceRoot retrieves the next row for the source at the root of the heap and
// updates the heap accordingly.
func (s *orderedSynchronizer) advanceRoot() error {
	if len(s.heap) == 0 {
		return nil
	}
	src := &s.sources[s.heap[0]]
	if src.row == nil {
		panic("trying to advance closed source")
	}
	oldRow := src.row
	var err error
	src.row, err = src.src.NextRow()
	if err != nil {
		s.err = err
		return err
	}
	if src.row == nil {
		heap.Remove(s, 0)
	} else {
		heap.Fix(s, 0)
		// TODO(radu): this check may be costly, we could disable it in production
		if cmp, err := oldRow.Compare(&s.alloc, s.ordering, src.row); err != nil {
			return err
		} else if cmp > 0 {
			return util.Errorf("incorrectly ordered stream %s after %s", src.row, oldRow)
		}
	}
	// heap operations might set s.err (see Less)
	return s.err
}
開發者ID:the872,項目名稱:cockroach,代碼行數:31,代碼來源:input_sync.go

示例9: TestRemove

func TestRemove(t *testing.T) {
	var count int
	if golangcafeheap.Len() <= 0 {
		// Add時に0件になるので…。
		heap.Push(golangcafeheap, GolangCafe{Name: "ttyokoyama", Priority: 1, Count: 13, Index: 2})
		heap.Push(golangcafeheap, GolangCafe{Name: "taknb2nch", Priority: 2, Count: 13, Index: 3})
		heap.Push(golangcafeheap, GolangCafe{Name: "qt_luigi", Priority: 3, Count: 13, Index: 4})
		heap.Push(golangcafeheap, GolangCafe{Name: "tam_x", Priority: 4, Count: 1, Index: 1})
	} else {
		count = golangcafeheap.Len()
	}

	heap.Remove(golangcafeheap, 2)

	if golangcafeheap.Len() != (count - 1) {
		t.Errorf("golangcafeheap.Len() = %d, %d", golangcafeheap.Len(), count)
	}

	n := golangcafeheap.Len()
	for i := 0; i < n; i++ {
		item := golangcafeheap.Pop()
		golangcafe := item.(*GolangCafe)

		t.Logf("Name: %s Priority: %d Count: %d Index: %d",
			golangcafe.Name, golangcafe.Priority, golangcafe.Count, golangcafe.Index)
	}
}
開發者ID:qt-luigi,項目名稱:golangcafe,代碼行數:27,代碼來源:heapsample_test.go

示例10: update

func (h *ttlKeyHeap) update(n *node) {
	index, ok := h.keyMap[n]
	if ok {
		heap.Remove(h, index)
		heap.Push(h, n)
	}
}
開發者ID:CliffYuan,項目名稱:etcd,代碼行數:7,代碼來源:ttl_key_heap.go

示例11: Dequeue

func (d *Driver) Dequeue(queue string, eid uid.ID) (e *storage.Envelope, err error) {
	now := time.Now().UnixNano()
	d.m.Lock()
	defer d.m.Unlock()
	msgs := d.queues.get(queue)
	for i, n := 0, len(*msgs); i < n; i++ {
		msg := (*msgs)[i]
		if msg.availAt > now {
			break
		}
		if !msg.envelope.Retry.IsValid() {
			event.Emit(event.EventMessageDiscarded, msg.envelope)
			msg.removed = true
		}
		if msg.removed {
			heap.Remove(msgs, i)
			i--
			n--
			continue
		}
		e = msg.envelope
		msg.eid = eid
		msg.availAt = now + int64(msg.envelope.Timeout)
		msg.envelope.Retry.Decr()
		msg.accumlating = false
		heap.Fix(msgs, i)
		d.ephemeralIndex[eid] = msg
		return
	}
	err = storage.ErrEmpty
	return
}
開發者ID:jmptrader,項目名稱:pluq,代碼行數:32,代碼來源:driver.go

示例12: proxyHandler

/*
For snowflake proxies to request a client from the Broker.
*/
func proxyHandler(w http.ResponseWriter, r *http.Request) {
	if isPreflight(w, r) {
		return
	}
	id := r.Header.Get("X-Session-ID")
	body, err := ioutil.ReadAll(r.Body)
	if nil != err {
		log.Println("Invalid data.")
		w.WriteHeader(http.StatusBadRequest)
		return
	}
	if string(body) != id { // Mismatched IDs!
		w.WriteHeader(http.StatusBadRequest)
	}
	// Maybe confirm that X-Session-ID is the same.
	log.Println("Received snowflake: ", id)
	snowflake := AddSnowflake(id)

	// Wait for a client to avail an offer to the snowflake, or timeout
	// and ask the snowflake to poll later.
	select {
	case offer := <-snowflake.offerChannel:
		log.Println("Passing client offer to snowflake.")
		w.Write(offer)

	case <-time.After(time.Second * ProxyTimeout):
		// This snowflake is no longer available to serve clients.
		heap.Remove(snowflakes, snowflake.index)
		delete(snowflakeMap, snowflake.id)
		w.WriteHeader(http.StatusGatewayTimeout)
	}
}
開發者ID:wwwiretap,項目名稱:snowflake,代碼行數:35,代碼來源:broker.go

示例13: Remove

// Remove a job from the queue.
func (jq *JobQueue) Remove(job *Job) {
	Debug("rm", job)
	delete(jq.byname, job.file)
	delete(jq.byidx, job.id)
	heap.Remove(&(jq.pq), job.index)
	job.index = -1
}
開發者ID:barnex,項目名稱:mjolnir,代碼行數:8,代碼來源:jobqueue.go

示例14: update

func (this *priorityQueue) update(node *space, end int, cost int) {
	heap.Remove(this, node.index)
	node.end = end
	node.cost = cost
	heap.Push(this, node)

}
開發者ID:pokerG,項目名稱:Go-DataStructure,代碼行數:7,代碼來源:priorityQueue.go

示例15: update

func (g *Graph) update(n *Node, distance int) {
	if n.distance > distance {
		heap.Remove(g, n.index)
		n.distance = distance
		heap.Push(g, n)
	}
}
開發者ID:JSoddy,項目名稱:goplay,代碼行數:7,代碼來源:dijkstra.go


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