Skip to content

Range interface for std.container.BinaryHeap #1989

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

Merged
merged 1 commit into from
Mar 15, 2014

Conversation

Poita
Copy link
Contributor

@Poita Poita commented Mar 9, 2014

See discussion here: #1886

Fixes Issue 12358

https://d.puremagic.com/issues/show_bug.cgi?id=12358

@andralex
Copy link
Member

Could you please add to the documentation that the heap is a standard input range, and add an example too? Thanks!

@Poita
Copy link
Contributor Author

Poita commented Mar 10, 2014

Done. Also took the liberty of moving the other example's introductory comment out to the unittest documentation.

@ghost
Copy link

ghost commented Mar 13, 2014

Could you amend the commit to include the comment Fixes Issue 12358, please? Thanks.

@Poita
Copy link
Contributor Author

Poita commented Mar 13, 2014

Do I actually need to change a commit, or is modifying the original comment in this thread enough?

@DmitryOlshansky
Copy link
Member

@Poita all must be in commit message.

{
int[] a = [4, 1, 3, 2, 16, 9, 10, 14, 8, 7];
auto top5 = heapify(a).take(5);
assert(top5.equal([16, 14, 10, 9, 8]));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also show/mention that the underlying ranges gets sorted too, by testing: assert(a[0 .. 5].isSorted(). It's not mere "iteration".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please - then let's pull this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would mention that if it were true :-) Your assertion fails.

The underlying range is only sorted after complete iteration. This fact is already mentioned in the documentation of BinaryHeap so I see no value in stating it again.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would mention that if it were true :-) Your assertion fails.

Right, but because of the backwards sorting. assert(a[0 .. 5].isSorted!"a > b"() should pass.

The underlying range is only sorted after complete iteration.

The parts iterated over so far should be sorted.

So I see no value in stating it again.

I think you can never document things too much, but fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't sort it in reverse either. It sorts it in reverse from the back (a[$-5..$].isSorted).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't sort it in reverse either.

Ah... See? An example would have helped me with that ;)

Well, actually, that's an unfair comment. I didn't actually the leading documentation.

@Poita
Copy link
Contributor Author

Poita commented Mar 15, 2014

I've rebased and added the "Fixes Issue 12358" message to the commit.

@monarchdodra
Copy link
Collaborator

Auto-merge toggled on

@braddr
Copy link
Member

braddr commented Mar 15, 2014

Pull updated, auto_merge toggled off

@monarchdodra
Copy link
Collaborator

Auto-merge toggled on

Fixes Issue 12358

See discussion here: dlang#1886
monarchdodra added a commit that referenced this pull request Mar 15, 2014
Range interface for std.container.BinaryHeap
@monarchdodra monarchdodra merged commit 8185eab into dlang:master Mar 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants