Skip to content

Add internal_queue #13

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

Merged

Conversation

TonalidadeHidrica
Copy link
Collaborator

No tests, no checks.

@MiSawa
Copy link
Contributor

MiSawa commented Sep 8, 2020

Why we use i32 as the index type?
It'd probably more natural and convinient to use usize as other Rust standard libraries.


impl<T> SimpleQueue<T>
where
T: Copy,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we want T to be Copy? It seems to me that passing T itself instead of reference &T in push is more natural.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because it was what the original code did. But yes, it's so unnatural and complicated to write in Rust, so I'll fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think removing Copy is better in the normal Rust libraries, but considering this is a internal code and is only used in the implementation of the maxflow algorithm (only for integer and pair of integers), I also think we can restrict the level of abstraction. Original C++ implementation are not using move semantics, either. For more general purposes we should use VecDeque in my opinion. At least it doesn't have enough interface to use with non-Copy type, e.g. no way to get the ownership of the queued value back.
As an alternative, we can use T directly instead of using references &T if T: Copy to make it more natural.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for late response....

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see. At least I changed &T to T in push method. Also it seemed that removing T: Copy does not do any harm, so I simply removed it for now.

@matsu7874 matsu7874 mentioned this pull request Sep 8, 2020
@TonalidadeHidrica
Copy link
Collaborator Author

I used i32 instead of usize in favor of the original code, but I agree that this is not idiomatic in Rust. However, if we are to replace some of them, we have to now decide to what extent we have to replace them. For now, I'll follow every comments on pull request, but I will not make any modification for the first time I create a new pull request.

@TonalidadeHidrica
Copy link
Collaborator Author

I changed my mind and use usize from beginning in some places.

@TonalidadeHidrica TonalidadeHidrica mentioned this pull request Sep 9, 2020
@TonalidadeHidrica
Copy link
Collaborator Author

I added boundary check in pop function, but wondering if this is a good idea from the viewpoint of performance. After all, this structure is only used internally.

@matsu7874 matsu7874 removed the request for review from statiolake September 11, 2020 15:18
@matsu7874 matsu7874 merged commit dd2a49c into rust-lang-ja:master Sep 11, 2020
@TonalidadeHidrica TonalidadeHidrica deleted the feature/internal_queue branch September 11, 2020 16:09
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