Skip to content

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

Closed
wants to merge 14 commits into from

Conversation

assemblaj
Copy link
Contributor

Ports partial_cmp functionality from std::iter to async-std.

{
type Output = Option<Ordering>;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Copy link
Member

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:

  1. We cache both elements we are currently comparing in the state of the PartialCmpFuture, in Options.
  2. As soon as both elements are received (Both options are .is_some()) we can compare elements.
  3. We have to consider all edge cases: i.e.
    a) we have l_next, l has closed, but we don't have r_next and r is not yet closed
    b) the same for r_next
    c) both streams are closed but we have only one element left in cache
    d) and so on

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 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.

Copy link
Member

@montekki montekki Oct 1, 2019

Choose a reason for hiding this comment

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

I also think that fuseing both streams would help.

cx.waker().wake_by_ref();
Poll::Pending
},
non_eq => Poll::Ready(non_eq),
Copy link
Contributor

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.

}

// wakes task to pull the next item from stream
cx.waker().wake_by_ref();
Copy link
Member

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

Copy link
Contributor Author

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.

Comment on lines 38 to 39
L: Stream + Unpin + Sized,
R: Stream + Unpin + Sized,
Copy link
Member

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;

Copy link
Member

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?

@montekki
Copy link
Member

montekki commented Oct 5, 2019

@yoshuawuyts Shall we r+?

Copy link
Contributor

@yoshuawuyts yoshuawuyts left a 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!

@yoshuawuyts
Copy link
Contributor

@assemblaj it seems like the rebase didn't go as expected; this is changing 1800 lines and 79 files!

@assemblaj
Copy link
Contributor Author

@yoshuawuyts I honestly have no idea what's happening here. Currently trying to fix this.

@assemblaj assemblaj force-pushed the assemblaj-partial_cmp branch from cdac349 to f8bd71c Compare October 11, 2019 21:34
@ghost
Copy link

ghost commented Oct 14, 2019

There are still some conflicts that need to be resolved.

@assemblaj assemblaj force-pushed the assemblaj-partial_cmp branch from d2c9c5f to 17a3afb Compare October 14, 2019 14:23
@assemblaj
Copy link
Contributor Author

@yoshuawuyts @stjepang Rebased again just now. Everything should be good.

@ghost
Copy link

ghost commented Oct 14, 2019

It looks like map, for_each, and try_for_each are getting removed by this PR. I suppose that was not intentional?

@assemblaj
Copy link
Contributor Author

@yoshuawuyts @stjepang The files for map, for_each, and try_for_each are there, they just keep getting removed from mod.rs for reason reason. There's been a lot of issues with this branch related to rebasing, so I created a new branch and opened a new PR here: #327

@ghost
Copy link

ghost commented Oct 15, 2019

Thanks for fixing this and opening a new PR!

@ghost ghost closed this Oct 15, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants