Skip to content

Proposal: container/heap: add Peek function #17510

@leonxu0

Description

@leonxu0

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions