You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
1.7.1
What operating system and processor architecture are you using (go env)?
linux
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
piece of code :
todo := &PushTaskList{}
todo.init("todo")
heap.Init(todo)
heap.Push(todo, &PushTask{v:"1",stime:9,ktime:5,priority:9})
heap.Push(todo, &PushTask{v:"2",stime:3,ktime:1,priority:10})
heap.Push(todo, &PushTask{v:"3",stime:5,ktime:7,priority:12})
heap.Push(todo, &PushTask{v:"4",stime:11,ktime:3,priority:11})
for todo.Len() > 0 {
pt := heap.Front(todo)
pt.print()
if pt.priority > 11 {
heap.Pop(todo)
}
}
What did you expect to see?
i need a function for container/heap to return the first element but not pop it.
What did you see instead?
no such function, i can't check the first element without using the heap.Pop() function, which in some case i should not call.
The text was updated successfully, but these errors were encountered:
leonxu0
changed the title
Need a function for container/heap to return the first element but not pop it.
Proposal: add function for container/heap to return the first element without poping it.
Oct 19, 2016
odeke-em
changed the title
Proposal: add function for container/heap to return the first element without poping it.
Proposal: container/heap: add Peek function
Oct 19, 2016
Unless you're developing code that takes a heap.Interface,
usually you have access to the slice representation, and
the minimum item is at index 0. Therefore, I don't think
Peek is very important.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.7.1
What operating system and processor architecture are you using (
go env
)?linux
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
piece of code :
todo := &PushTaskList{}
todo.init("todo")
heap.Init(todo)
heap.Push(todo, &PushTask{v:"1",stime:9,ktime:5,priority:9})
heap.Push(todo, &PushTask{v:"2",stime:3,ktime:1,priority:10})
heap.Push(todo, &PushTask{v:"3",stime:5,ktime:7,priority:12})
heap.Push(todo, &PushTask{v:"4",stime:11,ktime:3,priority:11})
for todo.Len() > 0 {
pt := heap.Front(todo)
pt.print()
if pt.priority > 11 {
heap.Pop(todo)
}
}
What did you expect to see?
i need a function for container/heap to return the first element but not pop it.
What did you see instead?
no such function, i can't check the first element without using the heap.Pop() function, which in some case i should not call.
The text was updated successfully, but these errors were encountered: