当前位置: 首页>>代码示例>>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;未经允许,请勿转载。