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

container/heap: add simple example #4331

Closed
rsc opened this issue Nov 1, 2012 · 6 comments
Closed

container/heap: add simple example #4331

rsc opened this issue Nov 1, 2012 · 6 comments
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Nov 1, 2012

The priority queue example is fine but very complex. I have heard of people copying and
pasting it (because it is unclear how to use the package otherwise) and having all the
code to maintain those index fields even if they were never used.

Two things to do:

1) Write a simple example. Make it first.
2) Make the complex example actually use the functionality the index field is allowing.
@kisielk
Copy link
Contributor

kisielk commented Nov 3, 2012

Comment 1:

For the simple example, how about a simple int heap like so:
http://play.golang.org/p/YxDSwLWqhs ?

@rsc
Copy link
Contributor Author

rsc commented Dec 10, 2012

Comment 2:

Labels changed: added size-m.

@rsc
Copy link
Contributor Author

rsc commented Dec 10, 2012

Comment 3:

Labels changed: added suggested.

@gopherbot
Copy link

Comment 4 by vegacom:

The Push could be simplified by using append, as in the following code snippet:
func (pq *PriorityQueue) Push(x interface{}) {
  item := x.(*Item)
  item.index = len(*pq)
  *pq = append(*pq, item)
}

@cespare
Copy link
Contributor

cespare commented Jan 7, 2013

Comment 5:

First pass attempt:
https://golang.org/cl/7068048/
I based the simple example on the int heap from Comment 1.

@rsc
Copy link
Contributor Author

rsc commented Jan 31, 2013

Comment 6:

This issue was closed by revision 0e74f04.

Status changed to Fixed.

@rsc rsc added fixed Suggested Issues that may be good for new contributors looking for work to do. labels Jan 31, 2013
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

4 participants