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

Add medianOfMedians #3938

Closed
wants to merge 2 commits into from
Closed

Add medianOfMedians #3938

wants to merge 2 commits into from

Conversation

andralex
Copy link
Member

This is a famous and very elegant algorithm. In addition, the implementation is a beauty.

@andralex andralex force-pushed the medianOfMedians branch 5 times, most recently from 43a1244 to b1bed39 Compare January 20, 2016 01:26
assert(notGreater >= 0.3 * v.length);
assert(notSmaller >= 0.3 * v.length);
}

Copy link
Member

Choose a reason for hiding this comment

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

Needs tests using std.internal.test.dummyrange

Copy link
Member

Choose a reason for hiding this comment

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

Also needs tests that use a custom less

@andralex andralex force-pushed the medianOfMedians branch 2 times, most recently from f70f461 to 72b2a7c Compare January 20, 2016 01:58
@9il
Copy link
Member

9il commented Jan 20, 2016

Awesome! This can be implemented for immutable ranges using a deep recursion. @andralex would you mind I create PR to your fork?

@andralex
Copy link
Member Author

I think I better get to implement the MoM with integrated partition first. Will get back to this.

@andralex andralex closed this Jan 20, 2016
@andralex andralex reopened this Jan 20, 2016
@JackStouffer
Copy link
Member

I'll reiterate my comments that were hidden due to the new commit:

  • this needs more tests, specifically ones using std.internal.test.dummyrange and ones using a custom less predicate.
  • More descriptive variable names and/or comments in the example couldn't hurt

@andralex
Copy link
Member Author

@JackStouffer agreed, will get to that soon. For now performance is just awful.

private void medianOf5(alias less, Range)(Range r)
{
assert(r.length == 5);
enum : uint { a, b, c, d, e }
Copy link
Member

Choose a reason for hiding this comment

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

this enum feels strange, especially as there is nothing similar in the next function.

@andralex
Copy link
Member Author

new work to come to this soon

@andralex andralex closed this Feb 12, 2016
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