本文整理汇总了Golang中container/heap.Remove函数的典型用法代码示例。如果您正苦于以下问题:Golang Remove函数的具体用法?Golang Remove怎么用?Golang Remove使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Remove函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: NextWorker
//
// 获取下一个可用的Worker
//
func (pq *PriorityQueue) NextWorker() *Worker {
now := time.Now()
for pq.Len() > 0 {
result := (*pq)[0]
if result.index != INVALID_INDEX && result.Expire.After(now) {
// 只要活着,就留在优先级队列中,等待分配任务
// log.Println("Find Valid Worker...")
result.priority -= 1
// 调整Worker的优先级
heap.Fix(pq, result.index)
return result
} else {
if result.index != INVALID_INDEX {
log.Errorf("Invalid Item index in PriorityQueue#NextWorker")
} else {
log.Println("Worker Expired")
// 只有过期的元素才删除
heap.Remove(pq, result.index)
}
}
}
log.Println("Has Not Worker...")
return nil
}
开发者ID:vinsia,项目名称:rpc_proxy,代码行数:33,代码来源:priority_queue.go
示例17: rmEndpoint
func (s *sandboxData) rmEndpoint(ep *endpoint) int {
ep.Lock()
joinInfo := ep.joinInfo
ep.Unlock()
sb := s.sandbox()
for _, i := range sb.Info().Interfaces() {
// Only remove the interfaces owned by this endpoint from the sandbox.
if ep.hasInterface(i.SrcName()) {
if err := i.Remove(); err != nil {
logrus.Debugf("Remove interface failed: %v", err)
}
}
}
// Remove non-interface routes.
for _, r := range joinInfo.StaticRoutes {
if err := sb.RemoveStaticRoute(r); err != nil {
logrus.Debugf("Remove route failed: %v", err)
}
}
// We don't check if s.endpoints is empty here because
// it should never be empty during a rmEndpoint call and
// if it is we will rightfully panic here
s.Lock()
highEpBefore := s.endpoints[0]
var (
i int
e *endpoint
)
for i, e = range s.endpoints {
if e == ep {
break
}
}
heap.Remove(&s.endpoints, i)
var highEpAfter *endpoint
if len(s.endpoints) > 0 {
highEpAfter = s.endpoints[0]
}
s.Unlock()
if highEpBefore != highEpAfter {
s.updateGateway(highEpAfter)
}
s.Lock()
s.refCnt--
refCnt := s.refCnt
s.Unlock()
if refCnt == 0 {
s.sandbox().Destroy()
}
return refCnt
}
开发者ID:MathewAniyan,项目名称:docker,代码行数:59,代码来源:sandboxdata.go
示例18: clearNetworkResources
func (sb *sandbox) clearNetworkResources(ep *endpoint) error {
sb.Lock()
osSbox := sb.osSbox
sb.Unlock()
if osSbox != nil {
for _, i := range osSbox.Info().Interfaces() {
// Only remove the interfaces owned by this endpoint from the sandbox.
if ep.hasInterface(i.SrcName()) {
if err := i.Remove(); err != nil {
log.Debugf("Remove interface failed: %v", err)
}
}
}
ep.Lock()
joinInfo := ep.joinInfo
ep.Unlock()
// Remove non-interface routes.
for _, r := range joinInfo.StaticRoutes {
if err := osSbox.RemoveStaticRoute(r); err != nil {
log.Debugf("Remove route failed: %v", err)
}
}
}
sb.Lock()
if len(sb.endpoints) == 0 {
// sb.endpoints should never be empty and this is unexpected error condition
// We log an error message to note this down for debugging purposes.
log.Errorf("No endpoints in sandbox while trying to remove endpoint %s", ep.Name())
sb.Unlock()
return nil
}
highEpBefore := sb.endpoints[0]
var (
i int
e *endpoint
)
for i, e = range sb.endpoints {
if e == ep {
break
}
}
heap.Remove(&sb.endpoints, i)
var highEpAfter *endpoint
if len(sb.endpoints) > 0 {
highEpAfter = sb.endpoints[0]
}
delete(sb.epPriority, ep.ID())
sb.Unlock()
if highEpBefore != highEpAfter {
sb.updateGateway(highEpAfter)
}
return nil
}
开发者ID:wangxujun163163,项目名称:libnetwork,代码行数:59,代码来源:sandbox.go
示例19: remove
func (jq *JobQueue) remove(jobID snowflake.Snowflake, err error) error {
for i, entry := range jq.working {
if entry.ID == jobID {
heap.Remove(&jq.working, i)
return nil
}
}
for i, entry := range jq.available {
if entry.ID == jobID {
heap.Remove(&jq.available, i)
return nil
}
}
return jobs.ErrJobNotFound
}
开发者ID:logan,项目名称:heim,代码行数:17,代码来源:jobs.go
示例20: removeMessage
//removeMessage removes the message from mh.
//If mh is empty, message is nil, or message is not in mh, then this is a nop
//and returns false.
//Returns true or false indicating whether or not message was actually removed
//from mh.
func (mh *messageHeap) removeMessage(message *Message) bool {
if mh.Len() == 0 || message == nil || message.index == notInIndex || message.mh != mh {
return false
}
result := heap.Remove(mh, message.index).(*Message)
beforeRemoval(result)
return true
}
开发者ID:gogolfing,项目名称:timequeue,代码行数:13,代码来源:message.go
注:本文中的container/heap.Remove函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论