Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: container/heap: add Peek function #17510

Closed
leonxu0 opened this issue Oct 19, 2016 · 4 comments
Closed

Proposal: container/heap: add Peek function #17510

leonxu0 opened this issue Oct 19, 2016 · 4 comments

Comments

@leonxu0
Copy link

leonxu0 commented Oct 19, 2016

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.

@leonxu0 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 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
@odeke-em
Copy link
Member

I've updated the title to make this a request for a Peek function https://en.wikipedia.org/wiki/Peek_(data_type_operation)

@minux
Copy link
Member

minux commented Oct 19, 2016 via email

@odeke-em
Copy link
Member

Yeah, @minux's words were also echoed on this golang-nuts mailing list post https://groups.google.com/forum/#!topic/golang-nuts/sy1p8SfyPoY.

@leonxu0
Copy link
Author

leonxu0 commented Oct 19, 2016

@odeke-em @minux thanks! problem solved!

@leonxu0 leonxu0 closed this as completed Oct 19, 2016
@golang golang locked and limited conversation to collaborators Oct 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants