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

Fix issue 10777 - multiSort should return a SortedRange #4235

Merged
merged 1 commit into from
May 5, 2016

Conversation

wilzbach
Copy link
Member

@wilzbach wilzbach commented Apr 25, 2016

As I now bumped for the second time into the problem of having a chainable multiSort (=SortedRange), I quickly wrote my own solution. Afterwards I realized that #4061 is already open, there are a couple of minor differences, here

  1. a inline, static function instead of MultiPred struct is used.
  2. no shrink method is provided (but can be in the future)

So in summary less (possibly controversial) changes.

As always, I am very happy about feedback.

@SzMK - let's join efforts to get this into Phobos?

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
10777 std.algorithm.multiSort to return a std.range.SortedRange

@wilzbach wilzbach force-pushed the multisort_with_pred branch from 94a1ac1 to 5c85223 Compare April 25, 2016 20:06
{
while (r.length > 1)
void multiSortImpl(funs...)(Range r) @safe
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a static fun?

@wilzbach wilzbach force-pushed the multisort_with_pred branch from 5c85223 to d87abdb Compare April 26, 2016 14:22
@wilzbach
Copy link
Member Author

thanks for your input @9il - addressed ;-)

@@ -844,7 +844,7 @@ private template validPredicates(E, less...)
}

/**
$(D void multiSort(Range)(Range r)
$(D auto multiSort(Range)(Range r)
Copy link
Member Author

Choose a reason for hiding this comment

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

is there a way how we could write SortedRange here?
The less fun is defined inline.

Copy link
Member

Choose a reason for hiding this comment

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

no

@wilzbach wilzbach force-pushed the multisort_with_pred branch 4 times, most recently from fae4c69 to adf529e Compare April 29, 2016 08:22
@wilzbach
Copy link
Member Author

Another example of the new Travis linting at work :)

There was also a small issue with autotester, that should be fixed now.

"What would be other use cases for MultiPred" (from #4061)

Please not that the difference to the stalled #4061 is that we just use a static, pred function which is passed to assumeSorted, so this is hidden from the user and if wanted we can still extend add a MultiPred struct in the future if wanted (?).

That being said 1) I would like to see MultiPred too and 2) this should be ready to go. The change for the user is that instead of void a SortedRange will be returned. If so, it will be added to the changelog once #4228 is there.

Ping @MartinNowak.

@MartinNowak
Copy link
Member

Same comment as on #4061 applies, converting a multi-sort predicate to a sort predicate should be seen as an intermediate step towards a SortedRange w/ multi-sort support, b/c it doesn't make use of the performance benefits (e.g. lowerBound makes M * log(N) comparisions for M predicates).

@@ -856,12 +856,16 @@ and sorts elements that have the same $(D id) by $(D date)
descending. Such a call is equivalent to $(D sort!"a.id != b.id ? a.id
< b.id : a.date > b.date"(r)), but $(D multiSort) is faster because it
does fewer comparisons (in addition to being more convenient).

Returns: The initial range wrapped as a $(D SortedRange) with its predicates.
Copy link
Member

Choose a reason for hiding this comment

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

How about with its predicates converted to an equivalent single predicate.?

@MartinNowak
Copy link
Member

MartinNowak commented Apr 29, 2016

Changelog entry missing.

@wilzbach wilzbach force-pushed the multisort_with_pred branch 2 times, most recently from 8b11098 to 678385e Compare April 29, 2016 13:08
@wilzbach
Copy link
Member Author

Changelog entry missing.

Added (could you please have a look at #4228)?

b/c it doesn't make use of the performance benefits (e.g. lowerBound makes M * log(N) comparisions for M predicates).

Have you looked at the implementation of predFun? It will break as soon as either lessFun(a,b) or lessFun(b, a) is true. Is there really a better way to do this?

All other comments were addressed - and I added a small fix (multiSort didn't work for a single predicate ...)

@wilzbach wilzbach force-pushed the multisort_with_pred branch from 678385e to 6b165d4 Compare April 30, 2016 09:38
@wilzbach
Copy link
Member Author

wilzbach commented Apr 30, 2016

@MartinNowak I am too lazy to rebase all the time, so I removed the changelog entry again. Here is the message:

   $(LI $(XREF algorithm, sorting, multiSort) returns now a
       $(XREF range, SortedRange) instead of `void`)

edit: btw I thought that if it's linked to an issue, you can generate the log entry automatically?

@MartinNowak
Copy link
Member

edit: btw I thought that if it's linked to an issue, you can generate the log entry automatically?

Yes, you'll get a Bugzilla fixed entry for references in a commit message. You can recognize that by the check mark in the dlang-bot comment.
#4235 (comment)

@MartinNowak
Copy link
Member

Have you looked at the implementation of predFun? It will break as soon as either lessFun(a,b) or lessFun(b, a) is true. Is there really a better way to do this?

Ah great, that's as good as it can get.

@MartinNowak
Copy link
Member

Auto-merge toggled on

@MartinNowak MartinNowak merged commit 72fdea9 into dlang:master May 5, 2016
@wilzbach wilzbach deleted the multisort_with_pred branch May 6, 2016 13:35
@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=16179

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