-
-
Notifications
You must be signed in to change notification settings - Fork 740
Fix Issue 6787 - Implement std.algorithm.lazySort #1886
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
Conversation
LGTM |
_heap.removeFront(); | ||
} | ||
} | ||
return Result(r); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could save some code by passing heapify!more(store)
here instead of using a constructor... but I guess it's partially a stylistic thing, as sometimes a constructor is strictly required for its special "cooking" privileges.
Should the struct be a private module-level struct instead of a voldemort? Last I heard, we have problems with voldemorts when alias parameters are involved. |
if (isRandomAccessRange!Range && | ||
hasAssignableElements!Range && | ||
!isInfinite!Range && | ||
is(typeof(binaryFun!less(r.front, r.front)) : bool)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the is(typeof(...) : bool)
is a non-pattern. The only thing it buys us, is turning down perfectly valid predicates. I don't have an example a sorting operator, but for a "test" operator, canFind
returns an int...
Yes, if the |
- Using documented unit test - De-Voldemortification - Removed bool check - Fixed import order - Duplicate element unit test
I think it's terrible that we have to make these fundamental style decisions based on DMD bugs... |
Well, strictly speaking you don't. The code is there for anyone sufficiently motivated to address the issue(s). There's a number of helpful contributors you could talk to about the specific issues and they might be willing to help with the fix or to even do it themselves. Taking the work around approach is just one option, not the only one, and not even the best one. |
Yeah, but fundamentally, I think there is a design issue in there too. That said, a workaround (I just thought of is): auto fun(alias pred)()
{
static struct Result(alias pred) //Look! I'm static!
{
bool foo()
{
return pred(5); //No problem!
}
}
return Result!pred();
}
void main()
{
int k;
auto s = fun!(a=>a==k)(); //This pred needs context.
} I think this creates 0 overhead too. I just tested this with |
One last thing: For what it's worth, as an end user, I personally dislike working with voldemort return types. When working with them, it seems like you always end up having to deal with |
On Wed, Jan 29, 2014 at 10:10:27AM -0800, monarch dodra wrote:
This isn't so much a flaw of voldemort types, as a flaw in compiler
than to:
T Curiosity kills the cat. Moral: don't be the cat. |
It's not the only reason why Voldemort's are problematic, another reason is that it's difficult to use them as a type for a field in an aggregate. |
I think this is getting off topic. Are there any other issues with this pull that people would like addressing? |
Is the fact that if we want to document that |
I don't think it should be documented to do a heap sort. That would lock us into a specific implementation that we may regret later. Edit: Actually, I think it is pretty well documented as is. The second sentence of the documentation is "$(D r) is modified by the range in-place." Is there a different phrasing you'd rather it used? |
That's a different issue (IMO), since most of the time, the return type is deliberately kept unspecified. |
This is a thin wrapper over the heap. Necessary? |
Now that I think of it - a range over heap (as container) would make this stuff obsolete. |
I think it'd make even more sense to simply give heap a range interface. It is already a wrapper over something else (not an actual container itself), so I see no problem doing that. It would have more primitives than your basic range, but that shouldn't keep it from being a range itself (I think). That said, I'm not completely familiar with |
That makes sense. By the looks of things, we'd just need to add @andralex would you be happy with that? |
Even if the range must be destructive, we should probably stick to |
Keep in mind I'm not even sure an |
Yeah, sorry; I should have familiarized myself with |
I'd be happy with that. |
I concur with @monarchdodra on this one, let's make |
I'm not so sure about this. Perhaps this could be a more general facility to consume any range? struct Consume(Container)
{
Container _container;
@property auto ref front() { return _container.front; }
@property bool empty() { return _container.empty; }
void popFront() { _container.removeFront(); }
// ... could add back, indexing, length etc. not saving, not slicing
}
auto consume(Container)(Container c) { return Consume!Container(c); } This way, you can Thoughts? |
You mean container. It is interesting. I assume with combination with things like |
According to doc, it's not a container either, it's a mere wrapper. It can wrap either a range, or a container, in which case, it also forwards the container primitives. |
I think making |
AFAIK, |
Perfect, @Poita - fire at will :) |
Why wouldn't |
I'll close this pull and make a new one since it's a completely separate approach to the problem. |
See discussion here: dlang#1886
Fixes Issue 12358 See discussion here: dlang#1886
https://d.puremagic.com/issues/show_bug.cgi?id=6787