-
Notifications
You must be signed in to change notification settings - Fork 341
Adds partial_cmp.rs file and partial_cmp signature to mod.rs #268
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
{ | ||
type Output = Option<Ordering>; | ||
|
||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
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.
uhhh, this doesn't look right. Values might arrive from streams at different points at time, but if this happens this doesn't mean that the streams are not equal. The more correct behaviour here would probably be as follows:
- We cache both elements we are currently comparing in the state of the
PartialCmpFuture
, inOption
s. - As soon as both elements are received (Both options are
.is_some()
) we can compare elements. - We have to consider all edge cases: i.e.
a) we havel_next
,l
has closed, but we don't haver_next
andr
is not yet closed
b) the same forr_next
c) both streams are closed but we have only one element left in cache
d) and so on
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 see. I wanted to start by replicating the std::iter code for partial_cmp as much as possible, but you're correct that it doesn't account for values from each stream arriving at different times. Thanks for the feedback.
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 also think that fuse
ing both streams would help.
src/stream/stream/partial_cmp.rs
Outdated
cx.waker().wake_by_ref(); | ||
Poll::Pending | ||
}, | ||
non_eq => Poll::Ready(non_eq), |
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.
This is probably going to fail cargo fmt
checks.
src/stream/stream/partial_cmp.rs
Outdated
} | ||
|
||
// wakes task to pull the next item from stream | ||
cx.waker().wake_by_ref(); |
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.
instead of this probably we should do a loop
like in fold
or skip_while
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.
Generally, when should looping be used instead of cx.waker().wake_by_ref()
? I've seen either approach used throughout the codebase and I wasn't sure which was the most applicable for this situation.
src/stream/stream/partial_cmp.rs
Outdated
L: Stream + Unpin + Sized, | ||
R: Stream + Unpin + Sized, |
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 don't believe Unpin
bounds are necessary here, are they?
.partial_cmp(vec![1.].into_iter().collect::<VecDeque<f64>>()).await; | ||
let result_none = vec![std::f64::NAN].into_iter().collect::<VecDeque<f64>>() | ||
.partial_cmp(vec![1.].into_iter().collect::<VecDeque<f64>>()).await; | ||
|
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.
Probably also tests for Greater
and Less
for streams of the same number of elements but with different values?
@yoshuawuyts Shall we 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.
Thanks so much for this! All that's needed now I think is a rebase!
@montekki yes; let's def land this!
@assemblaj it seems like the rebase didn't go as expected; this is changing 1800 lines and 79 files! |
@yoshuawuyts I honestly have no idea what's happening here. Currently trying to fix this. |
cdac349
to
f8bd71c
Compare
There are still some conflicts that need to be resolved. |
Hides docs as standard in our codebase for all Future types Co-Authored-By: Fedor Sakharov <[email protected]>
This reverts commit aaf2638.
Hides docs as standard in our codebase for all Future types Co-Authored-By: Fedor Sakharov <[email protected]>
This reverts commit aaf2638.
d2c9c5f
to
17a3afb
Compare
@yoshuawuyts @stjepang Rebased again just now. Everything should be good. |
It looks like |
@yoshuawuyts @stjepang The files for |
Thanks for fixing this and opening a new PR! |
Ports partial_cmp functionality from std::iter to async-std.